mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-05-24 16:01:26 +08:00
Add read_frame_as_jpeg example
This commit is contained in:
parent
e294bd7753
commit
e1dded89b1
28
examples/read_frame_as_jpeg.py
Executable file
28
examples/read_frame_as_jpeg.py
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import argparse
|
||||||
|
import ffmpeg
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description='Read individual video frame into memory as jpeg and write to stdout')
|
||||||
|
parser.add_argument('in_filename', help='Input filename')
|
||||||
|
parser.add_argument('frame_num', help='Frame number')
|
||||||
|
|
||||||
|
|
||||||
|
def read_frame_as_jpeg(in_filename, frame_num):
|
||||||
|
out, err = (
|
||||||
|
ffmpeg
|
||||||
|
.input(in_filename)
|
||||||
|
.filter_('select', 'gte(n,{})'.format(frame_num))
|
||||||
|
.output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
|
||||||
|
.run(capture_stdout=True)
|
||||||
|
)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
args = parser.parse_args()
|
||||||
|
out = read_frame_as_jpeg(args.in_filename, args.frame_num)
|
||||||
|
sys.stdout.buffer.write(out)
|
Loading…
x
Reference in New Issue
Block a user