Total number of frames with ffmpeg

20,660

Solution 1

Take a look at this answer. The problem is that the exact number of frames is often not stored in metadata and can only be truly found (not estimated) by decoding the file and figuring out how many there are. If you only need an estimate, you can just use the framerate and duration provided by ffmpeg -i <filename> to estimate.

Solution 2

If you are invoking ffmpeg programmatically then the OpenCV library provides a convenient python/c++ interface for accessing video properties -

http://opencv.willowgarage.com/documentation/python/reading_and_writing_images_and_video.html#getcaptureproperty

Alternatively you could try to parse the output from ffprobe which comes bundled with ffmpeg and calculate total frame based on duration and FPS.

Share:
20,660
Utkarsh Sinha
Author by

Utkarsh Sinha

Works with several languages and technologies to create new things.

Updated on July 07, 2020

Comments

  • Utkarsh Sinha
    Utkarsh Sinha almost 4 years

    How do I find the total number of frames in a video with ffmpeg?

  • Utkarsh Sinha
    Utkarsh Sinha almost 12 years
    I was looking for an ffmpeg only way. I'll check ffprobe
  • gaussblurinc
    gaussblurinc about 10 years
    @UtkarshSinha, did you find command line way for total number of frames?
  • Utkarsh Sinha
    Utkarsh Sinha about 10 years
    I did not - I could get a best guess/estimate, but not an exact number.
  • Superdooperhero
    Superdooperhero almost 7 years
    Which part of the ffmpeg -i output would the framerate and duration be, and how would you get the number of frames from that?
  • Alexis Wilke
    Alexis Wilke over 3 years