<p>I have solved the problem. Removing &quot;-re&quot; option in ffmpeg pipeline sets delay to 0.
My final pipeline:</p>
<pre><code>ffmpeg -rtsp_transport udp -i rtsp://192.168.3.107:554/av2_0 -codec copy -f rtsp rtsp://localhost:9000/camera1
</code></pre>

CC BY-SA 4.0
2023-10-26T08:58:48.850Z
2023-10-26T08:58:48.850Z
Anton
<p>I have ip and usb cameras. I try restream rtsp from camera using ffmpeg and mediamtx (rtsp simple server). For usb camera it works fine without any delay:<br />
mediamtx output:</p>
<pre><code>anton@anton:~$ RTSP_RTSPADDRESS=:9000 ./mediamtx
INF MediaMTX v1.2.0
INF configuration loaded from /home/anton/mediamtx.yml
INF [RTSP] listener opened on :9000 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
INF [RTMP] listener opened on :1935
INF [HLS] listener opened on :8888
INF [WebRTC] listener opened on :8889 (HTTP)
INF [SRT] listener opened on :8890 (UDP)
INF [RTSP] [conn 127.0.0.1:36742] opened
INF [RTSP] [session b6d6f987] created by 127.0.0.1:36742
INF [RTSP] [session b6d6f987] is publishing to path 'camera1', 1 track (MPEG-4 Video)
INF [RTSP] [conn 192.168.3.77:50422] opened
INF [RTSP] [session cec77920] created by 192.168.3.77:50422
INF [RTSP] [session cec77920] is reading from path 'camera1', with UDP, 1 track (MPEG-4 Video)
</code></pre>
<p>ffmpeg pipeline output:</p>
<pre><code>anton@anton:~$ ffmpeg -re -rtsp_transport tcp -i rtsp://192.168.3.100:9005/camera5 -codec copy -f rtsp rtsp://localhost:9000/camera1
ffmpeg version 3.2.18-0+deb9u1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version=0+deb9u1 --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, rtsp, from 'rtsp://192.168.3.100:9005/camera5':
  Metadata:
    title           : Session streamed with GStreamer
    comment         : rtsp-server
  Duration: N/A, start: 0.000367, bitrate: N/A
    Stream #0:0: Video: mpeg4 (Simple Profile), yuv420p, 648x486 [SAR 1:1 DAR 4:3], 30 tbr, 90k tbn, 30 tbc
Output #0, rtsp, to 'rtsp://localhost:9000/camera1':
  Metadata:
    title           : Session streamed with GStreamer
    comment         : rtsp-server
    encoder         : Lavf57.56.101
    Stream #0:0: Video: mpeg4 (Simple Profile), yuv420p, 648x486 [SAR 1:1 DAR 4:3], q=2-31, 30 tbr, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -&gt; #0:0 (copy)
Press [q] to stop, [?] for help
frame= 2609 fps= 30 q=-1.0 Lsize=N/A time=00:01:26.93 bitrate=N/A speed=0.999x    
</code></pre>
<p>for ip camera the same commands work too, but restreaming comes out with 0.5 - 1 second delay:<br />
mediamtx output:</p>
<pre><code>anton@anton:~$ RTSP_RTSPADDRESS=:9000 ./mediamtx
INF MediaMTX v1.2.0
INF configuration loaded from /home/anton/mediamtx.yml
INF [RTSP] listener opened on :9000 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
INF [RTMP] listener opened on :1935
INF [HLS] listener opened on :8888
INF [WebRTC] listener opened on :8889 (HTTP)
INF [SRT] listener opened on :8890 (UDP)
INF [RTSP] [conn 127.0.0.1:36736] opened
INF [RTSP] [session 967ae51e] created by 127.0.0.1:36736
INF [RTSP] [session 967ae51e] is publishing to path 'camera1', 1 track (H264)
INF [RTSP] [conn 192.168.3.77:50408] opened
INF [RTSP] [session 5b412272] created by 192.168.3.77:50408
INF [RTSP] [session 5b412272] is reading from path 'camera1', with UDP, 1 track (H264)
</code></pre>
<p>ffmpeg pipeline output:</p>
<pre><code>anton@anton:~$ ffmpeg -re -rtsp_transport tcp -i rtsp://192.168.3.107:554/av2_0 -codec copy -f rtsp rtsp://localhost:9000/camera1
ffmpeg version 3.2.18-0+deb9u1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version=0+deb9u1 --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, rtsp, from 'rtsp://192.168.3.107:554/av2_0':
  Metadata:
    title           : av2_0
  Duration: N/A, start: 0.040000, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 720x576, 25 fps, 25 tbr, 90k tbn, 180k tbc
Output #0, rtsp, to 'rtsp://localhost:9000/camera1':
  Metadata:
    title           : av2_0
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 720x576, q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -&gt; #0:0 (copy)
Press [q] to stop, [?] for help
[rtsp @ 0x5e0a3706a960] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[rtsp @ 0x5e0a3706a960] Non-monotonous DTS in output stream 0:0; previous: 0, current: 0; changing to 1. This may result in incorrect timestamps in the output file.
frame= 2568 fps= 25 q=-1.0 Lsize=N/A time=00:01:42.64 bitrate=N/A speed=   1x    
</code></pre>
<p>Can I remove this delay for ip camera? Is it necessary to change some params for ip camera or add extra arguments for ffmpeg command? I tried to minimize delay, but it didn't have any effect.</p>

<ffmpeg><streaming><h.264>
restreaming rtsp using ffmpeg delay problem
Anton
# restreaming rtsp using ffmpeg delay problem

(Asked by: username_0 on 2023-10-23)

I have ip and usb cameras. I try restream rtsp from camera using ffmpeg and mediamtx (rtsp simple server). For usb camera it works fine without any delay:
mediamtx output:
anton@anton:~$ RTSP_RTSPADDRESS=:9000 ./mediamtx
INF MediaMTX v1.2.0
INF configuration loaded from /home/anton/mediamtx.yml
INF [RTSP] listener opened on :9000 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
INF [RTMP] listener opened on :1935
INF [HLS] listener opened on :8888
INF [WebRTC] listener opened on :8889 (HTTP)
INF [SRT] listener opened on :8890 (UDP)
INF [RTSP] [conn 127.0.0.1:36742] opened
INF [RTSP] [session b6d6f987] created by 127.0.0.1:36742
INF [RTSP] [session b6d6f987] is publishing to path 'camera1', 1 track (MPEG-4 Video)
INF [RTSP] [conn 192.168.3.77:50422] opened
INF [RTSP] [session cec77920] created by 192.168.3.77:50422
INF [RTSP] [session cec77920] is reading from path 'camera1', with UDP, 1 track (MPEG-4 Video)

ffmpeg pipeline output:
anton@anton:~$ ffmpeg -re -rtsp_transport tcp -i rtsp://192.168.3.100:9005/camera5 -codec copy -f rtsp rtsp://localhost:9000/camera1
ffmpeg version 3.2.18-0+deb9u1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version=0+deb9u1 --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, rtsp, from 'rtsp://192.168.3.100:9005/camera5':
  Metadata:
    title           : Session streamed with GStreamer
    comment         : rtsp-server
  Duration: N/A, start: 0.000367, bitrate: N/A
    Stream #0:0: Video: mpeg4 (Simple Profile), yuv420p, 648x486 [SAR 1:1 DAR 4:3], 30 tbr, 90k tbn, 30 tbc
Output #0, rtsp, to 'rtsp://localhost:9000/camera1':
  Metadata:
    title           : Session streamed with GStreamer
    comment         : rtsp-server
    encoder         : Lavf57.56.101
    Stream #0:0: Video: mpeg4 (Simple Profile), yuv420p, 648x486 [SAR 1:1 DAR 4:3], q=2-31, 30 tbr, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame= 2609 fps= 30 q=-1.0 Lsize=N/A time=00:01:26.93 bitrate=N/A speed=0.999x    

for ip camera the same commands work too, but restreaming comes out with 0.5 - 1 second delay:
mediamtx output:
anton@anton:~$ RTSP_RTSPADDRESS=:9000 ./mediamtx
INF MediaMTX v1.2.0
INF configuration loaded from /home/anton/mediamtx.yml
INF [RTSP] listener opened on :9000 (TCP), :8000 (UDP/RTP), :8001 (UDP/RTCP)
INF [RTMP] listener opened on :1935
INF [HLS] listener opened on :8888
INF [WebRTC] listener opened on :8889 (HTTP)
INF [SRT] listener opened on :8890 (UDP)
INF [RTSP] [conn 127.0.0.1:36736] opened
INF [RTSP] [session 967ae51e] created by 127.0.0.1:36736
INF [RTSP] [session 967ae51e] is publishing to path 'camera1', 1 track (H264)
INF [RTSP] [conn 192.168.3.77:50408] opened
INF [RTSP] [session 5b412272] created by 192.168.3.77:50408
INF [RTSP] [session 5b412272] is reading from path 'camera1', with UDP, 1 track (H264)

ffmpeg pipeline output:
anton@anton:~$ ffmpeg -re -rtsp_transport tcp -i rtsp://192.168.3.107:554/av2_0 -codec copy -f rtsp rtsp://localhost:9000/camera1
ffmpeg version 3.2.18-0+deb9u1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --prefix=/usr --extra-version=0+deb9u1 --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-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --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-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 34.101 / 55. 34.101
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.101 / 57. 56.101
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, rtsp, from 'rtsp://192.168.3.107:554/av2_0':
  Metadata:
    title           : av2_0
  Duration: N/A, start: 0.040000, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 720x576, 25 fps, 25 tbr, 90k tbn, 180k tbc
Output #0, rtsp, to 'rtsp://localhost:9000/camera1':
  Metadata:
    title           : av2_0
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 720x576, q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[rtsp @ 0x5e0a3706a960] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[rtsp @ 0x5e0a3706a960] Non-monotonous DTS in output stream 0:0; previous: 0, current: 0; changing to 1. This may result in incorrect timestamps in the output file.
frame= 2568 fps= 25 q=-1.0 Lsize=N/A time=00:01:42.64 bitrate=N/A speed=   1x    

Can I remove this delay for ip camera? Is it necessary to change some params for ip camera or add extra arguments for ffmpeg command? I tried to minimize delay, but it didn't have any effect.

**Tags:** ffmpeg, streaming, h.264


---

## 1 answers

### Answer by username_0 on 2023-10-26. Score: 0 | Accepted answer

I have solved the problem. Removing "-re" option in ffmpeg pipeline sets delay to 0.
My final pipeline:
ffmpeg -rtsp_transport udp -i rtsp://192.168.3.107:554/av2_0 -codec copy -f rtsp rtsp://localhost:9000/camera1


---

