Reference mediasoup documentation and mediasoup3-record-demo. The rtp stream can be obtained from plaintransport, but can not save to mp4. And ffmpeg log display “Unkown error”.
What is the problem? Any help would be greatly appreciate it. thanks a lot!!
Steps & Log:
-
server side: createPlainTransport(comedia=false, rtcpMux=false, rtpPort=…, rtcpPort=rtpPort+1)
-
server side: plainTransport.consume(webrtc producerId)
-
client side: generate sdp file:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=FFmpeg
c=IN IP4 10.1.3.42
t=0 0
m=video 24213 RTP/AVP 101
a=rtpmap:101 H264/90000
a=framesize:101 640-480
a=sendonly
m=audio 24211 RTP/AVP 100
a=rtpmap:100 opus/48000/2
a=sendonly -
client side: use ffmpeg to pull rtp stream:
cmd := exec.Command(
ffmpeg_path,
“-loglevel”, “repeat+level+debug”,
“-protocol_whitelist”, “file,udp,rtp”,
“-fflags”, “+genpts”,
“-f”, “sdp”,
“-i”, “file.sdp”,
“-pix_fmt”, “yuv420p”,
“-map”, “0:v:0”, “-c:v”, “copy”,
“-map”, “0:a:0”, “-strict”, “-2”, “-c:a”, “copy”,
mp4_file) -
server side: plainTransport.connect(ip=client-side-ip,rtpPort=24213, rtcpPort=24214), plainTransport.connect(ip=client-side-ip,rtpPort=24211, rtcpPort=24212)
-
client side: use Wireshark to capture packets, rtp traffic is displayed
-
but ffmpeg does not generate mp4 files properly. the log:
[info] ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
[info] built with gcc 9.3.1 (GCC) 20200621
[info] configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib
–enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
[info] libavutil 56. 51.100 / 56. 51.100
[info] libavcodec 58. 91.100 / 58. 91.100
[info] libavformat 58. 45.100 / 58. 45.100
[info] libavdevice 58. 10.100 / 58. 10.100
[info] libavfilter 7. 85.100 / 7. 85.100
[info] libswscale 5. 7.100 / 5. 7.100
[info] libswresample 3. 7.100 / 3. 7.100
[info] libpostproc 55. 7.100 / 55. 7.100
[debug] Splitting the commandline.
[debug] Reading option ‘-loglevel’ … matched as option ‘loglevel’ (set logging level) with argument ‘repeat+level+debug’.
[debug] Reading option ‘-protocol_whitelist’ … matched as AVOption ‘protocol_whitelist’ with argument ‘file,udp,rtp’.
[debug] Reading option ‘-fflags’ … matched as AVOption ‘fflags’ with argument ‘+genpts’.
[debug] Reading option ‘-f’ … matched as option ‘f’ (force format) with argument ‘sdp’.
[debug] Reading option ‘-i’ … matched as input url with argument ‘D:\ffmpeg\file.sdp’.
[debug] Reading option ‘-pix_fmt’ … matched as option ‘pix_fmt’ (set pixel format) with argument ‘yuv420p’.
[debug] Reading option ‘-map’ … matched as option ‘map’ (set input stream mapping) with argument ‘0:v:0’.
[debug] Reading option ‘-c:v’ … matched as option ‘c’ (codec name) with argument ‘copy’.
[debug] Reading option ‘-map’ … matched as option ‘map’ (set input stream mapping) with argument ‘0:a:0’.
[debug] Reading option ‘-strict’ …Routing option strict to both codec and muxer layer
[debug] matched as AVOption ‘strict’ with argument ‘-2’.
[debug] Reading option ‘-c:a’ … matched as option ‘c’ (codec name) with argument ‘copy’.
[debug] Reading option ‘D:\ffmpeg\output.mp4’ … matched as output url.
[debug] Finished splitting the commandline.
[debug] Parsing a group of options: global .
[debug] Applying option loglevel (set logging level) with argument repeat+level+debug.
[debug] Successfully parsed a group of options.
[debug] Parsing a group of options: input url D:\ffmpeg\file.sdp.
[debug] Applying option f (force format) with argument sdp.
[debug] Successfully parsed a group of options.
[debug] Opening an input file: D:\ffmpeg\file.sdp.
[sdp @ 00000230370feb80] [debug] Opening ‘D:\ffmpeg\file.sdp’ for reading
[sdp @ 00000230370feb80] [debug] video codec set to: h264
[sdp @ 00000230370feb80] [debug] audio codec set to: opus
[sdp @ 00000230370feb80] [debug] audio samplerate set to: 48000
[sdp @ 00000230370feb80] [debug] audio channels set to: 2
[udp @ 0000023037109140] [debug] end receive buffer size reported is 393216
[udp @ 0000023037109240] [debug] end receive buffer size reported is 393216
[sdp @ 00000230370feb80] [verbose] setting jitter buffer size to 500
[udp @ 0000023037109dc0] [debug] end receive buffer size reported is 393216
[udp @ 0000023037109ec0] [debug] end receive buffer size reported is 393216
[sdp @ 00000230370feb80] [verbose] setting jitter buffer size to 500
[sdp @ 00000230370feb80] [debug] Before avformat_find_stream_info() pos: 224 bytes read:224 seeks:0 nb_streams:2
[sdp @ 00000230370feb80] [warning] Could not find codec parameters for stream 0 (Video: h264, 1 reference frame, none, 640x480, 1/180000): unspecified pixel format
Consider increasing the value for the ‘analyzeduration’ and ‘probesize’ options
[sdp @ 00000230370feb80] [debug] After avformat_find_stream_info() pos: 224 bytes read:224 seeks:0 frames:0
[info] Input #0, sdp, from ‘D:\ffmpeg\file.sdp’:
[info] Metadata:
[info] title : FFmpe
[info] Duration: N/A, bitrate: N/A
[info] Stream #0:0, 0, 1/90000: Video: h264, 1 reference frame, none, 640x480, 0/1, 90k tbr, 90k tbn, 180k tbc
[info] Stream #0:1, 0, 1/48000: Audio: opus, 48000 Hz, stereo, fltp
[debug] Successfully opened the file.
[debug] Parsing a group of options: output url D:\ffmpeg\output.mp4.
[debug] Applying option pix_fmt (set pixel format) with argument yuv420p.
[debug] Applying option map (set input stream mapping) with argument 0:v:0.
[debug] Applying option c:v (codec name) with argument copy.
[debug] Applying option map (set input stream mapping) with argument 0:a:0.
[debug] Applying option c:a (codec name) with argument copy.
[debug] Successfully parsed a group of options.
[debug] Opening an output file: D:\ffmpeg\output.mp4.
[file @ 000002303715ce00] [debug] Setting default whitelist ‘file,crypto,data’
[debug] Successfully opened the file.
[mp4 @ 0000023037584100] [warning] track 1: codec frame size is not set
[info] Output #0, mp4, to ‘D:\ffmpeg\output.mp4’:
[info] Metadata:
[info] title : FFmpeg
[info] encoder : Lavf58.45.100
[info] Stream #0:0, 0, 1/90000: Video: h264, 1 reference frame (avc1 / 0x31637661), none, 640x480 (0x0), 0/1, q=2-31, 90k tbr, 90k tbn, 90k tbc
[info] Stream #0:1, 0, 1/48000: Audio: opus (Opus / 0x7375704F), 48000 Hz, stereo, fltp
[info] Stream mapping:
[info] Stream #0:0 → #0:0 (copy)
[info] Stream #0:1 → #0:1 (copy)
[info] Press [q] to stop, [?] for help
[debug] cur_dts is invalid st:0 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[debug] cur_dts is invalid st:1 (0) [init:1 i_done:0 finish:0] (this is harmless if it occurs once at the start per stream)
[error] D:\ffmpeg\file.sdp: Unknown error
[verbose] No more output streams to write to, finishing.
[info] frame= 0 fps=0.0 q=-1.0 Lsize= 0kB time=00:00:00.00 bitrate=N/A speed= 0x
[info] video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
[verbose] Input file #0 (D:\ffmpeg\file.sdp):
[verbose] Input stream #0:0 (video): 0 packets read (0 bytes);
[verbose] Input stream #0:1 (audio): 0 packets read (0 bytes);
[verbose] Total: 0 packets (0 bytes) demuxed
[verbose] Output file #0 (D:\ffmpeg\output.mp4):
[verbose] Output stream #0:0 (video): 0 packets muxed (0 bytes);
[verbose] Output stream #0:1 (audio): 0 packets muxed (0 bytes);
[verbose] Total: 0 packets (0 bytes) muxed
[warning] Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
[debug] 0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 00000230375c5fc0] [verbose] Statistics: 2 seeks, 3 writeouts
[AVIOContext @ 0000023037107540] [verbose] Statistics: 224 bytes read, 0 seeks