<p>I have a webcam running on my Wifi, and am saving its stream to my harddisc drive. This is called by a python script which continuously restarts the recording (I want to have 4h long video files, not infinitely long video).</p>

<p>My calling code:</p>

<pre><code>"D:/Program Files/ffmpeg-4.2.2-win64-static/bin/ffmpeg.exe"  -y -err_detect ignore_err -re -rtsp_transport tcp -i rtsp://admin:123456@192.168.178.54:554/live/ch0 -t 14400 -vcodec copy -acodec copy .\200430\Falken-200430-2340.mkv
</code></pre>

<p>A sample output I get before the process stops:</p>

<pre><code>ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  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-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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, rtsp, from 'rtsp://admin:123456@192.168.178.54:554/live/ch0':
  Metadata:
    title           : hysxrtpsion
  Duration: N/A, start: 0.533000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1920x1080, 20 fps, 24.83 tbr, 90k tbn, 40 tbc
Output #0, matroska, to '.\200430\Falken-200430-2339.mkv':
  Metadata:
    title           : hysxrtpsion
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuvj420p(pc, bt709, progressive), 1920x1080, q=2-31, 20 fps, 24.83 tbr, 1k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -&gt; #0:0 (copy)
Press [q] to stop, [?] for help
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -272; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -232; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -152; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -111; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -71; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -31; changing to 0. This may result in incorrect timestamps in the output file.
frame=  725 fps= 20 q=-1.0 Lsize=    6387kB time=00:00:36.11 bitrate=1448.8kbits/s speed=0.991x
video:6381kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.100017%
</code></pre>

<p>If anyone wants to see it, this is my python wrapper which repeatedly simply calls ffmpeg to grab the camera stream:</p>

<pre><code>import subprocess
from datetime import datetime
import os

def ensure_dir(directory):
    if not os.path.exists(directory):
        os.makedirs(directory)

while True:
    dateString = datetime.today().strftime('%y%m%d-%H%M')
    folderString = datetime.today().strftime('%y%m%d')
    folderString = '.\\' + folderString
    ensure_dir(folderString)
    videoFilename = folderString + "\\Falken-" + dateString + ".mkv"

    commandLine = "\"D:/Program Files/ffmpeg-4.2.2-win64-static/bin/ffmpeg.exe\"  -y -err_detect ignore_err -re -rtsp_transport tcp -i rtsp://admin:123456@192.168.178.54:554/live/ch0 -t 14400 -vcodec copy -acodec copy " + videoFilename
    print("\nCalling new ffmpeg process\n", commandLine)
    process = subprocess.Popen(commandLine, shell=True, stdout=subprocess.PIPE)
    process.wait(14404)
    process.kill()
</code></pre>

<p>The video grabbing should run for 4h (14400 seconds), and instead it usually halts after 5-15 minutes (at random points). If there are lost packets or similar, why doesn't ffmpeg just go on (ignore_err)?</p>

CC BY-SA 4.0
2020-05-01T07:01:31.450Z
Don't add `-re` for live inputs.
Gyan
CC BY-SA 4.0
2020-05-01T16:52:59.367Z
Okay, tested, I still get a lot of halts on the recording. I added verbose log output, and get `No more output streams to write to, finishing.` Searching for that though did not really help unfortunately, found no solid answer on this.
SinisterMJ
<ffmpeg>
ffmpeg cancels extremely often with no apparent reason
SinisterMJ
# ffmpeg cancels extremely often with no apparent reason

(Asked by: username_0 on 2020-04-30)

I have a webcam running on my Wifi, and am saving its stream to my harddisc drive. This is called by a python script which continuously restarts the recording (I want to have 4h long video files, not infinitely long video).
My calling code:
"D:/Program Files/ffmpeg-4.2.2-win64-static/bin/ffmpeg.exe"  -y -err_detect ignore_err -re -rtsp_transport tcp -i rtsp://admin:123456@192.168.178.54:554/live/ch0 -t 14400 -vcodec copy -acodec copy .\200430\Falken-200430-2340.mkv

A sample output I get before the process stops:
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  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-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-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, rtsp, from 'rtsp://admin:123456@192.168.178.54:554/live/ch0':
  Metadata:
    title           : hysxrtpsion
  Duration: N/A, start: 0.533000, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuvj420p(pc, bt709, progressive), 1920x1080, 20 fps, 24.83 tbr, 90k tbn, 40 tbc
Output #0, matroska, to '.\200430\Falken-200430-2339.mkv':
  Metadata:
    title           : hysxrtpsion
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuvj420p(pc, bt709, progressive), 1920x1080, q=2-31, 20 fps, 24.83 tbr, 1k tbn, 90k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -272; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -232; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -152; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -111; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -71; changing to 0. This may result in incorrect timestamps in the output file.
[matroska @ 000002a85f765040] Non-monotonous DTS in output stream 0:0; previous: 0, current: -31; changing to 0. This may result in incorrect timestamps in the output file.
frame=  725 fps= 20 q=-1.0 Lsize=    6387kB time=00:00:36.11 bitrate=1448.8kbits/s speed=0.991x
video:6381kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.100017%

If anyone wants to see it, this is my python wrapper which repeatedly simply calls ffmpeg to grab the camera stream:
import subprocess
from datetime import datetime
import os

def ensure_dir(directory):
    if not os.path.exists(directory):
        os.makedirs(directory)

while True:
    dateString = datetime.today().strftime('%y%m%d-%H%M')
    folderString = datetime.today().strftime('%y%m%d')
    folderString = '.\\' + folderString
    ensure_dir(folderString)
    videoFilename = folderString + "\\Falken-" + dateString + ".mkv"

    commandLine = "\"D:/Program Files/ffmpeg-4.2.2-win64-static/bin/ffmpeg.exe\"  -y -err_detect ignore_err -re -rtsp_transport tcp -i rtsp://admin:123456@192.168.178.54:554/live/ch0 -t 14400 -vcodec copy -acodec copy " + videoFilename
    print("\nCalling new ffmpeg process\n", commandLine)
    process = subprocess.Popen(commandLine, shell=True, stdout=subprocess.PIPE)
    process.wait(14404)
    process.kill()

The video grabbing should run for 4h (14400 seconds), and instead it usually halts after 5-15 minutes (at random points). If there are lost packets or similar, why doesn't ffmpeg just go on (ignore_err)?

**Tags:** ffmpeg

> **Comments:**
> **username_1**: Don't add `-re` for live inputs.  
> **username_0**: Okay, tested, I still get a lot of halts on the recording. I added verbose log output, and get `No more output streams to write to, finishing.` Searching for that though did not really help unfortunately, found no solid answer on this.  

---

## 0 answers

