将RTP数据包流式传输到FFMPEG

时间:2017-03-20 16:00:02

标签: ffmpeg rtp sdp vp8

我使用node.js从WebRTC服务器(我使用mediasoup)获取RTP流,然后从流中获取解密的RTP数据包原始数据。我想将此RTP数据转发到ffmpeg。我创建了描述音频和视频流的SDP文件,并通过UDP发送数据包。 SDP:

v=0
o=mediasoup 7199daf55e496b370e36cd1d25b1ef5b9dff6858 0 IN IP4 192.168.193.182
s=7199daf55e496b370e36cd1d25b1ef5b9dff6858
c=IN IP4 192.168.193.182
t=0 0
m=audio 33400 RTP/AVP 111
a=rtpmap:111 /opus/48000
a=fmtp:111 minptime=10;useinbandfec=1
a=rtcp-fb:111 transport-cc
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=mid:audio
a=recvonly
m=video 33402 RTP/AVP 100
a=rtpmap:100 /VP8/90000
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=mid:video
a=recvonly
a=rtcp-mux

命令:     ffmpeg -loglevel debug -analyzeduration 2147483647 -probesize 2147483647 -protocol_whitelist file,crypto,udp,rtp -re -vcodec vp8 -acodec opus -i test.sdp -vcodec h264 -acodec aac -y output.mp4

日志:

ffmpeg version 3.2
 Copyright (c) 2000-2016 the FFmpeg developers


  built with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-11)

  configuration: --prefix=/opt/kaltura/ffmpeg-3.2 --libdir=/opt/kaltura/ffmpeg-3.2/lib --shlibdir=/opt/kaltura/ffmpeg-3.2/lib --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC -I/opt/kaltura/include' --extra-ldflags=-L/opt/kaltura/lib --disable-devices --enable-bzlib --enable-libgsm --enable-libmp3lame --enable-libschroedinger --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-avisynth --enable-libxvid --enable-filter=movie --enable-avfilter --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libvpx --enable-libspeex --enable-libass --enable-postproc --enable-pthreads --enable-static --enable-shared --enable-gpl --disable-debug --disable-optimizations --enable-gpl --enable-pthreads --enable-swscale --enable-vdpau --enable-bzlib --disable-devices --enable-filter=movie --enable-version3 --enable-indev=lavfi --enable-x11grab

  libavutil      55. 34.100 / 55. 34.100

  libavcodec     57. 64.100 / 57. 64.100

  libavformat    57. 56.100 / 57. 56.100

  libavdevice    57.  1.100 / 57.  1.100

  libavfilter     6. 65.100 /  6. 65.100

  libswscale      4.  2.100 /  4.  2.100

  libswresample   2.  3.100 /  2.  3.100

  libpostproc    54.  1.100 / 54.  1.100

Splitting the commandline.

Reading option '-loglevel' ...
 matched as option 'loglevel' (set logging level) with argument 'debug'.

Reading option '-analyzeduration' ...
 matched as AVOption 'analyzeduration' with argument '2147483647'.

Reading option '-probesize' ...
 matched as AVOption 'probesize' with argument '2147483647'.

Reading option '-protocol_whitelist' ...
 matched as AVOption 'protocol_whitelist' with argument 'file,crypto,udp,rtp'.

Reading option '-re' ...
 matched as option 're' (read input at native frame rate) with argument '1'.

Reading option '-vcodec' ...
 matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'vp8'.

Reading option '-acodec' ...
 matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'opus'.
Reading option '-i' ... matched as input file with argument 'test.sdp'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'h264'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'aac'.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option 'output.mp4' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Applying option y (overwrite output files) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input file test.sdp.
Applying option re (read input at native frame rate) with argument 1.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument vp8.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument opus.
Successfully parsed a group of options.
Opening an input file: test.sdp.
[sdp @ 0xb1ef00] Format sdp probed with size=2048 and score=50
[sdp @ 0xb1ef00] audio codec set to: (null)
[sdp @ 0xb1ef00] audio samplerate set to: 44100
[sdp @ 0xb1ef00] audio channels set to: 1
[sdp @ 0xb1ef00] video codec set to: (null)
[udp @ 0xb21940] end receive buffer size reported is 131072
[udp @ 0xb21660] end receive buffer size reported is 131072
[sdp @ 0xb1ef00] setting jitter buffer size to 500
[udp @ 0xb21da0] end receive buffer size reported is 131072
[udp @ 0xb22060] end receive buffer size reported is 131072
[sdp @ 0xb1ef00] setting jitter buffer size to 500

[sdp @ 0xb1ef00] Before avformat_find_stream_info() pos: 889 bytes read:889 seeks:0 nb_streams:2

[vp8 @ 0xb27600] Header size larger than data provided

    Last message repeated 2 times
[sdp @ 0xb1ef00] Non-increasing DTS in stream 1: packet 2 with DTS 0, packet 3 with DTS 0
[vp8 @ 0xb27600] Header size larger than data provided

... repeats many times until I kill the socket ...

    Last message repeated 1 times
[sdp @ 0xb1ef00] Non-increasing DTS in stream 1: packet 273 with DTS 553050, packet 274 with DTS 553050
[vp8 @ 0xb27600] Header size larger than data provided

received id=7199daf55e496b370e36cd1d25b1ef5b9dff6858 type=bye
PeerConnection close. id=7199daf55e496b370e36cd1d25b1ef5b9dff6858
-- PeerConnection.closed,  err: undefined
-- peers in the room = 0
[sdp @ 0xb1ef00] decoding for stream 1 failed
[sdp @ 0xb1ef00] Could not find codec parameters for stream 1 (Video: vp8, 1 reference frame, yuv420p): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
[sdp @ 0xb1ef00] After avformat_find_stream_info() pos: 889 bytes read:889 seeks:0 frames:584
Input #0, sdp, from 'test.sdp':
  Metadata:
    title           : 7199daf55e496b370e36cd1d25b1ef5b9dff6858
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0, 309, 1/90000: Audio: opus, 48000 Hz, mono, fltp
    Stream #0:1, 275, 1/90000: Video: vp8, 1 reference frame, yuv420p, 90k tbr, 90k tbn, 90k tbc
Successfully opened the file.
Parsing a group of options: output file output.mp4.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument h264.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument aac.
Successfully parsed a group of options.
Opening an output file: output.mp4.
Matched encoder 'libx264' for codec 'h264'.

[file @ 0xbc56e0]
Setting default whitelist 'file,crypto'

Successfully opened the file.

detected 1 logical cores

[graph 0 input from stream 0:1 @ 0xb1eca0]
Setting 'video_size' to value '0x0'

[buffer @ 0xbc54e0]
Unable to parse option value "0x0" as image size

[graph 0 input from stream 0:1 @ 0xb1eca0]
Setting 'pix_fmt' to value '0'

[graph 0 input from stream 0:1 @ 0xb1eca0]
Setting 'time_base' to value '1/90000'

[graph 0 input from stream 0:1 @ 0xb1eca0] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:1 @ 0xb1eca0] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:1 @ 0xb1eca0] Setting 'frame_rate' to value '90000/1'
[buffer @ 0xbc54e0] Unable to parse option value "0x0" as image size
[buffer @ 0xbc54e0] Error setting option video_size to value 0x0.
[graph 0 input from stream 0:1 @ 0xb1eca0] Error applying options to the filter.
Error opening filters!
[AVIOContext @ 0xbc57c0] Statistics: 0 seeks, 0 writeouts

[AVIOContext @ 0xb1f8c0]
Statistics: 889 bytes read, 0 seeks

正如您所看到的,在日志开始时,SDP在不识别编解码器的情况下进行了解析:

Opening an input file: test.sdp.
[sdp @ 0xb1ef00] Format sdp probed with size=2048 and score=50
[sdp @ 0xb1ef00] audio codec set to: (null)
[sdp @ 0xb1ef00] audio samplerate set to: 44100
[sdp @ 0xb1ef00] audio channels set to: 1
[sdp @ 0xb1ef00] video codec set to: (null)

然后它试图从套接字读取数据包。 只有当我关闭套接字时,ffmpeg才会继续解析SDP,这次找到正确的编解码器:

Opening an input file: test.sdp.
[sdp @ 0xb1ef00] Format sdp probed with size=2048 and score=50
[sdp @ 0xb1ef00] audio codec set to: (null)
[sdp @ 0xb1ef00] audio samplerate set to: 44100
[sdp @ 0xb1ef00] audio channels set to: 1
[sdp @ 0xb1ef00] video codec set to: (null)

我怀疑“非增加DTS”和“大于提供的数据的标头大小”错误是由于使用错误的编解码器而错误地解析数据包引起的。

我检查了SDP订单,它看起来与我的其他示例相同。

有人可以提出解释吗?

顺便说一句,音频只能正常工作,但我想这是因为OPUS的简单性。

感谢。

1 个答案:

答案 0 :(得分:1)

答案在这里:Stream RTP to FFMPEG using SDP

编解码器名称错误,我在编码名称之前删除了额外的斜杠,它解决了问题。