Opened 4 weeks ago

Last modified 3 weeks ago

#10954 new defect

ffmpeg should not round the frame rate from 23.976 fps to 23.98 fps

Reported by: milahu Owned by:
Priority: minor Component: ffmpeg
Version: 6.1.1 Keywords: framerate rounding formatting
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

when i process a video with 23.976 fps
then ffmpeg shows the frame rate 23.98 fps

ffmpeg -f lavfi -i color=rate=23.976 -t 0.1 test.mp4
ffmpeg -i test.mp4 2>&1 | grep "Stream #0:0"
Stream #0:0: Video: ..., 23.98 fps, 23.98 tbr, ...

... which is wrong
ffmpeg should not round the frame rate to %.2f
same problem with ffprobe, ffplay, ...

if rounding of the frame rate is necessary
then ffmpeg should round the frame rate to at least %.3f
to preserve 23.976 fps

the mpv video player
shows the correct frame rate 23.976fps

$ mpv test.mp4 2>&1 | grep Video
 (+) Video --vid=1 (*) (h264 1280x720 23.976fps)

Change History (5)

comment:1 by Marton Balint, 3 weeks ago

Why does this matter? 23.976 is not exact either. If you are parsing the frame rate from the stream details as written, you are doing something wrong, and you should be using the output of ffprobe instead, such as:

ffprobe -select_streams v -show_entries stream=avg_frame_rate -of csv test.mp4

comment:2 by Balling, 3 weeks ago

when i process a video with 23.976 fps

Why do you do that, nothing supports that. That actual frame rate is 24/1.001, just as for all other like 60 or 120.

then ffmpeg shows the frame rate 23.98 fps

That is school rounding and that is what some cameras do, so what is the issue, believe me we have a lot of bugs in this, but this one is actually correct. See: https://en.wikipedia.org/wiki/24p

"Remember that although computer editing systems may refer to "24p", usually the frame rate is 23.976 frame/s. To add to confusion, the popular editing program Final Cut Pro refers to 23.976 as "23.98" in menus and dialogs, even though it correctly works with the footage at the 23.976 frame rate. 23.976 is also not precise though, as the real frame rate is 24000/1001, so 23.98 is also a correct approximation."

the mpv video player shows the correct frame rate 23.976fps

Actually mpv uses nanoseconds, so even more digits internally and in the logs.

comment:3 by milahu, 3 weeks ago

Why does this matter?

i assume that "23.98 fps" is used for brevity,
but it can be misleading for noobs like me...

so either "~23.98 fps" or "24000/1001 fps" would be nice

23.976 is not exact either

aah, good to know.
(sorry, i should have done my research.)

you should be using the output of ffprobe

yepp, this works:

$ ffprobe -select_streams v -show_entries stream=avg_frame_rate -of csv src.mkv 2>/dev/null 
stream,24000/1001

the real frame rate is 24000/1001

$ echo 'scale=24; 24000/1001' | bc
23.976023976023976023976023

i have used the fps value for the atempo filter
to convert audiotracks between movies with different framerates.

example: convert tempo from 25fps to 23.976fps:

ffmpeg -i src.m4a -af atempo=23.976/25 dst.m4a

so the correct version would be

ffmpeg -i src.m4a -af atempo=24000/1001/25 dst.m4a

error versus 23.976 fps is 0.004 seconds per hour

$ echo 'scale=20; (((24000/1001)/23.976)-1)*3600' | bc
.00360000360000356400

error versus 23.98 fps is 0.6 seconds per hour

$ echo 'scale=20; (((24000/1001)/23.98)-1)*3600' | bc
-.59690101391519241600

comment:4 by Balling, 3 weeks ago

error versus 23.976 fps is 0.004 seconds per hour

Well, you can word it better: it accumulates 1 frame every 9 hours 15 minutes. So kinda sensitive in some scenarios.

About ~ symbol: what happens if the frame rate actually is 23976/1000? Some files have it even on youtube.

comment:5 by milahu, 3 weeks ago

the ~ symbol would only be used if the number is rounded

23976/1000 -> 23.976
24000/1001 -> ~23.976

Note: See TracTickets for help on using tickets.