[FFmpeg-user] Rounding of start offset and duration value to frame positions
Tobias Rapp
t.rapp at noa-archive.com
Tue Sep 8 14:44:20 CEST 2015
Hello,
I'm truncating loss-less (HuffYuv/PCM) video files with FFmpeg using
start offset and duration values as given by the user and noticed two
similar issues:
a) When the offset value does not fall on frame positions there is a
small delay between audio and video stream.
Example:
ffmpeg -i ffmpeg-trim03.avi -f avi -codec:v huffyuv -codec:a pcm_s24le
-ss 10.02 -t 60.00 -y ffmpeg-trim03-01.avi
Output see attached "ffmpeg-trim03-01a.log". From studying the output
video apparently the audio stream starts at 10.02 (original file
position) and the video stream starts at 10.04.
b) If the duration does not fall on frame positions the total length of
the audio and video stream is different.
Example:
ffmpeg -i ffmpeg-trim03.avi -f avi -codec:v huffyuv -codec:a pcm_s24le
-ss 10.00 -t 60.02 -y ffmpeg-trim03-02.avi
Output see attached "ffmpeg-trim03-02b.log". From studying the output
video the audio stream has a duration of 60.02 while the video stream
has a duration of 60.04.
It seems that ffmpeg does not do a rounding of the positions to frame
borders. Is there a possibility to achieve that besides doing a manual
fps detection using ffprobe followed by some rounded calculation before
calling ffmpeg?
Regards,
Tobias
-------------- next part --------------
ffmpeg version N-74308-g40ddbc8 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (GCC)
configuration: --disable-network --disable-w32threads --disable-static --enable-shared --enable-version3 --arch=x86 --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32- --prefix=/usr/local/win64
libavutil 54. 30.100 / 54. 30.100
libavcodec 56. 57.100 / 56. 57.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 32.100 / 5. 32.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
Splitting the commandline.
Reading option '-i' ... matched as input file with argument 'ffmpeg-trim03.avi'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'avi'.
Reading option '-codec:v' ... matched as option 'codec' (codec name) with argument 'huffyuv'.
Reading option '-codec:a' ... matched as option 'codec' (codec name) with argument 'pcm_s24le'.
Reading option '-ss' ... matched as option 'ss' (set the start time offset) with argument '10.02'.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '60.00'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option 'ffmpeg-trim03-01.avi' ... matched as output file.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file ffmpeg-trim03.avi.
Successfully parsed a group of options.
Opening an input file: ffmpeg-trim03.avi.
[avi @ 00000000002fd2c0] Format avi probed with size=2048 and score=100
[avi @ 0000000000305dc0] use odml:1
[avi @ 00000000002fd2c0] Before avformat_find_stream_info() pos: 10112 bytes read:279360 seeks:6
[avi @ 00000000002fd2c0] parser not found for codec huffyuv, packets or times may be invalid.
[avi @ 00000000002fd2c0] parser not found for codec pcm_s24le, packets or times may be invalid.
[avi @ 00000000002fd2c0] parser not found for codec huffyuv, packets or times may be invalid.
[avi @ 00000000002fd2c0] parser not found for codec pcm_s24le, packets or times may be invalid.
[avi @ 00000000002fd2c0] All info found
[avi @ 00000000002fd2c0] After avformat_find_stream_info() pos: 247688 bytes read:546624 seeks:6 frames:2
Input #0, avi, from 'ffmpeg-trim03.avi':
Metadata:
encoder : Lavf56.40.101
Duration: 00:02:00.00, start: 0.000000, bitrate: 48006 kb/s
Stream #0:0, 1, 1/25: Video: huffyuv, 1 reference frame (HFYU / 0x55594648), yuv422p, 720x576, 1/25, 46857 kb/s, SAR 1:1 DAR 5:4, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1, 1, 1/48000: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s32 (24 bit), 1152 kb/s
Successfully opened the file.
Parsing a group of options: output file ffmpeg-trim03-01.avi.
Applying option f (force format) with argument avi.
Applying option codec:v (codec name) with argument huffyuv.
Applying option codec:a (codec name) with argument pcm_s24le.
Applying option ss (set the start time offset) with argument 10.02.
Applying option t (record or transcode "duration" seconds of audio/video) with argument 60.00.
Successfully parsed a group of options.
Opening an output file: ffmpeg-trim03-01.avi.
Successfully opened the file.
detected 2 logical cores
[graph 0 input from stream 0:0 @ 000000000034c380] Setting 'video_size' to value '720x576'
[graph 0 input from stream 0:0 @ 000000000034c380] Setting 'pix_fmt' to value '4'
[graph 0 input from stream 0:0 @ 000000000034c380] Setting 'time_base' to value '1/25'
[graph 0 input from stream 0:0 @ 000000000034c380] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 000000000034c380] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 000000000034c380] Setting 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 000000000034c380] w:720 h:576 pixfmt:yuv422p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2
[format @ 00000000003ed380] compat: called with args=[yuv422p|rgb24|bgra]
[format @ 00000000003ed380] Setting 'pix_fmts' to value 'yuv422p|rgb24|bgra'
[AVFilterGraph @ 00000000003e9da0] query_formats: 5 queried, 4 merged, 0 already done, 0 delayed
[graph 1 input from stream 0:1 @ 00000000002f62a0] Setting 'time_base' to value '1/48000'
[graph 1 input from stream 0:1 @ 00000000002f62a0] Setting 'sample_rate' to value '48000'
[graph 1 input from stream 0:1 @ 00000000002f62a0] Setting 'sample_fmt' to value 's32'
[graph 1 input from stream 0:1 @ 00000000002f62a0] Setting 'channel_layout' to value '0x4'
[graph 1 input from stream 0:1 @ 00000000002f62a0] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x4
[audio format for output stream 0:1 @ 00000000002f6420] Setting 'sample_fmts' to value 's32'
[AVFilterGraph @ 00000000003edc60] query_formats: 5 queried, 12 merged, 0 already done, 0 delayed
[huffyuv @ 00000000002e24a0] using huffyuv 2.2.0 or newer interlacing flag
[huffyuv @ 00000000002e8940] using huffyuv 2.2.0 or newer interlacing flag
[huffyuv @ 0000000002cc4f80] using huffyuv 2.2.0 or newer interlacing flag
Output #0, avi, to 'ffmpeg-trim03-01.avi':
Metadata:
ISFT : Lavf56.40.101
Stream #0:0, 0, 1/25: Video: huffyuv, 1 reference frame (HFYU / 0x55594648), yuv422p, 720x576 [SAR 1:1 DAR 5:4], 1/25, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc56.57.100 huffyuv
Stream #0:1, 0, 1/48000: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s32 (24 bit), 1152 kb/s
Metadata:
encoder : Lavc56.57.100 pcm_s24le
Stream mapping:
Stream #0:0 -> #0:0 (huffyuv (native) -> huffyuv (native))
Stream #0:1 -> #0:1 (pcm_s24le (native) -> pcm_s24le (native))
Press [q] to stop, [?] for help
Cliping frame in rate conversion by 0.499992
Last message repeated 47 times
frame= 49 fps=0.0 q=-0.0 size= 11028kB time=00:00:02.05 bitrate=43878.9kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 201 times
frame= 251 fps=244 q=-0.0 size= 58366kB time=00:00:10.11 bitrate=47276.0kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 205 times
frame= 457 fps=296 q=-0.0 size= 106642kB time=00:00:18.38 bitrate=47525.4kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 206 times
frame= 664 fps=322 q=-0.0 size= 155167kB time=00:00:26.65 bitrate=47684.1kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 204 times
frame= 869 fps=338 q=-0.0 size= 203225kB time=00:00:34.84 bitrate=47774.8kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 207 times
frame= 1077 fps=349 q=-0.0 size= 251984kB time=00:00:43.17 bitrate=47806.3kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 206 times
frame= 1284 fps=356 q=-0.0 size= 300502kB time=00:00:51.45 bitrate=47842.2kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 205 times
frame= 1490 fps=362 q=-0.0 size= 348789kB time=00:00:59.70 bitrate=47859.4kbits/s
Cliping frame in rate conversion by 0.499992
Last message repeated 9 times
[output stream 0:1 @ 00000000002f6360] EOF on sink link output stream 0:1:default.
No more output streams to write to, finishing.
frame= 1499 fps=363 q=-0.0 Lsize= 351461kB time=00:01:00.00 bitrate=47986.1kbits/s
video:342877kB audio:8438kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.041566%
Input file #0 (ffmpeg-trim03.avi):
Input stream #0:0 (video): 1753 packets read (410625424 bytes); 1752 frames decoded;
Input stream #0:1 (audio): 4930 packets read (10094175 bytes); 4930 frames decoded (3364725 samples);
Total: 6683 packets (420719599 bytes) demuxed
Output file #0 (ffmpeg-trim03-01.avi):
Output stream #0:0 (video): 1499 frames encoded; 1499 packets muxed (351106548 bytes);
Output stream #0:1 (audio): 4221 frames encoded (2880000 samples); 4221 packets muxed (8640000 bytes);
Total: 5720 packets (359746548 bytes) muxed
6682 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0000000002d9a860] Statistics: 12 seeks, 16225 writeouts
[AVIOContext @ 0000000000305cc0] Statistics: 421035168 bytes read, 6 seeks
-------------- next part --------------
ffmpeg version N-74308-g40ddbc8 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.8 (GCC)
configuration: --disable-network --disable-w32threads --disable-static --enable-shared --enable-version3 --arch=x86 --target-os=mingw32 --cross-prefix=x86_64-w64-mingw32- --prefix=/usr/local/win64
libavutil 54. 30.100 / 54. 30.100
libavcodec 56. 57.100 / 56. 57.100
libavformat 56. 40.101 / 56. 40.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 32.100 / 5. 32.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.101 / 1. 2.101
Splitting the commandline.
Reading option '-i' ... matched as input file with argument 'ffmpeg-trim03.avi'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'avi'.
Reading option '-codec:v' ... matched as option 'codec' (codec name) with argument 'huffyuv'.
Reading option '-codec:a' ... matched as option 'codec' (codec name) with argument 'pcm_s24le'.
Reading option '-ss' ... matched as option 'ss' (set the start time offset) with argument '10.00'.
Reading option '-t' ... matched as option 't' (record or transcode "duration" seconds of audio/video) with argument '60.02'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option 'ffmpeg-trim03-02.avi' ... matched as output file.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file ffmpeg-trim03.avi.
Successfully parsed a group of options.
Opening an input file: ffmpeg-trim03.avi.
[avi @ 000000000065d2c0] Format avi probed with size=2048 and score=100
[avi @ 0000000000665dc0] use odml:1
[avi @ 000000000065d2c0] Before avformat_find_stream_info() pos: 10112 bytes read:279360 seeks:6
[avi @ 000000000065d2c0] parser not found for codec huffyuv, packets or times may be invalid.
[avi @ 000000000065d2c0] parser not found for codec pcm_s24le, packets or times may be invalid.
[avi @ 000000000065d2c0] parser not found for codec huffyuv, packets or times may be invalid.
[avi @ 000000000065d2c0] parser not found for codec pcm_s24le, packets or times may be invalid.
[avi @ 000000000065d2c0] All info found
[avi @ 000000000065d2c0] After avformat_find_stream_info() pos: 247688 bytes read:546624 seeks:6 frames:2
Input #0, avi, from 'ffmpeg-trim03.avi':
Metadata:
encoder : Lavf56.40.101
Duration: 00:02:00.00, start: 0.000000, bitrate: 48006 kb/s
Stream #0:0, 1, 1/25: Video: huffyuv, 1 reference frame (HFYU / 0x55594648), yuv422p, 720x576, 1/25, 46857 kb/s, SAR 1:1 DAR 5:4, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream #0:1, 1, 1/48000: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s32 (24 bit), 1152 kb/s
Successfully opened the file.
Parsing a group of options: output file ffmpeg-trim03-02.avi.
Applying option f (force format) with argument avi.
Applying option codec:v (codec name) with argument huffyuv.
Applying option codec:a (codec name) with argument pcm_s24le.
Applying option ss (set the start time offset) with argument 10.00.
Applying option t (record or transcode "duration" seconds of audio/video) with argument 60.02.
Successfully parsed a group of options.
Opening an output file: ffmpeg-trim03-02.avi.
Successfully opened the file.
detected 2 logical cores
[graph 0 input from stream 0:0 @ 00000000006ac380] Setting 'video_size' to value '720x576'
[graph 0 input from stream 0:0 @ 00000000006ac380] Setting 'pix_fmt' to value '4'
[graph 0 input from stream 0:0 @ 00000000006ac380] Setting 'time_base' to value '1/25'
[graph 0 input from stream 0:0 @ 00000000006ac380] Setting 'pixel_aspect' to value '1/1'
[graph 0 input from stream 0:0 @ 00000000006ac380] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 00000000006ac380] Setting 'frame_rate' to value '25/1'
[graph 0 input from stream 0:0 @ 00000000006ac380] w:720 h:576 pixfmt:yuv422p tb:1/25 fr:25/1 sar:1/1 sws_param:flags=2
[format @ 000000000038d380] compat: called with args=[yuv422p|rgb24|bgra]
[format @ 000000000038d380] Setting 'pix_fmts' to value 'yuv422p|rgb24|bgra'
[AVFilterGraph @ 0000000000389da0] query_formats: 5 queried, 4 merged, 0 already done, 0 delayed
[graph 1 input from stream 0:1 @ 00000000006562a0] Setting 'time_base' to value '1/48000'
[graph 1 input from stream 0:1 @ 00000000006562a0] Setting 'sample_rate' to value '48000'
[graph 1 input from stream 0:1 @ 00000000006562a0] Setting 'sample_fmt' to value 's32'
[graph 1 input from stream 0:1 @ 00000000006562a0] Setting 'channel_layout' to value '0x4'
[graph 1 input from stream 0:1 @ 00000000006562a0] tb:1/48000 samplefmt:s32 samplerate:48000 chlayout:0x4
[audio format for output stream 0:1 @ 0000000000656420] Setting 'sample_fmts' to value 's32'
[AVFilterGraph @ 000000000038dc60] query_formats: 5 queried, 12 merged, 0 already done, 0 delayed
[huffyuv @ 00000000006424a0] using huffyuv 2.2.0 or newer interlacing flag
[huffyuv @ 0000000000648940] using huffyuv 2.2.0 or newer interlacing flag
[huffyuv @ 0000000002d64f80] using huffyuv 2.2.0 or newer interlacing flag
Output #0, avi, to 'ffmpeg-trim03-02.avi':
Metadata:
ISFT : Lavf56.40.101
Stream #0:0, 0, 1/25: Video: huffyuv, 1 reference frame (HFYU / 0x55594648), yuv422p, 720x576 [SAR 1:1 DAR 5:4], 1/25, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
Metadata:
encoder : Lavc56.57.100 huffyuv
Stream #0:1, 0, 1/48000: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 48000 Hz, mono, s32 (24 bit), 1152 kb/s
Metadata:
encoder : Lavc56.57.100 pcm_s24le
Stream mapping:
Stream #0:0 -> #0:0 (huffyuv (native) -> huffyuv (native))
Stream #0:1 -> #0:1 (pcm_s24le (native) -> pcm_s24le (native))
Press [q] to stop, [?] for help
Cliping frame in rate conversion by 0.000008
frame= 43 fps=0.0 q=-0.0 size= 9616kB time=00:00:01.79 bitrate=43898.5kbits/s
frame= 247 fps=240 q=-0.0 size= 57423kB time=00:00:09.95 bitrate=47248.9kbits/s
frame= 457 fps=296 q=-0.0 size= 106636kB time=00:00:18.34 bitrate=47618.5kbits/s
frame= 667 fps=324 q=-0.0 size= 155864kB time=00:00:26.76 bitrate=47709.9kbits/s
frame= 875 fps=340 q=-0.0 size= 204628kB time=00:00:35.06 bitrate=47804.1kbits/s
frame= 1085 fps=351 q=-0.0 size= 253852kB time=00:00:43.48 bitrate=47823.7kbits/s
frame= 1296 fps=360 q=-0.0 size= 303308kB time=00:00:51.90 bitrate=47873.6kbits/s
[output stream 0:0 @ 000000000038d100] EOF on sink link output stream 0:0:default.
[output stream 0:1 @ 0000000000656360] EOF on sink link output stream 0:1:default.
No more output streams to write to, finishing.
frame= 1501 fps=366 q=-0.0 Lsize= 351922kB time=00:01:00.04 bitrate=48017.0kbits/s
video:343335kB audio:8440kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.041533%
Input file #0 (ffmpeg-trim03.avi):
Input stream #0:0 (video): 1754 packets read (410859732 bytes); 1753 frames decoded;
Input stream #0:1 (audio): 4932 packets read (10098270 bytes); 4932 frames decoded (3366090 samples);
Total: 6686 packets (420958002 bytes) demuxed
Output file #0 (ffmpeg-trim03-02.avi):
Output stream #0:0 (video): 1501 frames encoded; 1501 packets muxed (351575156 bytes);
Output stream #0:1 (audio): 4223 frames encoded (2880960 samples); 4223 packets muxed (8642880 bytes);
Total: 5724 packets (360218036 bytes) muxed
6685 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0000000002e3a860] Statistics: 12 seeks, 16243 writeouts
[AVIOContext @ 0000000000665cc0] Statistics: 421273588 bytes read, 6 seeks
More information about the ffmpeg-user
mailing list