python如何调用ffmpeg
发布网友
发布时间:2022-04-22 05:14
我来回答
共1个回答
热心网友
时间:2022-06-07 15:16
基本使用如下:
import av
container = av.open(path_to_video)
for frame in container.decode(video=0):
frame.to_image().save('frame-%04d.jpg' % frame.index)
保存关键帧:
import av
import av.datasets
content = av.datasets.curated('pexels/time-lapse-video-of-night-sky-857195.mp4')
with av.open(content) as container:
# Signal that we only want to look at keyframes.
stream = container.streams.video[0]
stream.codec_context.skip_frame = 'NONKEY'
for frame in container.decode(stream):
print(frame)
# We use `frame.pts` as `frame.index` won't make must sense with the `skip_frame`.
frame.to_image().save(
'night-sky.{:04d}.jpg'.format(frame.pts),
quality=80,
)