From f427a05c8905979ca345fe43581369c24d9da410 Mon Sep 17 00:00:00 2001 From: kfrn Date: Sat, 14 Oct 2017 11:30:57 +1300 Subject: [PATCH] Move 'Record and Live-Stream simultaneously' to 'Other' section It's not an ideal home for it, but I think it doesn't really belong in the 'Advanced concepts' section, being a command rather than a concept. I've also made a few small edits to the text of the command. --- index.html | 81 +++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/index.html b/index.html index c0a5c96..f44e265 100644 --- a/index.html +++ b/index.html @@ -125,47 +125,6 @@ - - -
-

Record and Live-Stream simultaneously

- -

ffmpeg -re -i ${INPUTFILE} -map 0 -flags +global_header -vf scale="1280:-1,format=yuv420p" -pix_fmt yuv420p -level 3.1 -vsync passthrough -crf 26 -g 50 -bufsize 3500k -maxrate 1800k -c:v libx264 -c:a aac -b:a 128000 -r:a 44100 -ac 2 -t ${STREAMDURATION} -f tee "[movflags=+faststart]${TARGETFILE}|[f=flv]${STREAMTARGET}"

-

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

-
    -
  1. I recommend to use this inside a shell script. then you can define the variables ${INPUTFILE}, ${STREAMDURATION}, ${TARGETFILE}, ${STREAMTARGET}.
  2. -
  3. 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.
  4. -
-
-
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.
-
-f tee
Use multiple outputs. Outputs defined below.
-
"[movflags=+faststart]target-file.mp4|[f=flv]rtmp://stream-url/stream-id"
The output divided by pipe (|). First is local file. Second is Live Stream. Options for each target in square brackets before the target.
-
- -
- -

Change container (rewrap)

@@ -1992,6 +1951,46 @@ ffmpeg -i $file -map 0 -c copy $output
+ + +
+

Record and live-stream simultaneously

+ +

ffmpeg -re -i ${INPUTFILE} -map 0 -flags +global_header -vf scale="1280:-1,format=yuv420p" -pix_fmt yuv420p -level 3.1 -vsync passthrough -crf 26 -g 50 -bufsize 3500k -maxrate 1800k -c:v libx264 -c:a aac -b:a 128000 -r:a 44100 -ac 2 -t ${STREAMDURATION} -f tee "[movflags=+faststart]${TARGETFILE}|[f=flv]${STREAMTARGET}"

+

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

+
    +
  1. I recommend to use this inside a shell script - then you can define the variables ${INPUTFILE}, ${STREAMDURATION}, ${TARGETFILE}, and ${STREAMTARGET}.
  2. +
  3. 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.
  4. +
+
+
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.
+
-f tee
Use multiple outputs. Outputs defined below.
+
"[movflags=+faststart]target-file.mp4|[f=flv]rtmp://stream-url/stream-id"
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.
+
+
+ +