当前位置:网站首页>Use ffmpeg command line to push UDP and RTP streams (H264 and TS), and ffplay receives
Use ffmpeg command line to push UDP and RTP streams (H264 and TS), and ffplay receives
2022-07-02 15:46:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
We often use UDP or RTP To send and receive streaming media , After developing the program, you need to build an environment for testing , At this time, you may need a streaming terminal or a receiving terminal . For the streaming end , We can use FFmpeg The tool can easily complete this function , You only need to hit a command to realize streaming , And support a variety of network protocols (UDP/RTP/RTSP/RTMP). At the receiving end, we can use ffplay, This program is also in FFmpeg Toolkit's Bin Inside the directory . You can use these two tools to push or receive according to your needs , Now let's take the transmission protocol UDP、RTP Based on , Introduce the usage of the two tools in several most common streaming scenarios .
1. Use RTP send out H264
FFmpeg Streaming command :
ffmpeg -re -i d:\videos\1080P.264 -vcodec copy -f rtp rtp://127.0.0.1:1234This command line implements reading a H264 file , Send data at the inherent frame rate of the source file ( add -re Parameters ), The output stream protocol is rtp.
ffplay The command of the receiving end :
ffplay -protocol_whitelist "file,udp,rtp" -i rtp://127.0.0.1:1234Be careful :ffplay Of RTP The protocol is not enabled by default , Need to add -protocol_whitelist Parameter put RTP The agreement is added to the white list . however , If you execute the above command, you may make an error , because ffplay Use RTP Protocol reception requires a SDP file , This file defines the format information of the input stream and the IP And port number .
We can get FFmpeg Export a SDP, The command line is as follows :
ffmpeg -re -i d:\videos\1080P.264 -vcodec copy -f rtp rtp://127.0.0.1:1234>test_rtp_h264.sdpHere's a SDP Examples of documents :
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 56.15.102
m=video 1234 RTP/AVP 96
a=rtpmap:96 H264/90000(SDP Information description of the document : Transfer protocol :RTP/AVP, The receiver IP:127.0.0.1, Receive port number :1234 , PayloadType:96 , Video format :H264 )
In the above SDP File for input let ffplay Turn on the flow , The command line is :
ffplay -protocol_whitelist "file,udp,rtp" -i test_rtp_h264.sdp2. Use UDP send out TS flow
FFmpeg Streaming command :
ffmpeg -re -i d:\videos\1080P.264 -vcodec copy -f mpegts udp://127.0.0.1:1234ffplay Receive commands for :
ffplay -protocol_whitelist "file,udp,rtp" -i udp://127.0.0.1:12343. Use RTP send out TS flow
Many people think this situation is similar to the above , Use the following streaming command ( error ):
ffmpeg -re -i d:\videos\1080P.264 -vcodec copy -f mpegts rtp://127.0.0.1:1234But actually not , I started using this command , Tried many times and always failed , The reason for the failure is : The package sent is missing RTP head , There is an error in the output protocol . actually , The right order is :
ffmpeg -re -i d:\videos\1080P.264 -vcodec copy -f rtp_mpegts rtp://127.0.0.1:1234ffplay Commands received :
ffplay -protocol_whitelist "file,udp,rtp" -i rtp://127.0.0.1:1234Or open one SDP file ,SDP File pair TS Writing method of stream :
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
m=video 1234 RTP/AVP 33
a=rtpmap:33 MP2T/90000( Be careful :FFmpeg send out TS The flow of RTP PayloadType No 96 It is 33)
There's another problem : In the early ffmpeg Version does not support rtp_mpegts Output protocol , You can use the command ffmpeg -formats see ffmpeg Whether this output protocol is supported . I use FFmpeg The version is ffmpeg-20180209 It supports this kind of agreement .
4. Use RTP Send audio stream and video stream respectively
FFmpeg command :
ffmpeg -re -i <media_file> -an -vcodec copy -f rtp rtp://<IP>:5004 -vn -acodec copy -f rtp rtp://<IP>:5005 > test.sdpFFplay Received SDP file :
SDP:
v=2
m=video 5004 RTP/AVP 96
a=rtpmap:96 H264
t=0 0
a=framerate:25
c=IN IP4 192.168.0.100
m=audio 5005 RTP/AVP 97
a=rtpmap:97 PCM/8000/1
a=framerate:25
c=IN IP4 192.168.0.100————————————————————————————————–
The above introduction uses the command line method
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/147723.html Link to the original text :https://javaforall.cn
边栏推荐
猜你喜欢

2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)

树-二叉搜索树

PTA ladder game exercise set l2-001 inter city emergency rescue

Bing. Com website
![[leetcode] 1905 statistics sub Island](/img/82/d2f7b829f5beb7f9f1eabe8d101ecb.png)
[leetcode] 1905 statistics sub Island

Thoroughly understand browser strong cache and negotiation cache

愛可可AI前沿推介(7.2)

The outline dimension function application of small motherboard

《大学“电路分析基础”课程实验合集.实验六》丨典型信号的观察与测量

Leetcode question brushing - parity linked list 328 medium
随机推荐
《大学“电路分析基础”课程实验合集.实验七》丨正弦稳态电路的研究
目标检测—利用labelimg制作自己的深度学习目标检测数据集
Leetcode skimming -- incremental ternary subsequence 334 medium
Leetcode skimming - remove duplicate letters 316 medium
睿智的目标检测23——Pytorch搭建SSD目标检测平台
Pyinstaller打包exe附带图片的方法
高考分数线爬取
怎样从微信返回的json字符串中截取某个key的值?
03. Preliminary use of golang
/bin/ld: 找不到 -llz4
Ant group's large-scale map computing system tugraph passed the national evaluation
【LeetCode】1020-飞地的数量
Bing.com網站
For the problem that Folium map cannot be displayed, the temporary solution is as follows
/bin/ld: 找不到 -lssl
[leetcode] 877 stone game
(5) Flink's table API and SQL update mode and Kafka connector case
《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
已知两种遍历序列构造二叉树
[leetcode] 200 number of islands