I use this script to stream to a RTMP target and record the stream locally as .mp4 with only one ffmpeg-instance.
-
As input, I use bmdcapture which is piped to ffmpeg. But it can also be used with a static videofile as input.
-
The input will be scaled to 1280px width, maintaining height. Also the stream will stop after a given time (see -t option.)
-
Notes
-
-
I recommend to use this inside a shell script. then you can define the variables ${INPUTFILE}, ${STREAMDURATION}, ${TARGETFILE}, ${STREAMTARGET}.
-
This is in daily use to live-stream a real-world TV show. No errors for nearly 4 years. Some parameters were found by trial-and-error or empiric testing. So suggestions / questions are welcome.
-
-
-
ffmpeg
starts the command
-
-re
Read input at native framerate
-
-i input.mov
The input file. Can also be a - to use STDIN if you pipe in from webcam or SDI.
-
-map 0
map ALL streams from input file to output
-
-flags +global_header
Don't place extra data in every keyframe
-
-vf scale="1280:-1"
Scale to 1280 width, maintain aspect ratio.
-
-pix_fmt yuv420p
convert to 420p chroma subsampling scheme
-
-level 3.1
H264 Level (defines some thresholds for bitrate)
-
-vsync passthrough
Each frame is passed with its timestamp from the demuxer to the muxer.
-
-crf 26
Constant rate factor - basically the quality
-
-g 50
GOP size.
-
-bufsize 3500k
Ratecontrol buffer size (~ maxrate x2)
-
-maxrate 1800k
Maximum bit rate
-
-c:v libx264
encode output video stream using H.264
-
-c:a aac
encode output audio stream using AAC
-
-b:a 128000
The audio bitrate
-
-r:a 44100
The audio samplerate
-
-ac 2
Two audio channels
-
-t ${STREAMDURATION}
Time (in seconds) after which the stream should automatically end.
I use this script to stream to a RTMP target and record the stream locally as .mp4 with only one ffmpeg-instance.
+
As input, I use bmdcapture which is piped to ffmpeg. But it can also be used with a static videofile as input.
+
The input will be scaled to 1280px width, maintaining height. Also the stream will stop after a given time (see -t option.)
+
Notes
+
+
I recommend to use this inside a shell script - then you can define the variables ${INPUTFILE}, ${STREAMDURATION}, ${TARGETFILE}, and ${STREAMTARGET}.
+
This is in daily use to live-stream a real-world TV show. No errors for nearly 4 years. Some parameters were found by trial-and-error or empiric testing. So suggestions/questions are welcome.
+
+
+
ffmpeg
starts the command
+
-re
Read input at native framerate
+
-i input.mov
The input file. Can also be a - to use STDIN if you pipe in from webcam or SDI.
+
-map 0
map ALL streams from input file to output
+
-flags +global_header
Don't place extra data in every keyframe
+
-vf scale="1280:-1"
Scale to 1280 width, maintain aspect ratio.
+
-pix_fmt yuv420p
convert to 4:2:0 chroma subsampling scheme
+
-level 3.1
H264 Level (defines some thresholds for bitrate)
+
-vsync passthrough
Each frame is passed with its timestamp from the demuxer to the muxer.
+
-crf 26
Constant rate factor - basically the quality
+
-g 50
GOP size.
+
-bufsize 3500k
Ratecontrol buffer size (~ maxrate x2)
+
-maxrate 1800k
Maximum bit rate
+
-c:v libx264
encode output video stream as H.264
+
-c:a aac
encode output audio stream as AAC
+
-b:a 128000
The audio bitrate
+
-r:a 44100
The audio samplerate
+
-ac 2
Two audio channels
+
-t ${STREAMDURATION}
Time (in seconds) after which the stream should automatically end.
The outputs, separated by a pipe (|). The first is the local file, the second is the live stream. Options for each target are given in square brackets before the target.