FFMPEG Live Video Streaming - xrchisense/xrevent-broadcaster-unity GitHub Wiki

Complete ffmpeg documentation: http://ffmpeg.org/ffmpeg-all.html#rtmp

General Live Streaming Terminology

Image Source: https://trac.ffmpeg.org/wiki/ffserver

Streaming HLS from a Windows Desktop

Test Pipeline: H264 video -> Encoder -> Video Segmenter -> Video Delivery

This deletes files after they exeed the number of files listed in the .m3u8

ffmpeg -re -stream_loop -1 -i legend.mp4 -acodec copy -vcodec copy -f hls -hls_time 4 -hls_flags delete_segments stream.m3u8

This overwrites the segments as it uses segment_Wrap:

ffmpeg -re -stream_loop -1 -i legend.mp4 -acodec copy -vcodec copy -f segment -segment_list live.m3u8 -segment_list_type hls -segment_list_size 5 -segment_time 4 -segment_wrap 12 live%03d.ts

Streaming RTMP from a Windows Desktop

ffmpeg -re -stream_loop -1 -i legend.mp4 -acodec copy -vcodec copy -f flv -listen 1 rtmp://localhost:1935/

Stream video to webspace via ftp

Test Pipeline: H264 video -> Encoder -> Video Segmenter -> ftp Note: The URL must be Percent Encoded at least for the special characters. Othen you may have those in the password.

!Issue!: ffmpeg can not execute DELETE command on FTP. Is there a way to use the segmenter???

ffmpeg -re -stream_loop -1 -i legend.mp4 -acodec copy -vcodec copy -f hls -hls_time 4 -hls_flags delete_segments ftp://user:[email protected]:21/xrevent-creator.de/httpdocs/upload/videos/live.m3u 8

Progressive Streaming (Video Download)

When encoding MP4 videos for streaming make sure they are encoded with the video header data at the beginning of the file. You normally do this by selecting “Fast Start” in QuickTime encoder, or use the “-movflags faststart” option in FFMPEG, Other encoders will have a similar option. To prepare an MP4 for streaming using FFMPEG you can use the following command: ffmpeg -i %1 -acodec copy -vcodec copy -movflags faststart %1-streaming.mp4

HowTo https://trac.ffmpeg.org/wiki/ffserver

Streaming to Janus

Method 1: Streaming a local file (used on Linux Server)

ffmpeg -re -stream_loop -1 -flags low_delay -i timelineLow.mkv -c:v copy -an -f rtp rtp://XXX.XXX.XXX.XXX:5004 -c:a copy -vn -f rtp rtp://XXX.XXX.XXX.XXX:5002

-re: Realtime: Streams the file at the fps rate the file is encoded at.

-stream_loop -1 Loops the File X amount of times. -1 loops continuously.

-flags low_delay I don't know if this does anything. (Signals the encoder to use a low_delay Mode)

-i The Input file.

-c:v copy Video Codec: copy means the Video is not encoded again.

-an Audio none

-f rtp rtp://XXX.XXX.XXX.XXX:5004 The location where the video stream is pointed.

-c:a copy -vn -f rtp rtp://XXX.XXX.XXX.XXX:5002 Same as above but for audio.

Method 2: Streaming from OBS (used on Windows).

.\ffmpeg.exe -listen 1 -timeout 1000 -flags low_delay -i tcp://localhost:1980/live/webrtc -b:v 800k -c:v libvpx -an -f rtp rtp://XXX.XXX.XXX.XXX:5004 -b:a 48k -c:a libopus -vn -f rtp rtp://XXX.XXX.XXX.XXX:5002

-listen 1 -timeout 1000 Tells ffmpeg to listen for Input for 1000 seconds.

-flags low_delay I don't know if this does anything. (Signals the encoder to use a low_delay Mode)

-i tcp://localhost:1980/live/webrtc The URL where ffmpeg is listening.

Here is the OBS Config:

OBS CONFIG

-b:v 800k -c:v libvpx ffmpeg re-encodes the video to vpX with a bitrate of 800k.

-an -f rtp rtp://XXX.XXX.XXX.XXX:5004 "Audio None" and the Endpoint for the Videostream.

-b:a 48k -c:a libopus ffmpeg re-encodes the audio to Opus with a bitrate of 48k.

-vn -f rtp rtp://XXX.XXX.XXX.XXX:5002 "Video none" and the Endpoint for the Adiostream.