[FFmpeg-user] How do I set a timeout for an RTSP source?

NZPWebcams nzpwebcams at si.edu
Tue Jun 17 16:08:47 CEST 2014


Hello,
I am streaming an IP camera with RTSP source that is always live. The command line below typically runs stable for many weeks.  If the IP RTSP source drops due to network issues, or if I force a camera reboot for testing, the FFmpeg process ends.  Other software monitors the FFmpeg process and restarts it.  At this point if the IP RTSP source does not respond FFmpeg hangs permanently at "Opening an input file:".  I can see 3 TCP RTSP packets sent to the camera, an initial packet then a retransmit after 3 seconds, and a final retransmit 6 seconds later.

How can I set a timeout on either connection attempts or after x seconds if encoding cannot start?  Can FFmpeg be configured to continue to try to reconnect for a longer period?

This is the failing command if the IP source does not respond when FFmpeg is starting.

I:\>ffmpeg -loglevel debug -i "rtsp://user:password@127.0.0.1/axis-media/media.amp?videocodec=h264&fps=15&resolution=800x600&compression=30&audio=0"  -c:v libx264 -pix_fmt yuv420p -profile:v baseline -r 15 -s 480x360 -g 30 -crf 20 -maxrate 100k -minrate 75k -bufsize 95k -b:v 95k -f rtsp -muxdelay 0.1 "rtsp://user:password@127.0.0.2/live/test"
ffmpeg version N-63968-g73d820e Copyright (c) 2000-2014 the FFmpeg developers
  built on Jun 15 2014 00:52:21 with gcc 4.8.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libblu
ray --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libope
njpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrw
benc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-decklink --enable-zlib
  libavutil      52. 89.100 / 52. 89.100
  libavcodec     55. 66.101 / 55. 66.101
  libavformat    55. 43.100 / 55. 43.100
  libavdevice    55. 13.101 / 55. 13.101
  libavfilter     4.  8.100 /  4.  8.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Splitting the commandline.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument 'debug'.
Reading option '-i' ... matched as input file with argument 'rtsp://user:password@127.0.0.1/axis-media/media.amp?videocodec=h264&fps=15&resolution=800x600&compression=30&audio=0'.
Reading option '-c:v' ... matched as option 'c' (codec name) with argument 'libx264'.
Reading option '-pix_fmt' ... matched as option 'pix_fmt' (set pixel format) with argument 'yuv420p'.
Reading option '-profile:v' ... matched as option 'profile' (set profile) with argument 'baseline'.
Reading option '-r' ... matched as option 'r' (set frame rate (Hz value, fraction or abbreviation)) with argument '15'.
Reading option '-s' ... matched as option 's' (set frame size (WxH or abbreviation)) with argument '480x360'.
Reading option '-g' ... matched as AVOption 'g' with argument '30'.
Reading option '-crf' ... matched as AVOption 'crf' with argument '20'.
Reading option '-maxrate' ... matched as AVOption 'maxrate' with argument '100k'.
Reading option '-minrate' ... matched as AVOption 'minrate' with argument '75k'.
Reading option '-bufsize' ... matched as AVOption 'bufsize' with argument '95k'.
Reading option '-b:v' ... matched as option 'b' (video bitrate (please use -b:v)) with argument '95k'.
Reading option '-f' ... matched as option 'f' (force format) with argument 'rtsp'.
Reading option '-muxdelay' ... matched as option 'muxdelay' (set the maximum demux-decode delay) with argument '0.1'.
Reading option 'rtsp://user:password@127.0.0.2/live/test' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option loglevel (set logging level) with argument debug.
Successfully parsed a group of options.
Parsing a group of options: input file rtsp://user:password@127.0.0.1/axis-media/media.amp?videocodec=h264&fps=15&resolution=800x600&compression=30&audio=0.
Successfully parsed a group of options.
Opening an input file: rtsp://user:password@127.0.0.1/axis-media/media.amp?videocodec=h264&fps=15&resolution=800x600&compression=30&audio=0.

I have to press Ctrl+C twice here to return to the prompt.

rtsp://user:password@127.0.0.1/axis-media/media.amp?videocodec=h264&fps=15&resolution=800x600&compression=30&audio=0: Input/output error
Received signal 2: terminating.

I:\>

Thanks,
Mike Thorpe






More information about the ffmpeg-user mailing list