Opened 12 months ago

Last modified 12 months ago

#10379 new defect

concat demuxer with stream copy produces wrong duration for flac files

Reported by: slycordinator Owned by:
Priority: normal Component: ffmpeg
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description (last modified by slycordinator)

Summary of the bug:
Using the concat demuxer with flac files, the generated file's duration is that of the first file in the list
How to reproduce:
1) create two flac files
In my case, I have one named half_sec.flac and another named 1_sec.flac. Both are silent files; half_sec is 0.5 seconds and 1_sec is 1.0 seconds in duration.
2) concatenate them using the concat demuxer as explained at https://trac.ffmpeg.org/wiki/Concatenate#demuxer
3) use ffprobe to see duration is equal to that of the first file and open in media player to see same

mylist.txt:
file '/path/to/half_sec.flac'
file '/path/to/1_sec.flac'

% ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.flac
ffmpeg version N-110692-gc4b3e882f8 Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 10 (Debian 10.2.1-6)
  configuration: --prefix=/usr/local --extra-libs='-lpthread -lm' --bindir=/usr/local/bin --disable-ffplay --disable-doc --disable-htmlpages --disable-manpages --disable-podpages --disable-txtpages --enable-libass --enable-libfdk-aac --enable-libaom --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-gnutls --enable-static --enable-gpl --enable-nonfree
  libavutil      58.  9.100 / 58.  9.100
  libavcodec     60. 14.101 / 60. 14.101
  libavformat    60.  5.100 / 60.  5.100
  libavdevice    60.  2.100 / 60.  2.100
  libavfilter     9.  8.100 /  9.  8.100
  libswscale      7.  2.100 /  7.  2.100
  libswresample   4. 11.100 /  4. 11.100
  libpostproc    57.  2.100 / 57.  2.100
Input #0, concat, from 'mylist.txt':
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Output #0, flac, to 'output.flac':
  Metadata:
    encoder         : Lavf60.5.100
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[out#0/flac @ 0x562a4f405d40] video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3871.962617%
size=       8kB time=00:00:01.44 bitrate=  47.2kbits/s speed=71.7x

% ffprobe output.flac
...
[flac @ 0x560349e5ed80] sample/frame number mismatch in adjacent frames
Input #0, flac, from 'output.flac':
  Metadata:
    encoder         : Lavf60.5.100
  Duration: 00:00:00.50, start: 0.000000, bitrate: 136 kb/s
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16

Results:
Duration of file is equal to the first file found in the temporary text file
As in above output, the first file is 0.5 seconds, the second is 1.0 seconds, the concatenated output file shows a duration of 0.5 seconds, and the file is 0.5 seconds long when opened in media players/audio editing utilities

Expected:
The total duration be the the total for all of the combined files and when opened in an editor/media player, the duration also be that of the combination of all files.

The above result only appears to happen if using '-c copy' or '-c:a copy'.
When run with '-c:a flac' to remux, the resulting file is the correct duration.

Attachments (4)

half_sec.flac (8.2 KB ) - added by slycordinator 12 months ago.
silent flac with duration of 0.5 seconds
1_sec.flac (8.2 KB ) - added by slycordinator 12 months ago.
silent flac with duration of 1.0 seconds
output.flac (8.3 KB ) - added by slycordinator 12 months ago.
output flac which is 0.5 seconds in duration
mylist.txt (39 bytes ) - added by slycordinator 12 months ago.

Download all attachments as: .zip

Change History (7)

by slycordinator, 12 months ago

Attachment: half_sec.flac added

silent flac with duration of 0.5 seconds

by slycordinator, 12 months ago

Attachment: 1_sec.flac added

silent flac with duration of 1.0 seconds

by slycordinator, 12 months ago

Attachment: output.flac added

output flac which is 0.5 seconds in duration

by slycordinator, 12 months ago

Attachment: mylist.txt added

comment:1 by slycordinator, 12 months ago

Description: modified (diff)
Summary: concat demuxer produces wrong duration for flac filesconcat demuxer with stream copy produces wrong duration for flac files

comment:2 by Elon Musk, 12 months ago

You can not concat flac files at demuxer level.

in reply to:  2 comment:3 by slycordinator, 12 months ago

Replying to Elon Musk:

You can not concat flac files at demuxer level.

Then there's a bug that ffmpeg allows you to do it.

Note: See TracTickets for help on using tickets.