Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#9616 closed defect (invalid)

concat of ffmpeg-created opus files defect

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

Description (last modified by Wolfgang May)

There seems to be a problem when concatenating two webm (with
audiocodec opus) files (our application is to edit Big Blue Button raw
source files for revising our teaching materials). Viewing
them with firefox results in errors (both under ubuntu and under windows):

(newly downloaded version ffmpeg-git-20220108-amd64-static.tar.xz)

Minimal example: concat 2x 5 seconds of nothing, generated
by ffmpeg itself:

ffmpeg -f lavfi -i anullsrc -t 5 silence.webm
ffmpeg -f lavfi -i anullsrc -t 5 silence2.webm

## file 'audiofiles.txt':
file 'silence.webm'
file 'silence2.webm'

ffmpeg -f concat -i audiofiles.txt -c copy bla.webm

Playing the audio with firefox stops at 5 seconds with the following output:

[Child 14301, MediaDecoderStateMachine #1] WARNING: Decoder=7fbf36a35300 Decode error: NS_ERROR_DOM_MEDIA_FATAL\
_ERR (0x806e0005) - virtual RefPtr<MediaDataDecoder::DecodePromise> mozilla::OpusDataDecoder::Decode(mozilla::M\
ediaRawData *): Discard padding on interstitial packet: file /build/firefox-oDiU8w/firefox-96.0+build2/dom/medi\
a/MediaDecoderStateMachine.cpp:3568

when the first file is further cut by ffmpeg, there is no problem:

ffmpeg -f lavfi -i anullsrc -t 5 silence.webm
ffmpeg -ss 00:00:01 -i silence.webm -c copy -t 00:00:03 silence1.webm
ffmpeg -f lavfi -i anullsrc -t 5 silence2.webm

## file 'audiofiles2.txt':
file 'silence1.webm'
file 'silence2.webm'

ffmpeg -f concat -i audiofiles2.txt -c copy bla2.webm

=> then it works well with firefox. So the problem seems to be at the end
of the generated file that then is the first file in the concat.

  • same problems for audio files that are not generated by ffmpeg but by obs <https://obsproject.com/>
  • playing the audio with vlc or chrome works.

If this is not considered a bug, I would be happy to learn how this is
done correctly (without re-encoding by filter_complex).

Change History (3)

comment:1 by Wolfgang May, 2 years ago

Description: modified (diff)

comment:2 by mkver, 2 years ago

Resolution: invalid
Status: newclosed

The packets of most audio codecs (including Opus) can't have an arbitrary duration, but can only contain (e.g. decode to) a few discrete values of samples, so that there are only a few possible values for the natural duration of a packet. While the bitstream can't accurately convey the true duration, some containers can and Matroska is one of them. It has the "DiscardPadding" element for this purpose: It contains the information how many of the samples of the packet are invalid (only inserted by the encoder to pad the packet length to one of the permissible values) and should be discarded.

Your error message indicates that Firefox doesn't support DiscardPadding unless it is at the very last packet. This is a bug in Firefox.

I don't know a good workaround for this; the least bad option I can think of is to trim the last audio frame of all non-last files away.

comment:3 by Wolfgang May, 2 years ago

THX.
As far as I understand, the generated+concatenated output files are correct Opus files according to the Opus spec (I do/did not know much of the details of the formats used in webm and the BBB tool, so I could not estimate whether it is a bug in Firefox, or whether chrome is overly tolerant).
So standard-compliant tools should be able to play them, and maybe it will be corrected some time in firefox (with the above information I will do a bugreport there).
Is there a quick way how to -as you mentioned- cut away just the last audio frame with ffmpeg?
(otherwise as a workaround I will create a slightly longer audio file, and cut it in a second step)

Note: See TracTickets for help on using tickets.