1

I am trying to output both an .264 and .mkv at the same time, while not having to encode it twice. The way to do this is of course with the "tee" muxer, however I am getting an error that I cannot figure out. If I encode each output separately as below it works fine:

-i input.mov -vcodec libx264 -map 0:v output.mkv
-i input.mov -vcodec libx264 -map 0:v output.264

However the following gives me an error:

-i input.mov -vcodec libx264 -map 0:v -f tee "output.mkv|output.264"

The error is Cound not write header for output file #0 (incorrect codec parameters ?): Invalid data found when processing input. Error initializing output stream 0:0. How could there be an error in the codec, when each worked just fine on their own?

2

Use

-i input.mov -c:v libx264 -map 0:v -flags +global_header -f tee "output.mkv|[bsfs/v=dump_extra=freq=keyframe]output.264"

The required format of H264 bitstreams can differ based on how it is stored. Containers like MKV and MP4 require that the bitstream parameters be stored globally. Usually the encoder embeds them within the bitstream itself, which is how raw H264 bitstream (.264, .h264) is stored. Now, the encoder normally separates out this metadata or not based on how ffmpeg signals what the output muxer wants. But the tee muxer doesn't represent any container. It is an intermediate layer added to allow reuse of payload packets into multiple outputs. So there is no effective signaling from muxer to encoder.

In your particular use, the added complication is that the two output formats require different bitstream formats. The added global header tells the encoder to generate a MP4/MKV-compatible bitstream and then the bsf filter reinserts the metadata for the .264 output.

| improve this answer | |
  • Thanks Gyan, that did the trick. Seems like good info for whenever you use the Tee muxer - I just ran into the same thing trying to encode a DNxHD .mov to two separate .mkv files (one stereo, one 5.1). – Spencer Jan 26 '19 at 18:04
  • I don't understand what bsfs/v... does. I assume this would be equivalent to the -bsf flag, in which case bsfs/v doesn't make any sense. Of course manuals on such things are either unclear or non-existent. – Ken Sharp Mar 3 at 8:04
  • This is a tee-specific syntax so see ffmpeg.org/ffmpeg-formats.html#Options-12 – Gyan Mar 3 at 8:09

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.