August 12, 2020, 03:39:57 pm

News:

--


AAC Dynamic Format Change

Started by TimW, August 12, 2019, 02:03:01 pm

Previous topic - Next topic

TimW

Hi folks, I wonder if anyone has any suggestions or thoughts on this.  When loading a UK freeview broadcast, the audio will often switch dynamically between 6-channel and 2-channel (2-channel is used typically for the adverts).  This confuses the audio decoder to the extent that the audio playback is either corrupted, or else if not corrupted only 2 of the 6 channels play.  Using the cut function to edit out the 2-channel commercial sections doesn't help.  This makes it effectively impossible to recode the audio, or to downmix 6-channel audio down to 2 channels.  I don't know whether the following is relevant, but Windows Media Player is able to cope with these changes and play the files correctly, but maybe it is using a different AAC decoder? 

eumagga0x2a

Of course WMP uses a different decoder.

The current design of Avidemux doesn't allow on-the-fly reconfiguration. The only exception: the a52dec decoder plugin for AC3 supports automatic downmixing on switch from stereo to surround (but AFAIR not the other way round). Apart from that, only mpegts container is purposely built to support on-the-fly format changes.

It is clear that an ability to handle audio format changes for AAC is nice to have, at least in the way a52dec is doing it for AC3, but this would be a major task. Patches as always welcome.

TimW

Many thanks for the rapid response.  It's really good to know it's not just me.  Always there is the suspicion on my part that it's my own PC setup / configuration or something else unique causing issues like this (usually user error in my case!), so it's really helpful to know that's not so here.  Any workarounds from other folks gratefully received, but it looks like that's the end of this line of investigation for now.  Thanks for all the great work on avidemux, it's the best and I use it on pretty much a daily basis. If such audio format changes are incorporated in the future then please can I put a word in for making them "both ways".  That would be necessary for handling commercial breaks, but I completely take on board that it's a major task and not likely to happen - just pleased to know it's not just my setup, so thanks again.

eumagga0x2a

It is not the end but rather the start of investigation. Could you please provide a sample mpegts file (<1 GB in size, please) containing two switches (5.1 --> 2 and back) of audio format via WeTransfer, Mega, Dropbox or Google Drive? The sample should be produces by a binary cutter from the original stream, not by means of saving it with Avidemux, ffmpeg or similar tools.

eumagga0x2a

In case CleanTalk makes it again extra hard to post a link to the sample, please provide the link per PM, I'll post it here for reference.

TimW

Thanks for your PM, I will make the adjustments and re-post tomorrow. 

TimW

As per PM, new files split with HJSplit at

https://drive.google.com/file/d/1Pdx0wg4W7jFeNvs5VLTeayUuTJNkEmWp/view?usp=sharing

password for 7z file is Bdj3^fia1sNsh(s$m4sz92AfKd3

Part 1.ts is 2-to-6 channels and Part 2.ts is 6-to-2-to-6 channels. I have also noticed that if you cut out a bit more than just the adverts (Part 2), sometimes the resulting file will play sound all the way through, and sometimes not.  The same trick doesn't seem to work for the other one (Part 1) which starts 2-channel.  No matter how much I cut off the beginning sometimes I get no sound and sometimes just 2 of the 6 channels playing, but never all 6.

Hope this is useful and thanks again.

eumagga0x2a

Got the both samples, will look at them later, thank you very much.

eumagga0x2a

A switch to 6 channels in a video which starts with stereo won't work without tricks: cut away the part of the original stream with stereo so that it starts with 6 channels using a binary cutter (well, something like tail or dd on Linux would be much more suitable for this task than HJSplit), then append the stream starting with stereo. Now you should be able to save video starting after adverts with 6 channel audio.

TimW

Excellent suggestion, I will try this with a full movie and report back here.

TimW

Thanks, this is an excellent workaround.  On my system it requires a two-stage process to get a good result.  First, cut off the start off the file (using a file splitter, not avidemux) as you suggest so that it starts with all 6 channels playing.  Now recode the audio in avidemux and downmix to 2- channel AC3 (or whatever your preference) without making any cuts whatsoever in avidemux  (i.e. leave all the adverts in).  There is no need to recode the video at stage 1.  Then take the result, load into avidemux, cut out the adverts and recode the video.  This produces a good result.  If you try to cut out the adverts at the first stage, the re-coding of the audio fails after the first cut point, more often than not.  I think this is at least in part because the broadcasters do not make the switch from 6 to 2 channel and back again on the exact same frame as the video changes. 

As a two stage process it's not quick, but it does work and produces good results, apart from tiny audio blemishes when the channels change, which is probably unavoidable. 

Also, for windows folks like myself, I have not been able to find a tool that cuts a given number of bytes off the start of a file.  HJSpit carves the file up into equal sized chunks.  H264 TS Cutter is an alternative that seems to be good enough to get the job done even though it might be altering the stream slightly.  I have also tried splitting with MKVtoolnix, but for some reason this does not give the right result.  Any other windows file cutter suggestions welcome - ideally just want to slice a file in two, but to choose unequal sizes for the two parts.

Despite these caveats, all in all it's a fantastic workaround, many thanks.

TimW

Update on file splitting for windows users.  After some googling I came across this:

http://www.gdgsoft.com/gsplit/

Seems to do a much better job than H264TSCutter.  Not only is it much quicker, but I was getting some audio sync problems with H264TSCutter.   GSplit does allow a single cut with the size of the first segment under user control.  Some trial and error is still required to calculate the number of bytes to cut off the start of the file.  I first do a % calculation based on timecodes and convert that into bytes, but it doesn't always land in exactly the right spot.  Usually the second iteration is good enough.

Huge thanks to eumagga0x2a for guiding me to the workaround.  I've recoded a couple of movies now with the 2-stage process and all looks good. 

eumagga0x2a

Quote from: TimW on August 15, 2019, 10:42:28 am
Some trial and error is still required to calculate the number of bytes to cut off the start of the file.  I first do a % calculation based on timecodes and convert that into bytes, but it doesn't always land in exactly the right spot.


The only requirement for the choice of the location is video codec parameters remaining unchanged and the AAC audio track having again 6 channels, so it should not be difficult to find a suitable one.