Extract Video Frames In Python

前端 未结 6 1190
别那么骄傲
别那么骄傲 2020-12-13 09:59

I want to extract video frames and save them as image.

import os, sys
from PIL import Image

a, b, c = os.popen3(\"ffmpeg -i test.avi\")
out = c.read()
dp =          


        
6条回答
  •  天涯浪人
    2020-12-13 10:43

    There are ffmpeg python modules are available

    ffmpeg: https://code.google.com/p/pyffmpeg/

    pyAV: https://github.com/mikeboers/PyAV

    import av
    
    container = av.open('/path/to/video.mp4')
    
    for packet in container.demux():
        for frame in packet.decode():
            if frame.type == 'video':
                frame.to_image().save('/path/to/frame-%04d.jpg' % frame.index)
    

提交回复
热议问题