Error when using the tee pseudo-muxer in FFMPEG 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?
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.