Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: cheesemonster on March 11, 2018, 05:24:56 PM

Title: Audio encoding chooses channel format at beginning of file, not cutpoint
Post by: cheesemonster on March 11, 2018, 05:24:56 PM
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
Title: Re: Audio encoding chooses channel format at beginning of file, not cutpoint
Post by: eumagga0x2a on March 11, 2018, 06:51:08 PM
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?
Title: Re: Audio encoding chooses channel format at beginning of file, not cutpoint
Post by: cheesemonster on March 12, 2018, 01:14:01 PM
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.
Title: Re: Audio encoding chooses channel format at beginning of file, not cutpoint
Post by: eumagga0x2a on March 12, 2018, 01:29:25 PM
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.
Title: Re: Audio encoding chooses channel format at beginning of file, not cutpoint
Post by: hai on May 22, 2018, 06:30:01 AM
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.
Title: Re: Audio encoding chooses channel format at beginning of file, not cutpoint
Post by: eumagga0x2a on May 22, 2018, 07:11:08 PM
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 (https://github.com/mean00/avidemux2/commit/04d3ab1c2496a3456f926e38ad046fbdb288f47c) (http://avidemux.org/smif/index.php/topic,18332.0.html (http://avidemux.org/smif/index.php/topic,18332.0.html)).
Title: Re: Audio encoding chooses channel format at beginning of file, not cutpoint
Post by: odin on May 15, 2020, 04:27:14 PM
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 ...