ffmpeg-python icon indicating copy to clipboard operation
ffmpeg-python copied to clipboard

How to get the duration of a video?

Open jasonmusespresso opened this issue 4 years ago • 3 comments

Thanks for the amazing tool for processing video with ffmpeg in Python. Is there a way to get the duration of a video with this library? Thank you!

jasonmusespresso avatar May 09 '21 19:05 jasonmusespresso

I made this morning, it works. ` import ffmpeg

filename ="video.mov"

metadata = ffmpeg.probe(filename) video_stream = next((stream for stream in metadata['streams'] if stream['codec_type'] == 'video'), None)

fps = metadata['streams'][0]['avg_frame_rate'].split('/')[0] duration = metadata['streams'][0]['duration']

width = int(video_stream['width']) height = int(video_stream['height'])

print(f'Width: {width}, Height: {height}, FPS: {fps}, Duration: {duration}') `

barckley75 avatar May 10 '21 14:05 barckley75

@TanvirMobasshir

rajib-raiyat avatar Jul 19 '22 07:07 rajib-raiyat

Getting error:

KeyError Traceback (most recent call last) in 7 8 fps = metadata['streams'][0]['avg_frame_rate'].split('/')[0] ----> 9 duration = metadata['streams'][0]['duration'] 10 11 width = int(video_stream['width'])

KeyError: 'duration'

Saumyadav avatar Oct 20 '22 11:10 Saumyadav