Audio completely replaced by static upon encoding from H.264 source

HandBrake for Mac support
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
arichards1
Posts: 4
Joined: Tue Aug 21, 2018 3:44 pm

Audio completely replaced by static upon encoding from H.264 source

Post by arichards1 »

Description of problem or question:
Upon initiating an encode from an H.264 file encoded on a blackmagic hyperdeck studio mini, the audio of the resulting file is complete static. No attempt at changing audio settings has helped. I've attempted to use all 4 codec options, mono mix down, as well as multiple bitrates to no avail. Thanks for any help you may be able to offer



Steps to reproduce the problem (If Applicable):
Simply initiating an encode of my mp4 file.



HandBrake version (e.g., 1.0.0):
1.1.1



Operating system and version (e.g., Ubuntu 16.04 LTS, macOS 10.13 High Sierra, Windows 10 Creators Update):
MacOS High Sierra 10.13.4



HandBrake Activity Log ***required*** (see How-to get an activity log)
https://pastebin.com/50XgjNtt
Deleted User 11865

Re: Audio completely replaced by static upon encoding from H.264 source

Post by Deleted User 11865 »

Can you provide a short sample of the source we could look at?
Deleted User 11865

Re: Audio completely replaced by static upon encoding from H.264 source

Post by Deleted User 11865 »

Looks like the audio is being mis-detected as big-endian when it's actually little-endian. Funnily enough, my browser also seems to play static with this sample, when VLC and QuickTime Player seem to detect endianness correctly somehow.
Deleted User 11865

Re: Audio completely replaced by static upon encoding from H.264 source

Post by Deleted User 11865 »

Probably fixed in a nightly build: https://handbrake.fr/nightly.php
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by JohnAStebbins »

The nightly build doesn't fix it. On my Linux system, firefox plays static, chrome refuses to play it (says the file can't be previewed), mpv plays static, git head ffmpeg plays static, totem plays correctly, and vlc plays correctly. However, in vlc Tools->Codec Information shows Codec: "PCM S24 BE (in24)". So even though it plays it correctly, there is something in the file that makes it display incorrect codec information.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by JohnAStebbins »

So, here's the problem. ffmpeg doesen't parse some 'qt' extensions in this file because neither the major brand nor compatible brands signalled by the file include 'qt'. But these extensions are present, so ffmpeg gets out of sync in it's parsing. It ends up skipping the "enda" atom that tells it the endianness of the samples due to the error in parsing.

I don't know off hand what the right thing to do is. The ISO spec *does not* have these extra fields. So you're going to incorrectly parse valid ISO media files if you ignore the brand information in the file.
Deleted User 11865

Re: Audio completely replaced by static upon encoding from H.264 source

Post by Deleted User 11865 »

Good catch, I didn't have time to actually test it.
Deleted User 11865

Re: Audio completely replaced by static upon encoding from H.264 source

Post by Deleted User 11865 »

So BlackMagic is creating invalid files apparently. I wonder how VLC manages to play it correctly?
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by JohnAStebbins »

A few possibilities:
1. VLC decodes as LE even though it has read BE from the audio description. Rember that VLC is still showing it as BE in it's codec information.
1. VLC doesn't play ISO media file correctly, but does play *this* invalid file.
2. VLC may have better/different MP4 parser error recovery.

When the error occurs, the next thing expected by ffmpeg is an box ID. ffmpeg doesn't see an ID that it recognizes, so it skips "size" bytes where size is the lesser of the size of the unrecognized box (random "garbage" from the extra qt fields) and the distance to the end of the audio description box. It continues trying to parse additional boxes in this way till it reaches the end of the audio description box.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by JohnAStebbins »

Still doing a bit of guessing here. But I'll bet that VLC succeeds because it assumes the qt format for the remainder of the audio sample description as soon as it sees the box with id "in24". This seems to be a qt specific tag. I tried to do an ffmpeg remux of the file and it won't even write out the associated wave and enda boxes *unless* the output is mov (a.k.a. major brand qt). If the output is mp4 (a.k.a. major brand isom) It ends up generating a completely useless invalid audio track.

And even when the output is mp4, ffmpeg *outputs* a qt version 1 audio sample description whenever the audio is pcm with a bit depth > 16. So it generates an audio sample description that it will not subsequently parse correctly upon playback.

So I think what needs to be done is ffmpeg needs to also *read* a qt version 1 audio sample description whenever the audio is pcm with a bit depth > 16.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by JohnAStebbins »

I opened an issue on github for this https://github.com/HandBrake/HandBrake/issues/1555
arichards1
Posts: 4
Joined: Tue Aug 21, 2018 3:44 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by arichards1 »

Thanks for all of your help. Seems a bit out of my league. I was able to open in quicktime, and export giving me a file able to be compressed with handbrake as we search for a more elegant solution.

Thanks again.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by JohnAStebbins »

I "fixed" the file by editing it with a hex editor and changing "isom" to "qt " in the header. HandBrake was able to transcode the file after that edit. In theory, other tools should be able to change the major brand as well. E.g. this *should* rebrand it:

Code: Select all

MP4Box -brand "qt  " file.mp4
But there is some additional problem with this file that causes MP4Box to get stuck in an infinite loop when trying to do this.

Maybe there is some other similar tool that I'm not aware of that can rebrand the file.
Deleted User 11865

Re: Audio completely replaced by static upon encoding from H.264 source

Post by Deleted User 11865 »

arichards1 wrote: Fri Aug 24, 2018 6:46 pm Thanks for all of your help. Seems a bit out of my league. I was able to open in quicktime, and export giving me a file able to be compressed with handbrake as we search for a more elegant solution.
The tl;dr is that your BlackBox software/hardware is creating invalid MP4 files (i.e. it creates an invalid MOV/MP4 hybrid). If it lets you export to MOV instead, you may be able to skip intermediate steps and feed it directly to HandBrake.
arichards1
Posts: 4
Joined: Tue Aug 21, 2018 3:44 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by arichards1 »

Thanks everyone. Short of a change to black magic or handbrake, looks like this is where it will stay for now. Good news is, importing the original file into final cut pro takes care of the issue as the final export is still compressible. All of our files are edited prior to compression so we should ultimately be good to go. Thanks again for all the input!
User avatar
JohnAStebbins
HandBrake Team
Posts: 5712
Joined: Sat Feb 09, 2008 7:21 pm

Re: Audio completely replaced by static upon encoding from H.264 source

Post by JohnAStebbins »

I submitted a patch to ffmpeg that fixes this issue. Once that goes through review on their mailing list and gets committed, I'll also add it to the patches we apply to HandBrake's copy of ffmpeg. Then the fix will be available in the nightly builds. I'll post a note here and in the github issue I created when it's committed.
Post Reply