Потоковая передача RTP-пакетов в FFMPEG

Я получаю поток RTP с сервера WebRTC (я использовал mediasoup) с помощью node.js, и я получаю необработанные данные расшифрованных пакетов RTP из потока. Я хочу переслать эти данные RTP в ffmpeg. Я создаю файл SDP, который описывает аудио- и видеопотоки, и отправляю пакеты через UDP. СДП:

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.

Спасибо.


person Johnathan Kanarek    schedule 20.03.2017    source источник


Ответы (1)


Ответ здесь: Потоковая передача RTP в FFMPEG с использованием SDP

Имя кодека неправильное, я удалил лишнюю косую черту перед закодированным именем, и это решило проблему.

person Johnathan Kanarek    schedule 21.03.2017