Re-stream sample.mp4
This example re-streams the sample.mp4 video.
Notes:
- The sample.mp4 file is about 10 minutes long. FFmpeg stops when streaming ends, so you may have to restart FFmpeg during configuration and testing. To loop your command to generate a constant test stream, preface the FFmpeg command with
FOR /L %% IN (0) DO
- To host FFmpeg on a computer other than the computer, change udp://127.0.0.1:10000 in the example to the IP address and any destination UDP port. Be sure that the specified UDP port is open on any routers or firewalls between the server hosting FFmpeg.
- In a Terminal window, enter one of the following commands.
- For a low-bitrate, low-complexity, low-quality stream that can be played on most devices and systems:
ffmpeg -re -i "%WMSAPP_HOME%/content/sample.mp4" -pix_fmt yuv420p -vsync 1 -threads 0 -vcodec libx264 -r 30 -g 60 -sc_threshold 0 -b:v 512k -bufsize 640k -maxrate 640k -preset veryfast -profile:v baseline -tune film -acodec aac -b:a 128k -ac 2 -ar 48000 -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -bsf:v h264_mp4toannexb -f mpegts udp://127.0.0.1:10000?pkt_size=1316
- For a higher-quality stream:
ffmpeg -re -i "%WMSAPP_HOME%/content/sample.mp4" -pix_fmt yuv420p -vsync 1 -threads 0 -vcodec libx264 -r 30 -g 60 -sc_threshold 0 -b:v 640k -bufsize 768k -maxrate 800k -preset veryfast -profile:v baseline -tune film -acodec aac -b:a 128k -ac 2 -ar 48000 -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -bsf:v h264_mp4toannexb -f mpegts udp://127.0.0.1:10000?pkt_size=1316
- Follow the instructions to set up a live application to re-stream the FFmpeg stream. When configuring the application and adding a stream file on the Stream Files page, use udp://127.0.0.1:10000 as the Stream URI.
Re-stream using passthrough
Content can also be re-streamed by passing the existing encode though FFmpeg without re-encoding. For passthrough re-streaming, use the -codec option and set it to copy. This example re-streams sample.mp4 as a passthrough instead of the full encode shown in the previous example.
ffmpeg -re -i "%WMSAPP_HOME%/content/sample.mp4" -codec copy -bsf:v h264_mp4toannexb -f mpegts udp://127.0.0.1:10000?pkt_size=1316
Re-stream RTSP with password authentication
This example re-streams sample.mp4 with user authentication, level 3.0 logging verbosity, a 24-fps frame rate, 2-second keyframe frequency, 310 kbps bitrate, and 44.1 kHz stereo audio.
ffmpeg -re -i "%WMSAPP_HOME%/content/sample.mp4" -pix_fmt yuv420p -vsync 1 -threads 0 -vcodec libx264 -r 30 -g 60 -sc_threshold 0 -b:v 640k -bufsize 768k -maxrate 800k -preset veryfast -profile:v baseline -tune film -acodec aac -b:a 128k -ac 2 -ar 48000 -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -f rtsp rtsp://username:password@[server-address]:1935/live/myStream
Re-stream RTP with SDP
This example captures local hardware devices, uses a 15-fps frame rate, 8-bit color, and generates an SDP file that contains metadata about the streaming session.
ffmpeg -f dshow -s 640x480 -r 15 -i video="Logitech HD Pro Webcam C920" -f dshow -i audio="Microphone (HD Pro Webcam C920)" -pix_fmt yuv420p -vsync 1 -threads 0 -vcodec libx264 -r 15 -g 30 -sc_threshold 0 -b:v 640k -bufsize 768k -maxrate 800k -preset veryfast -profile:v baseline -tune film -an -f rtp rtp://127.0.0.1:10000 -acodec aac -b:a 128k -ac 2 -ar 48000 -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -vn -f rtp rtp://127.0.0.1:10002 > 10000.sdp
Re-stream UDP-based MPEG-TS
- In a Terminal window, enter:
ffmpeg -re -i inputfile.mp4 -codec copy -bsf:v h264_mp4toannexb -f mpegts udp://[<em>server-address</em>]:1234?pkt_size=1316
- Follow the instructions to create a live application to broadcast the FFmpeg stream.
Re-stream TCP-based MPEG-TS
- In a Terminal window, enter:
ffmpeg -re -i inputfile.mp4 -codec copy -bsf:v h264_mp4toannexb -f mpegts tcp://[<em>server-address</em>]:1234?listen
- Follow the instructions to create a live application to broadcast the FFmpeg stream.
Re-stream UDP-based RTSP
- In a Terminal window, enter:
ffmpeg -re -i inputfile.mp4 -codec copy -f rtsp rtsp://username:password@[server-address]:1935/live/myStream
- Follow the instructions to connect your RTSP encoder and create a live application to broadcast the FFmpeg stream.
Re-stream TCP-based RTSP
- In a Terminal window, enter:
ffmpeg -re -i inputfile.mp4 -codec copy -rtsp_transport tcp -f rtsp rtsp://username:password@[server-address]:1935/live/myStream
- Follow the instructions to connect your RTSP encoder and create a live application to broadcast the FFmpeg stream.
Re-stream RTMP
- In a Terminal window, enter:
ffmpeg -re -i inputfile.mp4 -codec copy -f flv rtmp://username:password@[server-address]:1935/live/myStream
- Follow the instructions to connect your RTMP encoder and create a live application to broadcast the FFmpeg stream.
Re-stream to MP4
- In a Terminal window, enter:
ffmpeg -re -i inputfile.mp4 -codec copy -f mp4 output.mp4
source