ffmpeg视频推流的方法

25 篇文章 7 订阅

版权申明:未经允许请勿转载。转载前请先联系作者(hello@yeshen.org)

UDP

# push stream local
ffmpeg -re -i h264.mp4 -vcodec copy -f h264 udp://127.0.0.1:1234

# play stream
ffplay  udp://127.0.0.1:1234
ffplay -f h264 udp://127.0.0.1:1234

-i url (input)
input file url

-re (input)
Read input at native frame rate. Mainly used to simulate a grab device, or live input stream (e.g. when reading from a file). Should not be used with actual grab devices or live input streams (where it can cause packet loss). By default ffmpeg attempts to read the input(s) as fast as possible. This option will slow down the reading of the input(s) to the native frame rate of the input(s). It is useful for real-time output (e.g. live streaming).

-vcodec codec (output)
Set the video codec. This is an alias for -codec:v.

-f fmt (input/output)
Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.

RTP

# push stream local
ffmpeg -re -i h264.mp4 -vcodec copy -an -f rtp rtp://127.0.0.1:20000

-vcodec codec (output)
Set the video codec. This is an alias for -codec:v.

-an
“-an”(no audio)和“-vn”(no video)分别用来单独输出视频和音频

保上述的sdp信息进文件

$bash vim a.sdp

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 58.20.100
m=video 20000 RTP/AVP 96
b=AS:8885
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LAHtoBEA8eXwFsgAAAAwCAAAA8B4sXUA==,aM4PLIA=; profile-level-id=42C01E
# play stream
ffplay a.sdp -protocol_whitelist file,udp,rtp

RTMP:

# push stream local
ffmpeg -re -i h264.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/live/stream

# play stream
ffplay rtmp://192.168.0.157:1935/live/stream

rtmp服务器的部署方法见这篇博客:https://blog.csdn.net/yeshennet/article/details/72240465

参考资料:

  1. http://ffmpeg.org/ffmpeg.html#Main-options
  2. https://blog.csdn.net/yeshennet/article/details/72240465
  3. http://notes.maxwi.com/2017/04/05/ffmpeg-streaming/
  4. https://video.stackexchange.com/questions/16958/ffmpeg-encode-in-all-i-mode-h264-and-h265-streams
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值