[FFmpeg-user] Decimal times to frame numbers
amindfv at mailbox.org
amindfv at mailbox.org
Sat Aug 21 02:49:15 EEST 2021
To test this, I've just created a fixed-frame-rate video at 24 fps:
(1/3) seconds (8 frames) solid Red, followed by (1/24) seconds (1 frame) solid Green, followed by (1/3) seconds (8 frames) solid Blue.
Per the FFmpeg Mailing List FAQ, I've uploaded the sample file to https://0x0.st/-yD3.mp4
I then tested the output of running commands like this, only changing the value for $STARTTIME :
export STARTTIME=0.33 ; ffmpeg -r 24 -i color-frames.mp4 -r 24 -ss $STARTTIME "test-$STARTTIME.mp4"
(Side note: I originally put the -ss value before the input specifier, but the times were very inaccurate: some clips dropped no frames - i.e. I saw 8 frames of red in some cases! Other times too many frames appeared to be dropped. If I'm reading the man page entry for -ss correctly, this seems like a bug.)
Below are values for $STARTTIME, with the color of the first frame of the output:
0.3125: Green <-------- This is halfway between the start time of the last Red frame (7/24) and the start time of the first Green one (1/3). Calculation: ((7/24) + (((1/3)-(7/24))/2)) == (5/16). Note this output file starts with 2(!) green frames even though the input only contains 1.
0.31250000001: Green (still 2 frames of Green)
0.3125000001: Green (still 2 frames)
0.312500001: Green (still 2 frames)
0.31250001: Green (still 2 frames)
0.3125001: Green (still 2 frames)
0.312501: Green (back to only 1 frame of Green)
<-------------------- This is where the source video turns from Red to Green (1/3 == 0.333...)
0.375: Blue <-------- This is where the source video turns from Green to Blue
In summary, I'm more confused than when I started. It seems (though I haven't tried hairier time values, e.g. with frame rate 23.976) that seeking may compute the closest start frame - i.e. simply round. But then the output seems to be working in some other way: what's the distinction between time 0.312501 (1 frame of Green) and 0.3125001 (2 frames of Green)? I don't know.
Any help here is much appreciated. Thanks!
On Wed, Aug 18, 2021 at 09:26:03PM -0600, amindfv--- via ffmpeg-user wrote:
> How are frame numbers converted to and from decimal numbers of seconds in ffmpeg and related tools?
> For example, given a file foo.mp4 at 24fps, when I run a command like:
> ffmpeg -i foo.mp4 -t 0.72 bar.mp4
> 0.72 is a time between frame 18 (0.70833... seconds) and frame 19 (0.75 seconds).
> In my tests, it seems that the number of seconds is rounded down, i.e. any value less than 0.75 is equivalent to the earlier frame.
> Is this always true? Is this the best way to think about the decimal seconds<->frame number conversion? Is there any difference (e.g. in audio track duration) between saying 0.71 or 0.73 in the above?
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-user