<p>Use</p>

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

<p>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 (<code>.264</code>, <code>.h264</code>) 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.</p>

<p>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.</p>

CC BY-SA 4.0
2020-03-03T08:04:18.550Z
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
CC BY-SA 4.0
2020-03-03T08:09:18.187Z
This is a tee-specific syntax so see https://ffmpeg.org/ffmpeg-formats.html#Options-12
Gyan
CC BY-SA 4.0
2019-01-26T18:04:43.853Z
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
CC BY-SA 4.0
2019-01-26T06:10:39.327Z
2019-01-26T06:10:39.327Z
Gyan
<p>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:</p>

<pre><code>-i input.mov -vcodec libx264 -map 0:v output.mkv
-i input.mov -vcodec libx264 -map 0:v output.264
</code></pre>

<p>However the following gives me an error:</p>

<pre><code>-i input.mov -vcodec libx264 -map 0:v -f tee "output.mkv|output.264"
</code></pre>

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

<ffmpeg>
Error when using the tee pseudo-muxer in FFMPEG
Spencer
# Error when using the tee pseudo-muxer in FFMPEG

(Asked by: username_0 on 2019-01-26)

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?

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2019-01-26. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: Thanks username_1, 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).  
> **username_2**: 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.  
> **username_1**: This is a tee-specific syntax so see https://ffmpeg.org/ffmpeg-formats.html#Options-12  

---

