当前位置:网站首页>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
边栏推荐
- PostgresSQL 流复制 主备切换 主库无读写宕机场景
- 数组和链表的区别浅析
- Aiko ai Frontier promotion (7.2)
- 2303. 计算应缴税款总额
- [leetcode] 283 move zero
- 04. Some thoughts on enterprise application construction after entering cloud native
- Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface
- MD5 encryption
- PTA ladder game exercise set l2-001 inter city emergency rescue
- Name of institution approved in advance
猜你喜欢
已知兩種遍曆序列構造二叉樹
Two traversal sequences are known to construct binary trees
Review materials for the special topic of analog electronics with all essence: basic amplification circuit knowledge points
Pytoch saves tensor to Mat file
(Video + graphic) machine learning introduction series - Chapter 5 machine learning practice
Ant group's large-scale map computing system tugraph passed the national evaluation
Soul torture, what is AQS???
使用 percona 工具给 MySQL 表加字段中断后该如何操作
PTA ladder game exercise set l2-001 inter city emergency rescue
《大学“电路分析基础”课程实验合集.实验七》丨正弦稳态电路的研究
随机推荐
Redux——详解
[leetcode] 19 delete the penultimate node of the linked list
(万字精华知识总结)Shell脚本编程基础知识
Golang MD5 encryption and MD5 salt value encryption
Basic knowledge of cryptography
【LeetCode】577-反转字符串中的单词 III
Fiddler实现手机抓包——入门
[leetcode] 417 - Pacific Atlantic current problem
【LeetCode】695-岛屿的最大面积
Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
/bin/ld: 找不到 -lpam
Pyobject to char* (string)
【LeetCode】486-预测赢家
Add an empty column to spark dataframe - add an empty column to spark dataframe
[2. Basics of Delphi grammar] 3 Object Pascal constants and variables
/bin/ld: 找不到 -lxslt
【LeetCode】189-轮转数组
【LeetCode】1162-地图分析
/bin/ld: 找不到 -lxml2
How to intercept the value of a key from the JSON string returned by wechat?