Opened 7 years ago

Closed 2 months ago

#2333 closed defect (needs_more_info)

mkv + ac3 remux adds a little time

Reported by: Squeeto Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

ffmpeg adds time to the muxed mkv and demuxed mkv:

ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers

built on Feb 17 2013 02:37:45 with gcc 4.7.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 52. 17.101 / 52. 17.101
libavcodec 54. 91.103 / 54. 91.103
libavformat 54. 63.100 / 54. 63.100
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 38.100 / 3. 38.100
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100

ffmpeg -i input.mkv -i input.ac3 -map 0:0 -map 1:0 -vcodec copy -acodec copy -y done.mkv

Input #0, matroska,webm, from 'input.mkv':

Duration: 00:00:12.85, start: 0.000000, bitrate: 6039 kb/s

Input #0, ac3, from 'input.ac3':

Duration: 00:00:12.86, start: 0.000000, bitrate: 256 kb/s

Input #0, matroska,webm, from 'done.mkv':

Metadata:

ENCODER : Lavf54.63.100

Duration: 00:00:12.93, start: 0.000000, bitrate: 6256 kb/s

ffmpeg -i done.mkv -an -vcodec copy -y demux.mkv

ffmpeg -i done.mkv -acodec copy -vn -y demux.ac3

Input #0, matroska,webm, from 'demux.mkv':

Metadata:

ENCODER : Lavf54.63.100

Duration: 00:00:12.91, start: 0.000000, bitrate: 6008 kb/s

Input #0, ac3, from 'demux.ac3':

Duration: 00:00:12.86, start: 0.000000, bitrate: 256 kb/s

Change History (8)

comment:1 follow-ups: Changed 7 years ago by cehoyos

To make this a valid ticket, please provide your failing command line including complete, unedited console output and please consider using a "Code block".

comment:2 in reply to: ↑ 1 Changed 7 years ago by Squeeto

Replying to cehoyos:

To make this a valid ticket, please provide your failing command line including complete, unedited console output and please consider using a "Code block".

Please note the Duration discrepancies:

ffmpeg -i input.mkv -i input.ac3 -map 0:0 -map 1:0 -vcodec copy -acodec copy -y done.mkv

ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 02:37:45 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'input.mkv':
  Duration: 00:00:12.85, start: 0.000000, bitrate: 6039 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 20k tbn, 59.94 tbc (default)
[ac3 @ 025ad320] max_analyze_duration 5000000 reached at 5024000 microseconds
[ac3 @ 025ad320] Estimating duration from bitrate, this may be inaccurate
Input #1, ac3, from 'input.ac3':
  Duration: 00:00:12.86, start: 0.000000, bitrate: 256 kb/s
    Stream #1:0: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
Output #0, matroska, to 'done.mkv':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 1k tbn, 20k tbc (default)
    Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  385 fps=0.0 q=-1.0 Lsize=    9876kB time=00:00:12.86 bitrate=6289.3kbits/s    
video:9468kB audio:402kB subtitle:0 global headers:0kB muxing overhead 0.065323%

ffmpeg -i done.mkv -an -vcodec copy -y demux.mkv

ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 02:37:45 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'done.mkv':
  Metadata:
    ENCODER         : Lavf54.63.100
  Duration: 00:00:12.93, start: 0.000000, bitrate: 6256 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
    Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
Output #0, matroska, to 'demux.mkv':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 1k tbn, 1k tbc (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=  385 fps=0.0 q=-1.0 Lsize=    9471kB time=00:00:12.81 bitrate=6055.1kbits/s    
video:9468kB audio:0kB subtitle:0 global headers:0kB muxing overhead 0.038442%

ffmpeg -i done.mkv -acodec copy -vn -y demux.ac3

ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 02:37:45 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'done.mkv':
  Metadata:
    ENCODER         : Lavf54.63.100
  Duration: 00:00:12.93, start: 0.000000, bitrate: 6256 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
    Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
Output #0, ac3, to 'demux.ac3':
  Metadata:
    encoder         : Lavf54.63.100
    Stream #0:0: Audio: ac3, 48000 Hz, stereo, 256 kb/s
Stream mapping:
  Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=     402kB time=00:00:12.93 bitrate= 254.7kbits/s    
video:0kB audio:402kB subtitle:0 global headers:0kB muxing overhead 0.000000%

ffmpeg -i demux.mkv

ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 02:37:45 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'demux.mkv':
  Metadata:
    ENCODER         : Lavf54.63.100
  Duration: 00:00:12.91, start: 0.000000, bitrate: 6008 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc (default)
At least one output file must be specified

ffmpeg -i demux.ac3

ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 02:37:45 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[ac3 @ 0226b420] max_analyze_duration 5000000 reached at 5024000 microseconds
[ac3 @ 0226b420] Estimating duration from bitrate, this may be inaccurate
Input #0, ac3, from 'demux.ac3':
  Duration: 00:00:12.86, start: 0.000000, bitrate: 256 kb/s
    Stream #0:0: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
At least one output file must be specified

comment:3 Changed 7 years ago by Squeeto

Has my question been properly requested?
It has been a week so I am not sure if you are still waiting.

Recap:

input.mkv              12.85 sec
input.ac3              12.86
done.mkv (ffmpeg copy) 12.93
demux.mkv              12.91
demux.ac3              12.86

comment:4 Changed 7 years ago by cehoyos

If I understand correctly, you fear that remuxing makes your audio files longer. The only way to prove this is to decode both the original file and the remuxed file to wav files and compare them.

Or do I misunderstand the issue?

comment:5 in reply to: ↑ 1 Changed 7 years ago by Squeeto

I started this question at http://ffmpeg.zeranoe.com/forum; it was there that the demuxed times were asked for trouble-shooting purposes.

I only want to mux the input.mkv and input.ac3. I would prefer to use ffmpeg but I noticed that mkvmerge makes a done.mkv of 12.86 seconds. Why does ffmpeg add a little time? Does it matter? Can I still splice together done.mkv, done2.mkv, done3.mkv, etc. and expect doneTotal.mkv to be okay?

I am not concerned that input.ac3 is a little longer than input.mkv.

Thank you

comment:6 Changed 7 years ago by Squeeto

Hi again.
I found this branch of ffmpeg called ffmbc that creates an output mkv file of 12.86 seconds as I am hoping for.

ffmpeg -i done_ffmbc.mkv

ffmpeg version N-50025-gb8bb661 Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 17 2013 02:37:45 with gcc 4.7.2 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
  libavutil      52. 17.101 / 52. 17.101
  libavcodec     54. 91.103 / 54. 91.103
  libavformat    54. 63.100 / 54. 63.100
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 38.100 /  3. 38.100
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from 'done_ffmbc.mkv':
  Metadata:
    ENCODER         : FFmbc 0.7
  Duration: 00:00:12.86, start: 0.000000, bitrate: 6289 kb/s
    Stream #0:0: Video: h264 (High), yuv420p, 1920x1080, SAR 1:1 DAR 16:9, 20k fps, 20k tbr, 1k tbn, 59.94 tbc (default)
    Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s (default)
At least one output file must be specified

comment:7 Changed 7 years ago by rogerdpack

maybe it's rounding up or something, when reporting time back to the container?

comment:8 Changed 2 months ago by mkver

  • Resolution set to needs_more_info
  • Status changed from new to closed

I am closing this as needs_more_info, because there have been no samples provided. Nevertheless, based upon the information from your post at zeranoe's forum I can already guess what happened here. But for the record, here is the post I am basing my answer on:

Here is the first and last packets from:
original mkv = zoutput.mkv
original ac3 = zoutput_f.ac3
mux = done2
and demuxed = zvideo.mkv and zaudio.ac3

[zoutput.mkv]
[PACKET]
codec_type=video
stream_index=0
pts=0
pts_time=0.000000
dts=N/A
dts_time=N/A
duration=N/A
duration_time=N/A
convergence_duration=N/A
convergence_duration_time=N/A
size=238017
pos=241
flags=K
[/PACKET]

[PACKET]
codec_type=video
stream_index=0
pts=255588
pts_time=12.779400
dts=254921
dts_time=12.746050
duration=667
duration_time=0.033350
convergence_duration=N/A
convergence_duration_time=N/A
size=27305
pos=27899741
flags=_
[/PACKET]

[zoutput_f.ac3]
[PACKET]
codec_type=audio
stream_index=0
pts=0
pts_time=0.000000
dts=0
dts_time=0.000000
duration=2880
duration_time=0.032000
convergence_duration=N/A
convergence_duration_time=N/A
size=1024
pos=0
flags=K
[/PACKET]

[PACKET]
codec_type=audio
stream_index=0
pts=1154880
pts_time=12.832000
dts=1154880
dts_time=12.832000
duration=2880
duration_time=0.032000
convergence_duration=N/A
convergence_duration_time=N/A
size=1024
pos=410624
flags=K
[/PACKET]

[done2]
[PACKET]
codec_type=video
stream_index=0
pts=67
pts_time=0.067000
dts=N/A
dts_time=N/A
duration=N/A
duration_time=N/A
convergence_duration=N/A
convergence_duration_time=N/A
size=238017
pos=705
flags=K
[/PACKET]

[PACKET]
codec_type=audio
stream_index=1
pts=12899
pts_time=12.899000
dts=12899
dts_time=12.899000
duration=32
duration_time=0.032000
convergence_duration=N/A
convergence_duration_time=N/A
size=1024
pos=28340735
flags=K
[/PACKET]

[zvideo.mkv]
[PACKET]
codec_type=video
stream_index=0
pts=67
pts_time=0.067000
dts=N/A
dts_time=N/A
duration=N/A
duration_time=N/A
convergence_duration=N/A
convergence_duration_time=N/A
size=238017
pos=644
flags=K
[/PACKET]

[PACKET]
codec_type=video
stream_index=0
pts=12846
pts_time=12.846000
dts=12813
dts_time=12.813000
duration=33
duration_time=0.033000
convergence_duration=N/A
convergence_duration_time=N/A
size=27305
pos=27899931
flags=_
[/PACKET]

[zaudio.ac3]
[PACKET]
codec_type=audio
stream_index=0
pts=0
pts_time=0.000000
dts=0
dts_time=0.000000
duration=2880
duration_time=0.032000
convergence_duration=N/A
convergence_duration_time=N/A
size=1024
pos=0
flags=K
[/PACKET]

[PACKET]
codec_type=audio
stream_index=0
pts=1154880
pts_time=12.832000
dts=1154880
dts_time=12.832000
duration=2880
duration_time=0.032000
convergence_duration=N/A
convergence_duration_time=N/A
size=1024
pos=410624
flags=K
[/PACKET]

zoutput.mkv seems to be using two reorder frames (more on this later) and the very last packet in storage/coding order is not the last packet in display order, but only the second-to-last in display order. This both explains why the pts-dts-offset of the last packet (according to coding order) only amounts to one frame and why the duration of this file is 12.85s (actually 12.7794s+2*0,03335s = 12.8461s).

Before 9d4fdfe24c731d1880797dee65365154b41c1dea (fixing #4487), the timestamps (video and audio, keeping sync) would be shifted so that the dts is nonnegative which in case of reorder frames means that the very first pts can't be zero. In this case the shifting changed the first pts in done2 to 67ms (equal to two frames; hence me thinking that there are two reorder frames). This also adds 67ms to the duration (because FFmpeg's Matroska muxer uses max(timestamp + duration) (max over all packets) as duration; it does not subtract the lowest timestamp), explaining why the interleaved file is longer.

When demuxing the audio from this file to an elementary stream (which does not have explicit timestamps at all), the shifting can't be preserved at all, hence you have the original duration again.

But when remuxing the video to another Matroska file, the timestamps can be preserved; given that even the dts of the first packet is nonnegative, no further shifting is required and the timestamps of the remuxed video are the same as the timestamps in the interleaved file. The shifting adds the duration of two frames to the video's reported duration, resulting in 12.91s (up from 12.85s (notice that 12.85s was rounded up from a more precise value which is the reason why adding 67ms to the duration results in a reported increase of only 60ms)).

Note: See TracTickets for help on using tickets.