Tips From The Blog XVII: determining playback speed of a video

Generating movie files for publication can be a bit tricky. We have a protocol for making them for microscopy data, which simplifies things. However, we recently got this question from a journal:

please state the playback speed of each movie file

How can we do this?

What information is needed for movie files?

Usually movies have a time stamp and a scale bar. This is sufficient to understand the size of the everything in the movie and the speed at which processes are happening. Some journals also require the playback speed. This could be given as a scale factor (i.e. 10X, 10 min real time becomes 1 min of movie time) or as a speed (i.e. fps, frames per second).

Our protocol is to use 10 frames per second, but we sometimes make them at different speeds and either way we wanted to verify the speeds of the movie files that we had submitted.

If the number of frames is known, the solution is to find the duration of the movie. A quick way to do this on the command line is to use ffmpeg.

 ffmpeg -i path/to/movie.mp4 

Specifying the input (but no output) gives an error but reports the duration of the movie. Something like:

 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'path/to/movie.mp4': Metadata: major_brand : mp42 minor_version : 512 compatible_brands: isomiso2avc1mp41 creation_time : 2021-04-13T12:35:50.000000Z encoder : HandBrake 1.3.3 2020061300 Duration: 00:00:52.95, start: 0.000000, bitrate: 4257 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 752x752 [SAR 1:1 DAR 1:1], 4255 kb/s, 25.01 fps, 25 tbr, 90k tbn, 180k tbc (default) Metadata: creation_time : 2021-04-13T12:35:50.000000Z handler_name : VideoHandler vendor_id : [0][0][0][0] At least one output file must be specified 

Duration is 52.95 s

What to do if the number of frames is not known?

One solution is to use ffmpeg to split the movie file into separate image files and check how many there were.

 ffmpeg -i path/to/movie.mp4 frame%05d.jpg 

The resulting files are spat out into the working directory. Either take a look at the maximum file number (they are named frame0001.jpg, frame0002.jpg and so on), or consult the terminal. You will see, among the output, something like:

 frame= 1324 fps=320 q=24.8 Lsize=N/A time=00:00:52.96 bitrate=N/A speed=12.8x 

In this example, there were 1324 frames. You can check this with the number of jpg files that were saved to the working directory. So our frame rate is 1324/52.96 which is 25 fps.

Note that ffmpeg states fps is 320. However this speed refers to how fast the image files were saved to the working directory and doesn’t refer to the playback speed of the movie (confusing!).

Part of an occasional series of tech tips.