HydrogenAudio

Digital Audio/Video => General A/V => Topic started by: For Serious on 2022-07-05 18:12:16

Title: Can Multi-channel wma pro be stored in mkv?
Post by: For Serious on 2022-07-05 18:12:16
I've only tried in MKVToolNix, and it's not letting this unholy union happen.
Just wondering if this is something ffmepg can finagle, or it really is so unholy no one has ever fathomed it before?

The reason for my wanting to do this is simple. I have some movies I want to edit the sound in. I plan to serve them with Plex after. My surround sound system says it will play wma but not opus. Though that doesn't usually mean wma pro, I want to try it. (It's main function is to decode surround sound. If any hardware has a chance of decoding wma pro, this would be it.)

My next thought was to see if Plex will handle the oups support. Online it sounds like that depends on what you play if from. I have a Roku Premiere as the only thing I play my Plex from. Anyway, I found more people with issues than people praising how well it worked for them, and none of it was new within the last year.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-05 20:42:03
Looking at the MKVToolNix source:

https://gitlab.com/mbunkus/mkvtoolnix/-/blob/main/src/common/codec.h

It doesn't look like WMA is supported at all. Isn't it a dead/abandoned format?

I haven't found any use for Opus, either, as none of my devices support it, but can you use multichannel AAC?
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: ktf on 2022-07-05 21:10:26
Here's the matroska codec mapping spec: https://datatracker.ietf.org/doc/draft-ietf-cellar-codec/

There's nothing about WMA in there. There's A_MS/ACM, I don't know whether WMA would fit in that? Documentation links seem to be dead.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-05 21:50:23
ACM is not a codec but a framework for managing codecs. LAME bundles have historically included an ACM version that you can use with VirtualDub to encode audio to MP3, as one example. ACM is outdated and irrelevant now; it's from the days when everything was AVI and CBR.

The Matroska Codec Mappings page:

https://www.matroska.org/technical/codec_specs.html

doesn't mention WMA, either, so it appears to be unsupported.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Apesbrain on 2022-07-06 00:14:24
Convert the WMA to WAV and make your edits.  Encode the multi-channel WAV to AC-3.  MKV can encapsulate AC-3, right?

http://aften.sourceforge.net/
https://www.videohelp.com/software/Aften
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-06 03:51:41
AAC is probably the better choice, but MKV supports both AC3 and EAC3, as well.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: For Serious on 2022-07-06 23:12:17
Okay. Thank you all for pitching in. MKV will not allow for a wma audio track.
I tried an opus version of the audio. It took longer than wma to convert, but was able to be stored in the mkv file just fine.
Playing it back with MPC-HC was less than okay though. The sound was very off and seemed buggy.

I've been seeing vague mentions of multi-channel AAC, but nothing about it actually working or even hard proof that it's real. Though I guess it could be in the realm of wma pro: Everything assumes it's normal 2 channel AAC and breaks when it's not.

I'm willing to give Aften a try, but it says it's based off of ffmpeg, and that doesn't have an amazing AC3 encoder.


Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Apesbrain on 2022-07-07 00:00:46
Everything assumes it's normal 2 channel AAC and breaks when it's not.
I'm pretty sure that foobar2000 reads multi-channel and converts to multi-channel unless you tell it otherwise.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-07 01:18:41
I've been seeing vague mentions of multi-channel AAC, but nothing about it actually working or even hard proof that it's real.
It definitely real, considering I've encoded it before. ;)

You'll want qaac, which is a frontend for Apple's CoreAudio engine. It performs very well on stereo listening tests, and it supports 5.1, too. It's a little annoying to set up if you don't want iTunes installed, as you have to extract the relevant DLL files from the iTunes installer, but it's well worth the effort if you want flexible AAC encoding with the best quality. Apple doesn't update CoreAudio anymore, so you only have to do the setup process once.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: nu774 on 2022-07-07 10:01:08
Indeed, the situation of multi-channel AAC was not good … in the past.
As is written here, channel model of AAC is rather complex and unnecessarily flexible.
http://spectralhole.blogspot.com/2010/08/aac-bistream-flaws-part-1-channel-model.html
In other words, it was difficult for decoder to handle it correctly.

Non-standard AAC channel layout requires special treatments (using PCE: program config element), which was not supported by ffmpeg until this patch on 2012:
https://lists.libav.org/pipermail/libav-devel/2012-February/020612.html
(This patch was written by the same very guy who written the blog above, by the way)

Now ffmpeg can correctly handle multichannel AAC files encoded by qaac, including strange ones such as 6.1ch or 7.0ch.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: For Serious on 2022-07-07 15:42:00
That's good and encouraging to hear about AAC.
I'm not sure what was going on with opus. I tried it on another movie and it played back fine on MPC-HC.
Maybe it has something to do with my editing method. I use ffmpeg to chop it into clips, then join them with MKVToolNix. For each join, the audio seems to go off by half a second. Probably because the final mkv file has a separate audio file for each clip.

Anyway, I don't want to stray too from from the original question.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: DVDdoug on 2022-07-07 19:15:46
Quote
I'm willing to give Aften a try, but it says it's based off of ffmpeg, and that doesn't have an amazing AC3 encoder.
I've used wavtoac3cncoder (http://wieslawsoltes.github.io/wavtoac3encoder/) which I believe is based on Aften and I didn't hear anything wrong with the audio.

Or, it should be quick-and-easy to try Audacity with the FFmpeg library to see if the AC-3 quality is acceptable before making an MKV.    (I don't think I've ever made an AC-3 file with Audacity but I'm pretty sure it can do it as long as it can open the original WMA file.)
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: For Serious on 2022-07-08 15:14:45
There is a chance they have made improvements beyond ffmpeg. Who knows though. I think it says the last update was in 2008.

I did finally run a test on Plex and it converts opus to EAC3. I didn't notice any compression artifacts, but also didn't try very hard. I think it's passable.

The main issue left is I need to figure out a better way to cut sections out of my videos—since joining them with MKVToolNix seems to be the real source of sound inconsistencies.

Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-08 21:14:41
You can use Avidemux to do simple cuts at keyframes, if your goal is to just cut out pieces of a longer video. You need more advanced processing in order to join the pieces together, so you can either spend lots of time messing with Avisynth, or you can pay for a commercial solution, e.g. VideoReDo. You can't cut and join pieces of an existing video without transcoding, so simply cutting and pasting MKV files together will never work.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Porcus on 2022-07-08 21:22:28
You cannot arbitrarily cut and paste, but cutting at keyframes should be lossless. Try https://github.com/mifi/lossless-cut .

Also if Plex converts to EAC3, try if it lets that codec pass through? If that is what it doesn't touch, then that is a case for using it.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-08 23:25:04
You cannot arbitrarily cut and paste, but cutting at keyframes should be lossless. Try https://github.com/mifi/lossless-cut .
Yes, but you cannot paste those chunks together into a new file, because the video frame and audio frame boundaries will not match. The audio usually must be delayed by a certain number of milliseconds at the start of the video in order to synchronise the audio with the video, and if you paste two videos together, the audio in the second half will either be too late or too early and will almost never be aligned properly.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: For Serious on 2022-07-09 21:11:43
Yes, but you cannot paste those chunks together into a new file, because the video frame and audio frame boundaries will not match. The audio usually must be delayed by a certain number of milliseconds at the start of the video in order to synchronise the audio with the video, and if you paste two videos together, the audio in the second half will either be too late or too early and will almost never be aligned properly.
And that's where I'm at now. Since I'm running an AI upscaler, I'm transcoding already. I dumped all the frames as image files into one folder. But yes. After converting them back into a movie file, the sound is super off even after the first cut.

Try https://github.com/mifi/lossless-cut .
I think I tried that last year, but the key frames don't align with scene changes, somehow. I still have it, so I can try again.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-09 21:36:39
Yup. The easiest way to fix it is to transcode the audio, too. Decode the entire soundtrack to WAV so you can make cuts at the appropriate millisecond boundaries, then stitch the WAV files back together and encode the new WAV to AAC or Opus.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Octocontrabass on 2022-07-09 21:41:35
Are you making any changes to the movie aside from upscaling and re-encoding? If not, I see no reason why you would need to cut the audio into segments and stitch it back together in the first place - just transcode (if necessary) and multiplex with your final video.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: For Serious on 2022-07-10 00:14:53
Yes I am. I am cutting out sections. For movies that I don't need to do that, that approach works awesome.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Porcus on 2022-07-10 07:36:07
Ignorant question: Is there any provision in Matroska to set chapter marks so that sections are skipped upon playback?
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: Aleron Ives on 2022-07-10 08:23:38
No, but you can use the ordered chapters feature to cut the film into chunks and then build a "playlist" into the first MKV, which will auto load the other MKV files in the order you specify, as if they were a single contiguous movie. This is useful if you plan to view the files on a PC, but it's fairly useless for hardware players, as they generally don't support ordered chapters.
Title: Re: Can Multi-channel wma pro be stored in mkv?
Post by: For Serious on 2022-07-11 18:50:18
I've used wavtoac3cncoder (http://wieslawsoltes.github.io/wavtoac3encoder/) which I believe is based on Aften and I didn't hear anything wrong with the audio.
Thanks for this. That was really easy to use and I also didn't notice anything bad. Okay, there are tons of options, but I just left them at the defaults.
Yup. The easiest way to fix it is to transcode the audio, too. Decode the entire soundtrack to WAV so you can make cuts at the appropriate millisecond boundaries, then stitch the WAV files back together and encode the new WAV to AAC or Opus.
That's what I ended up doing. I just had to figure out how many milliseconds to cut out at each cut point. There might be some programmatic way to do it, but just by ear, I think I got it good enough. Luckily, I don't plan on doing many more edits like this.