Command for sending streaming media by FFMPEG (UDP, RTP, rtmp)

Source: Internet
Author: User

These two days I have studied the command for sending streaming media from FFMPEG. Here I will record it for memo.

1. udp1.1. send the H.264 bare stream to the multicast address.

Note: The multicast address ranges from 224.0.0.0 to 239.255.255.255.

The following command sends the H.264 raw stream "Chunwan. h264" to the address UDP: // 233.233.233.223: 264

ffmpeg -re -i chunwan.h264 -vcodec copy -f h264 udp://233.233.233.223:6666

Note 1:-Re must be added, indicating that data is sent at the frame rate. Otherwise, FFMPEG sends data at the highest efficiency.

NOTE 2:-vcodec copy must be added; otherwise, FFMPEG recodes the input H.264 bare stream.

1.2. UDP playing the H.264 bare stream

ffplay -f h264 udp://233.233.233.223:6666

Note: Use-F to indicate that the data type is H.264.

You can add some parameters during playback, such as-max_delay. The following command sets-max_delay to 100 MS:

ffplay -max_delay 100000 -f h264 udp://233.233.233.223:6666

1.3. Send the MPEG2 raw stream to the multicast address

The following command reads the data from the local camera, encoded as MPEG2, and sent to the UDP: // 233.233.233.223: 6666 address.

ffmpeg -re -i chunwan.h264 -vcodec mpeg2video -f mpeg2video udp://233.233.233.223:6666

1.4. Play the MPEG2 bare stream

Specify-vcodec as mpeg2video.

ffplay -vcodec mpeg2video udp://233.233.233.223:6666

2. rtp2.1. send the H.264 bare stream to the multicast address.

The following command sends the H.264 raw stream "Chunwan. h264" to the address RTP: // 233.233.233.223: 264

ffmpeg -re -i chunwan.h264 -vcodec copy -f rtp rtp://233.233.233.223:6666>test.sdp

Note 1:-Re must be added, indicating that data is sent at the frame rate. Otherwise, FFMPEG sends data at the highest efficiency.

NOTE 2:-vcodec copy must be added; otherwise, FFMPEG recodes the input H.264 bare stream.

NOTE 3: the rightmost "> test. SDP" is used to store the output information of FFMPEG to form an SDP file. This file is used to receive RTP. If "> test. SDP" is not added, FFMPEG directly outputs the SDP information to the console. Copy the information and save it as a. SDP text file suffix. It can also be used to receive the RTP stream. After "> test. SDP" is added, you can directly Save the SDP information as text.


2.2. Play the RTP that carries the H.264 bare stream.

ffplay test.sdp

3. rtmp3.1. send the H.264 bare stream to the rtmp server (flashmedia server, red5, etc)

Run the command to send the "Chunwan. h264" of the H.264 bare stream to the rtmp URL where the host is localhost, the application is oflademo, and the path is livestream.

ffmpeg -re -i chunwan.h264 -vcodec copy -f flv rtmp://localhost/oflaDemo/livestream

3.2. Play rtmp

ffplay “rtmp://localhost/oflaDemo/livestream live=1”

Note: It is best to enclose the rtmp URL of ffplay in double quotation marks and add the live = 1 parameter to the end to represent real-time streams. In fact, this parameter is passed to librtmp of FFMPEG.

For details about how to process rtmp, refer to the article: How to Use FFMPEG to process rtmp Streaming Media

 

4. Test latency

There is one way to test the latency, that is, one way to play the sender's video, and the other way to play the stream received by the streaming media. Two Stream play modes are available: FFMPEG and ffplay.

Playing Through ffplay is a well-known method, for example:

ffplay -f dshow -i video="Integrated Camera"

You can play back the camera with the local name "integrated camera.

In addition, you can use FFMPEG to play back the video by specifying the "-f sdl" parameter. For example:

ffmpeg -re -i chunwan.h264 -pix_fmt yuv420p –f sdl xxxx.yuv -vcodec copy -f flv rtmp://localhost/oflaDemo/livestream

You can send video streams to the rtmp server while playing videos through SDL.

NOTE 1: The XXXX. YUV specified after SDL is not output.

NOTE 2: FFMPEG can specify multiple outputs. This command specifies two outputs.

The method of the playback receiver has been mentioned previously and will not be detailed here.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.