当前位置:网站首页>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:1234
This 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:1234
Be 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.sdp
Here'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.sdp
2. 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:1234
ffplay Receive commands for :
ffplay -protocol_whitelist "file,udp,rtp" -i udp://127.0.0.1:1234
3. 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:1234
But 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:1234
ffplay Commands received :
ffplay -protocol_whitelist "file,udp,rtp" -i rtp://127.0.0.1:1234
Or 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.sdp
FFplay 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
边栏推荐
- [leetcode] 344 reverse string
- fastjson List转JSONArray以及JSONArray转List「建议收藏」
- matlab中wavedec2,说说wavedec2函数[通俗易懂]
- 奥比中光 astra: Could not open “2bc5/[email protected]/6“: Failed to set USB interface
- C # get PLC information (kepserver) II
- 士官类学校名录
- [leetcode] 167 - sum of two numbers II - enter an ordered array
- [development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)
- (5) Flink's table API and SQL update mode and Kafka connector case
- [salesforce] how to confirm your salesforce version?
猜你喜欢
《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
彻底弄懂浏览器强缓存和协商缓存
Redux——详解
【LeetCode】1254-统计封闭岛屿的数量
6.12 critical moment of Unified Process Platform
已知两种遍历序列构造二叉树
Pytoch saves tensor to Mat file
PTA 天梯赛习题集 L2-001 城市间紧急救援
[development environment] install the Chinese language pack for the 2013 version of visual studio community (install test agents 2013 | install visual studio 2013 simplified Chinese)
Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
随机推荐
Moveit 避障路径规划 demo
[leetcode] 1140 stone game II
《大学“电路分析基础”课程实验合集.实验六》丨典型信号的观察与测量
lseek 出错
使用 percona 工具给 MySQL 表加字段中断后该如何操作
Aiko ai Frontier promotion (7.2)
制作p12证书[通俗易懂]
2303. Calculate the total tax payable
6095. Strong password checker II
怎样从微信返回的json字符串中截取某个key的值?
蚂蚁集团大规模图计算系统TuGraph通过国家级评测
二叉树前,中,后序遍历
Review materials for the special topic of analog electronics with all essence: basic amplification circuit knowledge points
College entrance examination score line climbing
【LeetCode】977-有序数组的平方
[leetcode] 577 reverse word III in string
[leetcode] 1905 statistics sub Island
彻底弄懂浏览器强缓存和协商缓存
(5) Flink's table API and SQL update mode and Kafka connector case
【LeetCode】877-石子游戏