简体   繁体   中英

How to get frame number given a timestamp using ffmpeg

How can I get the frame number closest to a given time (relative to the start of the video) using ffmpeg? The video has variable frame rate . I do not need any other metadata or the actual frame (image) itself. Speed is more important than precision (unless the possible error is more than a couple of seconds).

Example:

Input

  • video.mp4 (assuming ideal constant 30 fps for simplicity)
  • 00:00:05 (HH:MM:SS)

Output

  • 150
ffmpeg -t 01:05 -i input.mp4  -nostats -vcodec copy -y -f rawvideo /dev/null   2>&1  | grep frame | awk '{print $2}' | tr -d ,

This ffmpeg command takes your input.mp4, truncates it to -t (in the example above 01:05, and writes the file to /dev/null. the -y overwrites whatever is on /dev/null.

The grep command grabs the number of frames.

INPUT: ffmpeg -t 01:05 -i baywatch.mp4 -nostats -vcodec copy -y -f rawvideo /dev/null 2>&1 | grep frame | awk '{print $2}' | tr -d ,

OUTPUT: 1559

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM