Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • How to set ffmpeg reconnect or quit when rtsp stream connection breaks

    8 février, par hate29

    I use ffmpeg to save rtsp stream from my wi-fi camera. It works fine but when connection dies, I don't get any notice or it doesn't reconnect automatically. Here's my command:

    screen -S garage ffmpeg -hide_banner -y -loglevel error -rtsp_transport tcp -use_wallclock_as_timestamps 1 -i rtsp://user:password@192.168.XXX.XXX:XXX/stream1 -vcodec copy -acodec copy -f segment -reset_timestamps 1 -segment_time 14400 -segment_format mkv -segment_atclocktime 1 -strftime 1 garage%Y%m%dT%H%M%S.mkv
    

    I found this code from this site (if I remember correctly), tinkered a little (added screen -S) and got it working fine. Now I check my stream every morning by looking saved files and are they in realtime. If yes, then I know that stream is working. Needless to say that this is quite cumbersome technique.

    So what I need is that the stream reconnects if it fails to connect. This would be best. Second best option would be that it kills screen. Now it just seems do its job even if its not recording anything. I think the connection breaks from time to time because wi-fi is what it is. For that I can't do anything.

  • FFmpeg/DASH : duration or timestamp out of range for mov/mp4 format

    6 février, par mike

    I'm trying to convert a aac stream to dash. The issue is that I get a lot of errors as below(though it seems to segment it into multiple files but I get errors on the player too). The question is why do I get these errors and how can I fix it? If I simply convert "copy" it into to a single mp4 file it works without error.

        ffmpeg -i  "a.mkv" -y -map  0:1 -c:0 copy -min_seg_duration 1000000 
    -use_timeline 1 -use_template 1 -init_seg_name init.mp4s 
    -media_seg_name  "\$Number\$.mp4s" -adaptation_sets "id=1,streams=0"
    -remove_at_exit 0  -f dash -dash 1 
    "out/stream.mpd" -loglevel error 
    

    Output

    [mp4 @ 0x7fbb70819600] Application provided duration: -32 / timestamp: 40475608 is out of range for mov/mp4 format
    [mp4 @ 0x7fbb70819600] Application provided duration: -32 / timestamp: 40764376 is out of range for mov/mp4 format
    [mp4 @ 0x7fbb70819600] Application provided duration: -32 / timestamp: 40860664 is out of range for mov/mp4 format
    [mp4 @ 0x7fbb70819600] Application provided duration: -32 / timestamp: 41149432 is out of range for mov/mp4 format
    [mp4 @ 0x7fbb70819600] Application provided duration: -32 / timestamp: 41390056 is out of range for mov/mp4 format
    [mp4 @ 0x7fbb70819600] Application provided duration: -32 / timestamp: 41823208 is out of range for mov/mp4 format
    

    Copy to a single MP4 works just fine ffmpeg -i "a.mkv" -y -map 0:1 -c:0 copy -f mp4 -dash 1 "out/out.mp4" -loglevel error

    Probe

    ffprobe a.mkv
    ffprobe version 3.4 Copyright (c) 2007-2017 the FFmpeg developers
      built with Apple LLVM version 9.0.0 (clang-900.0.37)
      configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
      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, matroska,webm, from 'a.mkv':
      Metadata:
        encoder         : libebml v1.3.1 + libmatroska v1.4.2
        creation_time   : 2017-03-11T02:56:50.000000Z
      Duration: 02:12:52.39, start: 0.000000, bitrate: 740 kb/s
        Chapter #0:0: start 0.000000, end 520.270000
        Metadata:
          title           : 00:00:00.000
        Chapter #0:1: start 520.270000, end 1135.718000
        Metadata:
          title           : 00:08:40.270
        Chapter #0:2: start 1135.718000, end 1703.660000
        Metadata:
          title           : 00:18:55.718
        Chapter #0:3: start 1703.660000, end 2314.187000
        Metadata:
          title           : 00:28:23.660
        Chapter #0:4: start 2314.187000, end 2888.594000
        Metadata:
          title           : 00:38:34.187
        Chapter #0:5: start 2888.594000, end 3499.246000
        Metadata:
          title           : 00:48:08.594
        Chapter #0:6: start 3499.246000, end 4154.692000
        Metadata:
          title           : 00:58:19.246
        Chapter #0:7: start 4154.692000, end 4646.392000
        Metadata:
          title           : 01:09:14.692
        Chapter #0:8: start 4646.392000, end 5373.660000
        Metadata:
          title           : 01:17:26.392
        Chapter #0:9: start 5373.660000, end 5882.085000
        Metadata:
          title           : 01:29:33.660
        Chapter #0:10: start 5882.085000, end 6627.871000
        Metadata:
          title           : 01:38:02.085
        Chapter #0:11: start 6627.871000, end 7144.471000
        Metadata:
          title           : 01:50:27.871
        Chapter #0:12: start 7144.471000, end 7451.944000
        Metadata:
          title           : 01:59:04.471
        Chapter #0:13: start 7451.944000, end 7972.394000
        Metadata:
          title           : 02:04:11.944
        Stream #0:0(eng): Video: h264 (High), yuv420p(tv, bt709/unknown/unknown, progressive), 720x300 [SAR 1:1 DAR 12:5], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
        Metadata:
          title           : X264
          BPS             : 623765
          BPS-eng         : 623765
          DURATION        : 02:12:52.311000000
          DURATION-eng    : 02:12:52.311000000
          NUMBER_OF_FRAMES: 191144
          NUMBER_OF_FRAMES-eng: 191144
          NUMBER_OF_BYTES : 621606403
          NUMBER_OF_BYTES-eng: 621606403
          _STATISTICS_WRITING_APP: mkvmerge v8.3.0 ('Over the Horizon') 64bit
          _STATISTICS_WRITING_APP-eng: mkvmerge v8.3.0 ('Over the Horizon') 64bit
          _STATISTICS_WRITING_DATE_UTC: 2017-03-11 02:56:50
          _STATISTICS_WRITING_DATE_UTC-eng: 2017-03-11 02:56:50
          _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
          _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
        Stream #0:1(eng): Audio: aac (LC), 48000 Hz, stereo, fltp (default)
        Metadata:
          BPS             : 114797
          BPS-eng         : 114797
          DURATION        : 02:12:52.394000000
          DURATION-eng    : 02:12:52.394000000
          NUMBER_OF_FRAMES: 373706
          NUMBER_OF_FRAMES-eng: 373706
          NUMBER_OF_BYTES : 114401387
          NUMBER_OF_BYTES-eng: 114401387
          _STATISTICS_WRITING_APP: mkvmerge v8.3.0 ('Over the Horizon') 64bit
          _STATISTICS_WRITING_APP-eng: mkvmerge v8.3.0 ('Over the Horizon') 64bit
          _STATISTICS_WRITING_DATE_UTC: 2017-03-11 02:56:50
          _STATISTICS_WRITING_DATE_UTC-eng: 2017-03-11 02:56:50
          _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
          _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
    

    Shaka debug

    Assertion failed: This should be an update of the last segment in a period
    shaka.media.SegmentIndex.merge @ segment_index.js:153
    shaka.dash.SegmentTemplate.createStream @ segment_template.js:82
    shaka.dash.DashParser.parseRepresentation_ @ dash_parser.js:1080
    shaka.dash.DashParser.parseAdaptationSet_ @ dash_parser.js:978
    shaka.dash.DashParser.parsePeriod_ @ dash_parser.js:722
    shaka.dash.DashParser.parsePeriods_ @ dash_parser.js:626
    shaka.dash.DashParser.processManifest_ @ dash_parser.js:520
    (anonymous) @ dash_parser.js:431
    Promise resolved (async)
    shaka.dash.DashParser.parseManifest_ @ dash_parser.js:430
    (anonymous) @ dash_parser.js:397
    Promise resolved (async)
    shaka.dash.DashParser.requestManifest_ @ dash_parser.js:390
    shaka.dash.DashParser.onUpdate_ @ dash_parser.js:1161
    setTimeout (async)
    shaka.dash.DashParser.setUpdateTimer_ @ dash_parser.js:1209
    (anonymous) @ dash_parser.js:331
    Promise resolved (async)
    shaka.dash.DashParser.start @ dash_parser.js:329
    (anonymous) @ player.js:555
    Promise resolved (async)
    shaka.util.CancelableChain.then @ cancelable_chain.js:72
    shaka.Player.load @ player.js:499
    initPlayer @ ?x=149&y=88&q=http%3A%2F%2Flocalhost%3A8080%2Fmeta%2F%3FbucketID%3D%2FVolumes%2FTV%2FFa%26channelID%3D%2FVolumes%2FTV%26containerID%3D%2FUsers%2F%2Fbrev%%2FL1ZvbHVtZXMvVFYvRmFudGFzdGljLkJlYXN0cy5hbmQuV2hlcmUudG8uRmluZC5UaGVtLjIwMTYuQkRSaXAueDI2NC1TUEFSS1MvYS5ta3Y%2F97M4TS6IqnQ.mpd:392
    463segment_index.js:145 Refusing to rewrite original references on update!
    shaka.media.SegmentIndex.merge @ segment_index.js:145
    shaka.dash.SegmentTemplate.createStream @ segment_template.js:82
    shaka.dash.DashParser.parseRepresentation_ @ dash_parser.js:1080
    shaka.dash.DashParser.parseAdaptationSet_ @ dash_parser.js:978
    shaka.dash.DashParser.parsePeriod_ @ dash_parser.js:722
    shaka.dash.DashParser.parsePeriods_ @ dash_parser.js:626
    shaka.dash.DashParser.processManifest_ @ dash_parser.js:520
    (anonymous) @ dash_parser.js:431
    Promise resolved (async)
    shaka.dash.DashParser.parseManifest_ @ dash_parser.js:430
    (anonymous) @ dash_parser.js:397
    Promise resolved (async)
    shaka.dash.DashParser.requestManifest_ @ dash_parser.js:390
    shaka.dash.DashParser.onUpdate_ @ dash_parser.js:1161
    setTimeout (async)
    shaka.dash.DashParser.setUpdateTimer_ @ dash_parser.js:1209
    (anonymous) @ dash_parser.js:331
    Promise resolved (async)
    shaka.dash.DashParser.start @ dash_parser.js:329
    (anonymous) @ player.js:555
    Promise resolved (async)
    shaka.util.CancelableChain.then @ cancelable_chain.js:72
    shaka.Player.load @ player.js:499
    initPlayer @ ?x=149&y=88&q=http%3A%2F%2Flocalhost%3A8080%2Fmeta%2F%3FbucketID%3D%2FVolumes%2FTV%2FFa%26channelID%3D%2FVolumes%2FTV%26containerID%3D%2FUsers%2F%2Fbrev%%2FL1ZvbHVtZXMvVFYvRmFudGFzdGljLkJlYXN0cy5hbmQuV2hlcmUudG8uRmluZC5UaGVtLjIwMTYuQkRSaXAueDI2NC1TUEFSS1MvYS5ta3Y%2F97M4TS6IqnQ.mpd:392
    
  • cross compiling ffmpeg with conan fails : x86_64-w64-mingw32-ld : unrecognised emulation mode : 64

    6 février, par ovni jeroqui

    I'm trying to install ffmpeg (and some other libraries, but ffmpeg alone fails too) with conan to cross compile from linux (ubuntu) to windows.

    Conan throws an error on Running configure, inside build(). It says that x86_64-w64-mingw32-gcc is unable to create an executable file..

    On the config log I discovered it's because of a flag when running tests for x86_64-w64-mingw32-ld.

    x86_64-w64-mingw32-ld -m64 -L/home/jeroqui/.conan2/p/b/freetd8d522cfe5ed9/p/lib -L/home/jeroqui/.conan2/p/b/libsv9862cce477f3c/p/lib -L/home/jeroqui/.conan2/p/b/opensf32bb84148b27/p/lib -L/home/jeroqui/.conan2/p/b/vorbib2efb2d738443/p/lib -L/home/jeroqui/.conan2/p/b/libpn1c271e119251a/p/lib -L/home/jeroqui/.conan2/p/b/dav1d0798c06f2d7c3/p/lib -L/home/jeroqui/.conan2/p/b/libaoec0c6ff69236b/p/lib -L/home/jeroqui/.conan2/p/b/cpuin94c00ccfd6939/p/lib -L/home/jeroqui/.conan2/p/b/zlib09a824ccbeb0e/p/lib -L/home/jeroqui/.conan2/p/b/libwedcd84ab019a17/p/lib -L/home/jeroqui/.conan2/p/b/libfdbad6e447d67d4/p/lib -L/home/jeroqui/.conan2/p/b/libmpeb5a9a1a779c7/p/lib -L/home/jeroqui/.conan2/p/b/libvp0218afdff461c/p/lib -L/home/jeroqui/.conan2/p/b/libx2ec0d07d4a0565/p/lib -L/home/jeroqui/.conan2/p/b/libx23198ed0a549b9/p/lib -L/home/jeroqui/.conan2/p/b/opus8d5d63e1681f3/p/lib -L/home/jeroqui/.conan2/p/b/ogg813050272864b/p/lib -L/home/jeroqui/.conan2/p/b/openh3680a2c5cc945/p/lib -L/home/jeroqui/.conan2/p/b/openj09e5e15be595a/p/lib -L/home/jeroqui/.conan2/p/b/brotl58bc227a041f8/p/lib -L/home/jeroqui/.conan2/p/b/bzip2e67b6fd4c7720/p/lib -L/home/jeroqui/.conan2/p/b/libic229c7a1dc80e2/p/lib -L/home/jeroqui/.conan2/p/b/xz_ut8375de634122a/p/lib -m64 -o /tmp/ffconf.eAkkSIml/test.exe /tmp/ffconf.eAkkSIml/test.o
    x86_64-w64-mingw32-ld: unrecognised emulation mode: 64
    Supported emulations: i386pep i386pe
    C compiler test failed.
    

    I've tried to get conan to not add the -m64 flag, but I haven't been able to get it working. Setting env variables like LDFLAGS= doesn't seam to work either on the conan profile, on the conanfile.py or directly on my terminal. Any suggestions?

  • cv2/ffmpeg "grabFrame packet read max attempts exceeded" error after exactly reading certain number of frames

    6 février, par banjaxing

    I am using OpenCV to extract frames from videos, run a segmentation AI model, and save the frames and masks to a folder. When I run my code to extract the frame from I encounter the error "grabFrame packet read max attempts exceeded" after processing a certain number of frames. This issue occurs consistently for the same videos across multiple environments.

    Error message:

    [ WARN:0@379.898] global cap_ffmpeg_impl.hpp:1541 grabFrame packet read max attempts exceeded, if your video have multiple streams (video, audio) try to increase attempt limit by setting environment variable OPENCV_FFMPEG_READ_ATTEMPTS (current value is 10000)
    

    Minimum Reproducible Example

    import os
    import cv2
    
    videofilename = "test.mp4"
    capture = cv2.VideoCapture(videofilename)
    frameNum = 0
    
    createfolder = os.getcwd() + '/' + videofilename.split(".")[0] + '/'
    if not os.path.exists(createfolder):
        os.makedirs(createfolder)
        os.makedirs(createfolder + "/frames/")
    
    while True:
        success, frame = capture.read()
        if success is False:
            break
        frameNum += 1
        framedownloadname = videofilename.split(".")[0] + '-fr' + str(frameNum) + '.jpg'
        framedownloadloc = createfolder + '/frames/' + framedownloadname
        print(framedownloadloc)
        cv2.imwrite(framedownloadloc, frame)
        img = cv2.imread(framedownloadloc)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    
    capture.release()
    

    As suggested in error, I increased the OPENCV_FFMPEG_READ_ATTEMPTS env variable up to 10000. However, this seems to have little to no effect on the number of frames before the error appears.

  • Remove a section from the middle of a video without concat

    6 février, par user3310334

    How do I cut a section out of a video with ffmpeg?

    Imagine I have a 60 second mp4 A.

    I want to remove all the stuff from 0:15 to 0:45.

    The result should be a 30-second mp4, which is composed of the first 15 seconds of A directly followed by the last 15 seconds of A.

    How can I do this without using concat?

    I know how I could do it by creating two intermediary files and then using ffmpeg to concat them. I don't want to have to perform so much manual work for this (simple?) operation.

    I have also seen the trim filder used for removing multiple parts from a video. All the usages I've found show that it seems to be very verbose, and I haven't found an example for a case as simple as I would like (just a single section removed).

    Do I have to use trim for this operation? Or are there other less verbose solutions?

    The ideal would of course be something at least simple as -ss 0:15 -to 0:45 which removes the ends of a video (-cut 0:15-0:45 for example).