ffmpeg仅将传入的RTP音频流保存到文件中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ffmpeg仅将传入的RTP音频流保存到文件中相关的知识,希望对你有一定的参考价值。
我已安装kurento媒体服务器,该服务器流RTP音频(仅音频)。现在,我正在尝试测试收到的RTP流。为此,我将传入的RTP流保存到将它们转换为mp3的文件中。我正在使用以下命令。
sudo ffmpeg -loglevel debug -protocol_whitelist file,crypto,udp,rtp -reorder_queue_size 100 -acodec opus -i mySdpOffer.sdp -acodec mp3 -y -f segment -segment_atclocktime 1 -segment_time 900 -reset_timestamps 1 -strftime 1 out-%Y%m%dT%H%M.mp3
SDP报价:
v=0
t=0 0
m=audio 8978 RTP/AVP 98
c=IN IP4 127.0.0.1
a=recvonly
a=rtpmap:98 opus/48000/2
a=fmtp:98 stereo=0; sprop-stereo=0; useinbandfec=1
我正在获取输出的mp3文件,但是当我在VLC中播放该文件时,没有音频,并且在流式传输大约1分钟时,mp3输出文件显示的音频时间为7分钟。
ffmpeg没有错误。我在这里想念什么吗?
UPDATE
添加ffmpeg日志,
初始日志,开始捕获/解码/写入文件之前>
Splitting the commandline. Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'. Reading option '-protocol_whitelist' ... matched as AVOption 'protocol_whitelist' with argument 'file,crypto,udp,rtp'. Reading option '-reorder_queue_size' ... matched as AVOption 'reorder_queue_size' with argument '100'. Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'opus'. Reading option '-i' ... matched as input url with argument '/home/ubuntu/Documents/inputAudio.sdp'. Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'mp3'. Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'. Reading option '-f' ... matched as option 'f' (force format) with argument 'segment'. Reading option '-segment_atclocktime' ... matched as AVOption 'segment_atclocktime' with argument '1'. Reading option '-segment_time' ... matched as AVOption 'segment_time' with argument '900'. Reading option '-reset_timestamps' ... matched as AVOption 'reset_timestamps' with argument '1'. Reading option '-strftime' ... matched as AVOption 'strftime' with argument '1'. Reading option 'out-%Y%m%dT%H%M.mp3' ... matched as output url. 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 url /home/ubuntu/Documents/inputAudio.sdp. Applying option acodec (force audio codec ('copy' to copy stream)) with argument opus. Successfully parsed a group of options. Opening an input file: /home/ubuntu/Documents/inputAudio.sdp. [NULL @ 0x55e09081d440] Opening '/home/ubuntu/Documents/inputAudio.sdp' for reading [sdp @ 0x55e09081d440] Format sdp probed with size=2048 and score=50 [sdp @ 0x55e09081d440] audio codec set to: opus [sdp @ 0x55e09081d440] audio samplerate set to: 48000 [sdp @ 0x55e09081d440] audio channels set to: 2 [udp @ 0x55e090825200] end receive buffer size reported is 131072 [udp @ 0x55e090824ec0] end receive buffer size reported is 131072 [sdp @ 0x55e09081d440] setting jitter buffer size to 100 [sdp @ 0x55e09081d440] Before avformat_find_stream_info() pos: 141 bytes read:141 seeks:0 nb_streams:1 [sdp @ 0x55e09081d440] All info found [sdp @ 0x55e09081d440] After avformat_find_stream_info() pos: 141 bytes read:141 seeks:0 frames:1 Input #0, sdp, from '/home/ubuntu/Documents/inputAudio.sdp': Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0, 1, 1/48000: Audio: opus, 48000 Hz, stereo, fltp Successfully opened the file. Parsing a group of options: output url out-%Y%m%dT%H%M.mp3. Applying option acodec (force audio codec ('copy' to copy stream)) with argument mp3. Applying option f (force format) with argument segment. Successfully parsed a group of options. Opening an output file: out-%Y%m%dT%H%M.mp3. Matched encoder 'libmp3lame' for codec 'mp3'. Successfully opened the file. Stream mapping: Stream #0:0 -> #0:0 (opus (native) -> mp3 (libmp3lame)) Press [q] to stop, [?] for help cur_dts is invalid (this is harmless if it occurs once at the start per stream) detected 2 logical cores [graph_0_in_0_0 @ 0x55e0908a2240] Setting 'time_base' to value '1/48000' [graph_0_in_0_0 @ 0x55e0908a2240] Setting 'sample_rate' to value '48000' [graph_0_in_0_0 @ 0x55e0908a2240] Setting 'sample_fmt' to value 'fltp' [graph_0_in_0_0 @ 0x55e0908a2240] Setting 'channel_layout' to value '0x3' [graph_0_in_0_0 @ 0x55e0908a2240] tb:1/48000 samplefmt:fltp samplerate:48000 chlayout:0x3 [format_out_0_0 @ 0x55e0908875c0] Setting 'sample_fmts' to value 's32p|fltp|s16p' [format_out_0_0 @ 0x55e0908875c0] Setting 'sample_rates' to value '44100|48000|32000|22050|24000|16000|11025|12000|8000' [format_out_0_0 @ 0x55e0908875c0] Setting 'channel_layouts' to value '0x4|0x3' [AVFilterGraph @ 0x55e0908a1400] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed [segment @ 0x55e09081f7c0] Selected stream id:0 type:audio [segment @ 0x55e09081f7c0] Opening 'out-20191105T1707.mp3' for writing [file @ 0x55e0908a2bc0] Setting default whitelist 'file,crypto' Output #0, segment, to 'out-%Y%m%dT%H%M.mp3': Metadata: encoder : Lavf58.20.100 Stream #0:0, 0, 1/48000: Audio: mp3 (libmp3lame), 48000 Hz, stereo, fltp, delay 1105 Metadata: encoder : Lavc58.35.100 libmp3lame cur_dts is invalid (this is harmless if it occurs once at the start per stream) Last message repeated 3 times [segment @ 0x55e09081f7c0] segment:'out-20191105T1707.mp3' starts with packet stream:0 pts:0 pts_time:0 frame:0 [segment @ 0x55e09081f7c0] stream:0 start_pts_time:0 pts:0 pts_time:0 dts:0 dts_time:0 -> pts:0 pts_time:0 dts:0 dts_time:0 [segment @ 0x55e09081f7c0] stream:0 start_pts_time:0 pts:1152 pts_time:0.024 dts:1152 dts_time:0.024 -> pts:1152 pts_time:0.024 dts:1152 dts_time:0.024 [segment @ 0x55e09081f7c0] stream:0 start_pts_time:0 pts:179904 pts_time:3.748 dts:179904 dts_time:3.748 -> pts:179904 pts_time:3.748 dts:179904 dts_time:3.748 [segment @ 0x55e09081f7c0] stream:0 start_pts_time:0 pts:181056 pts_time:3.772 dts:181056 dts_time:3.772 -> pts:181056 pts_time:3.772 dts:181056 dts_time:3.772
最后几行。
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137124480 pts_time:2856.76 dts:137124480 dts_time:2856.76 -> pts:137124480 pts_time:2856.76 dts:137124480 dts_time:2856.76
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137130912 pts_time:2856.89 dts:137130912 dts_time:2856.89 -> pts:137130912 pts_time:2856.89 dts:137130912 dts_time:2856.89
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137132064 pts_time:2856.92 dts:137132064 dts_time:2856.92 -> pts:137132064 pts_time:2856.92 dts:137132064 dts_time:2856.92
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137133216 pts_time:2856.94 dts:137133216 dts_time:2856.94 -> pts:137133216 pts_time:2856.94 dts:137133216 dts_time:2856.94
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137134368 pts_time:2856.97 dts:137134368 dts_time:2856.97 -> pts:137134368 pts_time:2856.97 dts:137134368 dts_time:2856.97
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137135520 pts_time:2856.99 dts:137135520 dts_time:2856.99 -> pts:137135520 pts_time:2856.99 dts:137135520 dts_time:2856.99
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137136672 pts_time:2857.01 dts:137136672 dts_time:2857.01 -> pts:137136672 pts_time:2857.01 dts:137136672 dts_time:2857.01
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137137824 pts_time:2857.04 dts:137137824 dts_time:2857.04 -> pts:137137824 pts_time:2857.04 dts:137137824 dts_time:2857.04
[libmp3lame @ 0x5613ffd81900] Trying to remove 47 more samples than there are in the queue
[segment @ 0x5613ffd7f7c0] stream:0 start_pts_time:0 pts:137138976 pts_time:2857.06 dts:137138976 dts_time:2857.06 -> pts:137138976 pts_time:2857.06 dts:137138976 dts_time:2857.06
[segment @ 0x5613ffd7f7c0] segment:'out-20191105T1651.mp3' count:0 ended
[AVIOContext @ 0x5613ffe02a00] Statistics: 1 seeks, 24 writeouts
size=N/A time=00:47:37.06 bitrate=N/A speed= 236x
video:0kB audio:5803kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Input file #0 (/home/ubuntu/Documents/bz-squawk-sdpoffer/inputAudio.sdp):
Input stream #0:0 (audio): 18568 packets read (2970880 bytes); 18568 frames decoded (17825280 samples);
Total: 18568 packets (2970880 bytes) demuxed
Output file #0 (out-%Y%m%dT%H%M.mp3):
Output stream #0:0 (audio): 15473 frames encoded (17824896 samples); 15474 packets muxed (5942016 bytes);
Total: 15474 packets (5942016 bytes) muxed
18568 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x5613ffd86000] Statistics: 141 bytes read, 0 seeks
Exiting normally, received signal 2.
我已安装kurento媒体服务器,该服务器流RTP音频(仅音频)。现在,我正在尝试测试收到的RTP流。为此,我将传入的RTP流保存到将它们转换为mp3的文件中。 ...
答案
检查kurento媒体服务器正在使用Wireshark发送单声道或立体声音频数据。
以上是关于ffmpeg仅将传入的RTP音频流保存到文件中的主要内容,如果未能解决你的问题,请参考以下文章
使用 VLC 从其他计算机上的 ffmpeg 接收 rtp (opus) 流