I have a very specific pipeline I need to set up, it starts with an mov file from Avid which gets transcoded to mkv for internal review and .264 for burning to Blu-ray in Scenarist. It goes:

.mov (DNxHD) -> .mkv (h264) -> .264

For purposes of quality and speed I transcode to .mkv in FFMPEG and then when the time comes to make a Blu-ray I demux the mkv to the .264, however I'm told this is throwing a very ambiguous error in scenarist and I can't figure out what I'm doing wrong. Interestingly if I transcode directly to .264 instead of demuxing it there is no problem, so this appears to be a metadata issue. Here's the demux recipe I'm using:

-i input.mkv -codec copy -bsf:v h264_mp4toannexb output.264

Here's the transcode recipe if that is useful:

-i input -c:v libx264 -preset fast -tune film -b:v 20000k -maxrate 35000k -bufsize 30000k -level 4.1 -pix_fmt yuv420p -x264opts bluray-compat=1:open-gop=1:slices=4:keyint=24 -r fps outfile.mkv

  • Add -bsf:v dump_extra=k and check. Annex B bsf is auto-inserted since v3.2
    – Gyan
    Feb 7 '19 at 19:11
  • @Gyan Just tried that and Scenarist says "Media file invalid". If I inspect the file it seems almost all metadata is now gone, and if I check it in FFPROBE I get a massive stream of PPS and SPS errors. Tried dump_extra=all and got a 0kb file...
    – Spencer
    Feb 7 '19 at 19:39
  • What was the original Scenarist error? Workaround is to transcode to .264 and mux that into MKV.
    – Gyan
    Feb 7 '19 at 20:18
  • @Gyan The error says "Parse error: The garbage data exists in ES. offset=0, size=773". I am also re-evaluating if we really need to go to .264. If some other format works then I believe I can change this requirement, though I did just try an m4v and it did not work. (though encoding an m4v from Adobe Media Encoder did work...)
    – Spencer
    Feb 7 '19 at 22:03
  • Contacted Scenarist and they gave us a 46 page white paper on Blu-Ray specifications! Wasn't quite able to glean anything useful out of it yet, except that "Video streams shall be...MPEG-4 AVC video format (ISO/IEC 14496-10) compliant...". Don't know if anyone can decypher what that means or not...
    – Spencer
    Feb 8 '19 at 5:12

The demuxed H264 stream has the same metadata content, however it is rearranged, compared to the directly produced .264 stream. So far, I don't see a way to rearrange it to match.

So, transcode directly to 264 and use mp4box to generate a stream inside a container

mp4box -add direct.264 -new muxed.mp4

You can then use ffmpeg to mux to MKV.

ffmpeg -i muxed.mp4 -c copy muxed.mkv

mp4box is part of the GPAC project. Get a nightly build from https://gpac.wp.imt.fr/downloads/gpac-nightly-builds/

To do this entirely within ffmpeg, you can use the tee muxer to pipe a AVI mux to another ffmpeg instance

ffmpeg -i input.mov -map 0:v -vsync cfr -r fps -pix_fmt yuv420p -c:v libx264 -preset fast -tune film -b:v 20000k -maxrate 35000k -bufsize 30000k -level 4.1 -x264opts bluray-compat=1:open-gop=1:slices=4:keyint=24 -f tee "scenarist.264|[f=avi]pipe:1" | ffmpeg -f avi -i - -c copy -y playback.mkv

Verify the

  • Thanks Gyan, but unfortunately this is the backend for an application I built and I need it to be portable so GPAC does not work. However I did just figure out a ridiculous but workable solution. I cannot mux .264 directly to .mkv, however this is the only workflow I've found that does the trick: mov -> 264 -> avi -> mkv. For whatever reason the avi muxer seems to regenerate whatever metadata is needed for the mkv... Because they're all just stream copies it isn't too slow. Do you know of a way to go 264 -> avi -> mkv in one process?
    – Spencer
    Feb 11 '19 at 22:34
  • Added workaround. There are bugs with the method you've used. In H264 streams with hierarichical B-frames, ffmpeg may reorder B-frames presentation order. However, Blu-ray limits the B-frame count, so you may be OK. Test a few MKVs, though.
    – Gyan
    Feb 12 '19 at 5:46
  • What's the barrier with GPAC? It's FOSS and cross-platform. Installation is not needed.
    – Gyan
    Feb 12 '19 at 5:46
  • Thanks for all of your help! I couldn't find a portable version of GPAC, just an exe? Your tee mux recipe gave me a better idea, why not just transcode a .264 and .mkv at the same time? Then I don't need to mux the .264 later, that can just go straight to scenarist and I can mux the mkv with chapters and audio later. Don't know why I didn't think of it before!
    – Spencer
    Feb 12 '19 at 23:09
  • why not just transcode a .264 and .mkv at the same time? --> that's double CPU + RAM.
    – Gyan
    Feb 13 '19 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.