Audio encoding chooses channel format at beginning of file, not cutpoint

Started by cheesemonster, March 11, 2018, 05:24:56 PM

Previous topic - Next topic

cheesemonster

Given a MPEG-TS recording that may consist of an TV earlier programme recorded in 2.0 AC3 followed by a 5.1 AC3 recording in the same file, setting the A-B cutpoints to save the programme section with 5.1AC3 recording will result in using a 2.0 channel format only when audio encoding in any format.  It seems that the channel output is defined by the start of the MPEG-TS file rather than what is set at the start of the cut-point.

Tested with avidemux master from 20180301

eumagga0x2a

Yes, this is a current design limitation. Does saving the part of the stream after the switch to 5.1 in copy mode as an intermediate step and loading the resulting video file help?

cheesemonster

Yes that does work, with the caveat that the programme and sound channel switch may start on a B-frame, so there's some frame-loss/sync issue when using copy.

eumagga0x2a

This is exactly the reason I wrote "after the switch to 5.1". You must start the selection on an IDR to avoid video corruption (notwithstanding the issue of streams which don't include IDR frames at all). Don't even try to cut at the B-frame where the switch occurs. Avidemux will try to go back to the previous I-frame and you will probably end up with the 2-channels layout again.

hai

Is there an easy way to find out from within avidemux where the audio format changes in such a MPEG-TS recording?
I'd rather lose a few seconds of a recording than have broken audio. Cutting at the first I-Frame of the desired subset of the recording is not a guarantee for success unless all TV stations switch the audio format before or at the first I-Frame after the movie starts.

eumagga0x2a

If you use Avidemux built from 2018-05-13 or earlier, you can hear when the layout switches. After that, you would need to remove the *ad_a52.* plugin file first, in order to force Avidemux to use the internal lavcodec instead of liba52 for AC3 decoding due to [audioDecoders/ac3] Force downmix to stereo on switch from 2.0 to 5.0/5.1, based on patch by Basic.Master (http://avidemux.org/smif/index.php/topic,18332.0.html).

odin

I know this thread is quite old. But maybe s.o. is interested in my solution for this problem.
Starting point is an mpeg-ts stream which changes from AC3-2ch to 5ch, e.g. like:
2225555555...
My workaround: from the middle of the file, I save a few seconds in copy-mode using mpeg-ts output format (typically I use the part which shows the movie title, and of course it must have 5ch).
Then I close the file in avidemux, open instead my saved short clip, append the original mpeg-ts, do some cutting, and save it again (incl. the short clip from the beginning!), e.g. into .MP4 container (copy-mode). Result might look like this:
525555555...
Didn't had problems with this approach so far ...