当前位置:网站首页>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
边栏推荐
- Leetcode skimming - remove duplicate letters 316 medium
- Some problems about pytorch extension
- 【LeetCode】417-太平洋大西洋水流问题
- SQL修改语句
- 数字藏品系统开发(程序开发)丨数字藏品3D建模经济模式系统开发源码
- 已知兩種遍曆序列構造二叉樹
- The outline dimension function application of small motherboard
- Loss function and positive and negative sample allocation: Yolo series
- (Wanzi essence knowledge summary) basic knowledge of shell script programming
- 【LeetCode】1020-飞地的数量
猜你喜欢

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

2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)

Loss function and positive and negative sample allocation: Yolo series

Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)

Bing. Site Internet

Leetcode skimming - remove duplicate letters 316 medium

彻底弄懂浏览器强缓存和协商缓存

03. Preliminary use of golang

(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice

Leetcode skimming -- sum of two integers 371 medium
随机推荐
【LeetCode】189-轮转数组
《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
[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)
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
Leetcode skimming -- count the number of numbers with different numbers 357 medium
The task cannot be submitted after the installation of flick is completed
6.12 critical moment of Unified Process Platform
6096. Success logarithm of spells and potions
【LeetCode】344-反转字符串
/bin/ld: 找不到 -lssl
[leetcode] 200 number of islands
6090. Minimax games
Loss function and positive and negative sample allocation: Yolo series
C # get PLC information (kepserver) II
[leetcode] 167 - sum of two numbers II - enter an ordered array
Pyinstaller打包exe附带图片的方法
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
/bin/ld: 找不到 -lcrypto
Redux——详解
《大学“电路分析基础”课程实验合集.实验六》丨典型信号的观察与测量