ffmpeg视频推流的方法

版权申明:未经允许请勿转载。转载前请先联系作者([email protected]

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

你可能感兴趣的:(linux,Android,ffmpeg)