[FFmpeg-user] Using ffmpeg receive udp stream without hangs
zy
393969258 at qq.com
Fri Sep 28 04:25:40 EEST 2018
I try to use ffmpeg to receive udp streams and write to my local files. But the udp links may be interrupted. When ffmpeg can't access the udp link, the writing process hangs.
Is there any way to keep ffmpeg to write blank to the file instead of just hanging? Or use multicast when the main udp disconnected, it switch to the vice udp. When main udp connect again it can switch back to the main udp.
Following up are my own commands, the sender sent the file to udp, and receiver receive the udp port. If the sender was interrupted, the receiver stop writing to the files.
sender:
ffmpeg -re -i test.ts -c copy -f mpegts -map 0 udp://0.0.0.0:6666
re
receiver:
ffmpeg -i udp://0.0.0.0:6666 -vn -acodec pcm_s16le -ac 8000 -f segment -segment_time 3 -reset_timestamps 1 -strftime 1 -segment_format wav ~/Desktop/temp/%s.wa
server:
ffserver
here are my output of these commands:
ffserver
ffserver version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
/etc/ffserver.conf:164: Setting default value for video bit rate tolerance = 21333. Use NoDefaults to disable it.
/etc/ffserver.conf:164: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
/etc/ffserver.conf:164: Setting default value for video max rate = 128000. Use NoDefaults to disable it.
/etc/ffserver.conf:219: Setting default value for audio sample rate = 22050. Use NoDefaults to disable it.
/etc/ffserver.conf:219: Setting default value for audio channel count = 1. Use NoDefaults to disable it.
/etc/ffserver.conf:219: Setting default value for video bit rate tolerance = 64000. Use NoDefaults to disable it.
/etc/ffserver.conf:219: Setting default value for video rate control equation = tex^qComp. Use NoDefaults to disable it.
/etc/ffserver.conf:219: Setting default value for video max rate = 512000. Use NoDefaults to disable it.
Fri Sep 28 09:06:36 2018 Codecs do not match for stream 0
Fri Sep 28 09:06:36 2018 [ffm @ 0x55f0d97b36e0]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Fri Sep 28 09:06:36 2018 [ffm @ 0x55f0d97b36e0]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Fri Sep 28 09:06:36 2018 [ffm @ 0x55f0d97b36e0]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Fri Sep 28 09:06:36 2018 [ffm @ 0x55f0d97b36e0]Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Fri Sep 28 09:06:36 2018 FFserver started.
ffmpeg -re -i test.ts -c copy -f mpegts -map 0 udp://0.0.0.0:6666
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mpegts, from 'test.ts':
Duration: 00:02:26.29, start: 1.400000, bitrate: 214 kb/s
Program 1
Metadata:
service_name : Õ¾³¤ËزÄ(sc.chinaz.com)
service_provider: FFmpeg
Stream #0:0[0x100]: Audio: mp3 ([3][0][0][0] / 0x0003), 44100 Hz, stereo, s16p, 192 kb/s
Output #0, mpegts, to 'udp://0.0.0.0:6666':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Audio: mp3 ([3][0][0][0] / 0x0003), 44100 Hz, stereo, s16p, 192 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 392kB time=00:00:15.07 bitrate= 213.1kbits/s speed= 1x
video:0kB audio:354kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 10.817121%
Exiting normally, received signal 2.
ffmpeg -i udp://0.0.0.0:6666 -vn -acodec pcm_s16le -ac 8000 -f segment -segment_time 3 -reset_timestamps 1 -strftime 1 -segment_format wav ~/Desktop/temp/%s.wav
ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mpegts, from 'udp://0.0.0.0:6666':
Duration: N/A, start: 3.071844, bitrate: 192 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Audio: mp3 ([3][0][0][0] / 0x0003), 44100 Hz, stereo, s16p, 192 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538096980.wav' for writing
Output #0, segment, to '/home/wzq/Desktop/temp/%s.wav':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
Metadata:
encoder : Lavc57.107.100 pcm_s16le
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538096980.wav' for writing
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538096981.wav' for writing
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538096984.wav' for writing
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538096987.wav' for writing
size=N/A time=00:00:12.90 bitrate=N/A speed=1.65x
--------------------------
Here I use Control-C to stop the sender's terminal. The udp port connection is broken and the receiver is hanging.
When I interrupt the sender terminal, the receiver terminal is hanging. If I start the sender terminal again the receiver terminal go continue writing.
--------------------------
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538096987.wav' for writing
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538097528.wav' for writing
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538097531.wav' for writing
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538097534.wav' for writing
[segment @ 0x5633475e75a0] Opening '/home/wzq/Desktop/temp/1538097537.wav' for writing
--------------------------
As shown in the record, the gap between normal neighbor files is 3s, however the gap between 1538096987.wav and 1539097528.wav is about 600 seconds. I want to know is there any method to keep the receiver writing files even if it doesn't receive anyting?
Thanks,
More information about the ffmpeg-user
mailing list