What format/syntax is needed for ffmpeg to output the same input to several different "output" files? For instance different formats/different bitrates? Does it support parallelism on the output?
7 Answers
The ffmpeg documentation has been updated with lots more information about this and options depend on the version of ffmpeg you use: http://ffmpeg.org/trac/ffmpeg/wiki/Creating%20multiple%20outputs

- 228
- 3
- 10
-
1What about multiple stream input and ofcourse multiple output? – A Sahra Apr 16 '17 at 04:44
-
1For multiple input I think you need to use -map : https://trac.ffmpeg.org/wiki/Map – rogerdpack Jun 20 '20 at 20:08
From FFMpeg documentation, FFmpeg writes to an arbitrary number of output "files".
Just make sure each output file (or stream), is preceded by the proper output options.

- 3,902
- 2
- 21
- 13
I use
ffmpeg -f lavfi -re -i 'life=s=300x200:mold=10:r=25:ratio=0.1:death_color=#C83232:life_color=#00ff00,scale=1200:800:flags=16' \
-f lavfi -re -i sine=frequency=1000:sample_rate=44100 -pix_fmt yuv420p \
-c:v libx264 -b:v 1000k -g 30 -keyint_min 60 -profile:v baseline -preset veryfast -c:a aac -b:a 96k \
-f flv "rtmp://yourname.com:1935/live/stream1" \
-f flv "rtmp://yourname.com:1935/live/stream2" \
-f flv "rtmp://yourname.com:1935/live/stream3" \

- 680
- 7
- 11
-
4Use the [tee muxer](https://ffmpeg.org/ffmpeg-formats.html#tee) so you only have to encode once, not three times. – llogan Jun 10 '19 at 20:36
based on http://sonnati.wordpress.com/2011/08/30/ffmpeg-–-the-swiss-army-knife-of-internet-streaming-–-part-iv/ and http://ffmpeg-users.933282.n4.nabble.com/Multiple-output-files-td2076623.html
ffmpeg -re -i rtmp://server/live/high_FMLE_stream -acodec copy -vcodec x264lib -s 640×360 -b 500k -vpre medium -vpre baseline rtmp://server/live/baseline_500k -acodec copy -vcodec x264lib -s 480×272 -b 300k -vpre medium -vpre baseline rtmp://server/live/baseline_300k -acodec copy -vcodec x264lib -s 320×200 -b 150k -vpre medium -vpre baseline rtmp://server/live/baseline_150k -acodec libfaac -vn -ab 48k rtmp://server/live/audio_only_AAC_48k
Or you could pipe the output to a "tee" and send it to "X" other processes to actually do the encoding, like
ffmpeg -i input - | tee ...
which might save cpu since it might enable more output parallelism, which is apparently otherwise unavailable
see http://ffmpeg.org/trac/ffmpeg/wiki/Creating%20multiple%20outputs and here

- 62,887
- 36
- 269
- 388
-
2This is quite outdated. There is no `x264lib` encoder, and `-vpre` has been deprecated a long time ago. `-b` alone is ambiguous and should not be used. – slhck Oct 27 '13 at 09:33
-
1Yeah http://ffmpeg.org/trac/ffmpeg/wiki/Creating%20multiple%20outputs has more up to date information than this post did... – rogerdpack Oct 28 '13 at 22:03
Is there any reason you can't just run more than one instance of ffmpeg
? I've have great results with that ...
Generally what I've done is run ffmpeg
once on the source file to get it to sort of the base standard (say a higher quality h.264 mp4 file) this will make sure your other jobs will run more quickly if your source file has any issues since they'll be cleaned up in this first pass
Then use that new source/input file to run x number of ffmpeg
jobs, for example in bash ...
Where you see "..." would be where you'd put all your encoding options.
# create 'base' file
ffmpeg -loglevel error -er 4 -i $INPUT_FILE ... INPUT.mp4 >> $LOG_FILE 2>&1
# the command above will run and then move to start 3 background jobs
# text output will be sent to a log file
echo "base file done!"
# note & at the end to send job to the background
ffmpeg ... -i INPUT.mp4 ... FILENAME1.mp4 ... >/dev/null 2>&1 &
ffmpeg ... -i INPUT.mp4 ... FILENAME2.mp4 ... >/dev/null 2>&1 &
ffmpeg ... -i INPUT.mp4 ... FILENAME3.mp4 ... >/dev/null 2>&1 &
# wait until you have no more background jobs running
wait > 0
echo "done!"
Each of the background jobs will run in parallel and will be (essentially) balanced over your cpus, so you can maximize each core.

- 26,590
- 6
- 68
- 1,285
-
1Yeah you could, though it's said to "save cpu" if you use one input process (http://ffmpeg-users.933282.n4.nabble.com/Multiple-output-files-td2076623.html) and sometimes it isn't possible, for example in live streaming... – rogerdpack Aug 20 '12 at 20:31
-
I'm messing around with reading `/dev/video0` and the second `ffmpeg` complains that the device is busy. – Daniel Earwicker Jul 17 '17 at 17:28
I have done like that
ffmpeg -re -i nameoffile.mp4 -vcodec libx264 -c:a aac -b:a 160k -ar 44100 -strict -2 -f flv \
-f flv rtmp://rtmp.1.com/code \
-f flv rtmp://rtmp.2.com/code \
-f flv rtmp://rtmp.3.com/code \
-f flv rtmp://rtmp.4.com/code \
-f flv rtmp://rtmp.5.com/code \
but is not working completely well as i was expecting and having on restream with nginx

- 49
- 1
- 8
Well I used this way. So you take input once, define settings for each output that's it. If you want 3 output files, just add so.
command = (
# Start of the command string
f"sudo ffmpeg -i {input_path}/{content_id}.mp4 "
f"-c:a copy -vf scale=-2:{height} -c:v libx264 -profile:v main -level:v 4.0 "
f"-x264-params scenecut=0:open_gop=0:min-keyint=72:keyint=72 "
f"-minrate {bitrate} -maxrate {bitrate} -bufsize {bitrate} -b:v {bitrate} "
f"-y -preset veryfast -crf 20 -movflags +faststart "
# First output file path
f"{output_path1}/{content_id}_{height}p_{bitrate}.mp4 "
# Second output file path
f"-y -preset veryfast -crf 20 -movflags +faststart "
f"{output_path2}/{content_id}_{height}p_{bitrate}.mp4 "
# Options that are not part of the file paths
"-loglevel quiet -stats"
# End of the command string
)

- 504
- 2
- 14