Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • _stricoll is unsolved while linking the libmingwex.a with vs2010

    14 mai 2018, par damantou

    I am tending to build some app which staticly links the ffmpeg libs on windows 8. I have successfully build the static lib of ffmpeg in mingw/msys env on windows 8. Then I use cmake to generate the vs2010 project to start work with my app.

    While I am trying to build the first dead simple main program, I got quite some link errors.

    extern "C" {
    
    // to work around error:
    // 'UINT64_C': identifier not found
    #ifndef __STDC_CONSTANT_MACROS
    #define __STDC_CONSTANT_MACROS
    #endif
    
    
    #include avcodec.h>
    #include avformat.h>
    #include swscale.h>
    
    }
    
    
    int main(int argc, char *argv[])
    {
        av_register_all();
        return 0;
    }
    

    After struggling with a bunch of unresolved symbols, I come up with the following libraries to link with in order:

    c:/MinGW/mingw32/lib/libiconv.a
    libavcodec.a
    libavdevice.a
    libavfilter.a
    libavformat.a
    libavutil.a
    libswresample.a
    libswscale.a
    c:/MinGW/lib/gcc/mingw32/4.8.1/libgcc.a
    c:/MinGW/mingw32/lib/libws2_32.a
    c:/MinGW/mingw32/lib/libmingw32.a
    c:/MinGW/mingw32/lib/libmingwex.a
    

    Finally there is one unresolved symbol issue not able to fix:

    libmingwex.a(glob.o) : error LNK2019: unresolved external symbol 
                           _stricoll referenced in function _glob_match
    

    I tried to add some a fake function, but still not help :(

    int  __cdecl _stricoll(_In_z_  const char * _Str1, _In_z_  const char * _Str2)
    {
        return 0;
    };
    

    I googled it the whole morning, but nobody ever mentioned this problem. I guess there should be simple reason and solution for this, maybe because of my ignorance on simple knowledge.

  • Parse mkv file to get duration

    14 mai 2018, par Parth Shah

    I have one mkv file that doesn't have valid duration. I want to change this duration parameter manually. I gone through this matroska specification defined at http://www.matroska.org/technical/specs/index.html

    Looking at specification for matroska this contains only identification magic numbers, but this doesn't specify length for data.

    So, My question is how to parse this matroska header so that i get duration field and change this field?

    Any Help or advice? Thank you in advance.

  • How to configure AVStream to write 29.97FPS files using FFmpeg

    14 mai 2018, par vtruant

    I'm trying to write mkv file using ffmpeg to encode in FFV1 and FLAC in NTSC format, but the frame rate shown in VLC and media info are not correct.

    Here is how I create and configure the output format context:

    AVOutputFormat  *outputFormat = av_guess_format("matroska", NULL, NULL);
    
    //Allocate an AVFormatContext for an output format.
    int err = avformat_alloc_output_context2(&_formatContext, outputFormat, NULL, filename);
    
    //Specify the codec of the outputFormat
    _formatContext->oformat->video_codec = _videoCodecContext->codec_id;
    
    //Create AVStream 
    AVStream *videoStream = avformat_new_stream(_formatContext, NULL);  
    
    //FrameDuration.value : 1001, FrameDuration.timescale : 30000
    videoStream->time_base = (AVRational){ (int)_frameDuration.value, (int)_frameDuration.timescale };  //1001 30000
    
    //Copy video stream parameters to the muxer
    err = avcodec_parameters_from_context(videoStream->codecpar, _videoCodecContext);
    
    //Open file for writing
    err = avio_open(&_formatContext->pb, filename, AVIO_FLAG_WRITE);            
    
    if (err >= 0) {
        //Write header
        err = avformat_write_header(_formatContext, &options);
    }
    

    Before writing the packet, I use this to convert PTS to the stream time_base

    // Rescale output packet timestamp values from codec to stream timebase
    av_packet_rescale_ts(inAVPacket, *inTimeStamp, [outputStream stream]->time_base);
    

    The thing is that the avformat_write_header method is changing the stream time_base from 30000/1001 to 1/1000, so PTS loose precision. In VLC inspector, the frame rate shown is 1000 fps and in MediaInfo 30.033 fps.

    The file is playing correctly and the video/audio sync is OK.

    Is there something to do to specify the file frame rate somewhere else ? Or a work around to avoid changing the time_base when calling avformat_write_header ?

  • FFMPEG : RTSP re-stream dies randomly

    14 mai 2018, par stevendesu

    I have a security camera streaming RTSP, and I wish to re-stream this to an RTMP ingest server. For now I'm using my laptop as an ffmpeg proxy, but eventually I'll use a raspberry pi or something similar (cheap/small)

    Here's the command I'm using (pretty simple):

    ffmpeg -i rtsp://@10.0.0.16:554/1/h264major -c:v libx264 -c:a none -f flv rtmp://output/camera_stream
    

    This works but after a minute or two the stream dies. Here's the output:

    ffmpeg version N-90057-g7c82e0f Copyright (c) 2000-2018 the FFmpeg developers
      built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.6) 20160609
      configuration: --prefix=/home/sbarnett/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/sbarnett/ffmpeg_build/include --extra-ldflags=-L/home/sbarnett/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/sbarnett/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libspeex --enable-nonfree
      libavutil      56.  7.101 / 56.  7.101
      libavcodec     58. 11.101 / 58. 11.101
      libavformat    58.  9.100 / 58.  9.100
      libavdevice    58.  1.100 / 58.  1.100
      libavfilter     7. 12.100 /  7. 12.100
      libswscale      5.  0.101 /  5.  0.101
      libswresample   3.  0.101 /  3.  0.101
      libpostproc    55.  0.100 / 55.  0.100
    Input #0, rtsp, from 'rtsp://@10.0.0.16:554/1/h264major':
      Metadata:
        title           : h264major
        comment         : h264major
      Duration: N/A, start: 0.360000, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 720x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
    Press [q] to stop, [?] for help
    [libx264 @ 0x38843c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
    [libx264 @ 0x38843c0] profile High, level 3.0
    [libx264 @ 0x38843c0] 264 - core 155 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, flv, to 'rtmp://output/camera_stream':
      Metadata:
        title           : h264major
        comment         : h264major
        encoder         : Lavf58.9.100
        Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuvj420p(pc), 720x480, q=-1--1, 25 fps, 1k tbn, 25 tbc
        Metadata:
          encoder         : Lavc58.11.101 libx264
        Side data:
          cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Past duration 0.999992 too large
        Last message repeated 29 times
    [rtsp @ 0x3847600] max delay reached. need to consume packet
    [rtsp @ 0x3847600] RTP: missed 48 packets
    Past duration 0.999992 too large
        Last message repeated 4 times
    frame=   44 fps=0.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A dup=0 drop=5 speed=   0x    
    frame=   57 fps= 54 q=28.0 size=      43kB time=00:00:00.16 bitrate=2186.4kbits/s dup=0 drop=5 speed=0.153x    
    ... (lots of similar messages) ...   
    frame= 1163 fps= 26 q=28.0 size=    1341kB time=00:00:44.84 bitrate= 245.0kbits/s dup=0 drop=5 speed=0.99x    
    frame= 1177 fps= 26 q=28.0 size=    1353kB time=00:00:45.40 bitrate= 244.2kbits/s dup=0 drop=5 speed=0.99x    
    [rtsp @ 0x3847600] max delay reached. need to consume packet
    [rtsp @ 0x3847600] RTP: missed 2 packets
    frame= 1190 fps= 26 q=28.0 size=    1370kB time=00:00:45.92 bitrate= 244.4kbits/s dup=0 drop=5 speed=0.99x    
    [h264 @ 0x38c08c0] Increasing reorder buffer to 1
    frame= 1201 fps= 26 q=28.0 size=    1381kB time=00:00:46.36 bitrate= 244.0kbits/s dup=0 drop=5 speed=0.989x    
    frame= 1214 fps= 26 q=28.0 size=    1393kB time=00:00:46.88 bitrate= 243.4kbits/s dup=0 drop=5 speed=0.989x    
    ... (lots of similar messages) ...    
    frame= 1761 fps= 25 q=28.0 size=    2030kB time=00:01:08.80 bitrate= 241.7kbits/s dup=0 drop=5 speed=0.993x    
    frame= 1774 fps= 25 q=28.0 size=    2041kB time=00:01:09.32 bitrate= 241.2kbits/s dup=0 drop=5 speed=0.993x    
    [flv @ 0x3884900] Failed to update header with correct duration.
    [flv @ 0x3884900] Failed to update header with correct filesize.
    frame= 1782 fps= 25 q=-1.0 Lsize=    2127kB time=00:01:11.64 bitrate= 243.2kbits/s dup=0 drop=5 speed=1.02x    
    video:2092kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.679417%
    [libx264 @ 0x38843c0] frame I:8     Avg QP:16.89  size: 42446
    [libx264 @ 0x38843c0] frame P:1672  Avg QP:19.54  size:  1065
    [libx264 @ 0x38843c0] frame B:102   Avg QP:23.00  size:   205
    [libx264 @ 0x38843c0] consecutive B-frames: 92.4%  0.0%  0.0%  7.6%
    [libx264 @ 0x38843c0] mb I  I16..4: 12.9% 36.2% 50.9%
    [libx264 @ 0x38843c0] mb P  I16..4:  0.2%  0.2%  0.0%  P16..4: 16.7%  0.7%  1.0%  0.0%  0.0%    skip:81.1%
    [libx264 @ 0x38843c0] mb B  I16..4:  0.1%  0.1%  0.0%  B16..8: 11.7%  0.1%  0.0%  direct: 1.5%  skip:86.5%  L0:62.2% L1:35.3% BI: 2.5%
    [libx264 @ 0x38843c0] 8x8 transform intra:40.8% inter:47.4%
    [libx264 @ 0x38843c0] coded y,uvDC,uvAC intra: 46.5% 53.0% 17.2% inter: 3.9% 8.7% 0.0%
    [libx264 @ 0x38843c0] i16 v,h,dc,p: 21% 56%  8% 15%
    [libx264 @ 0x38843c0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 33% 31%  1%  2%  3%  2%  2%  3%
    [libx264 @ 0x38843c0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 39%  9%  3%  3%  4%  5%  3%  8%
    [libx264 @ 0x38843c0] i8c dc,h,v,p: 43% 33% 21%  3%
    [libx264 @ 0x38843c0] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 0x38843c0] ref P L0: 88.0%  1.4%  6.6%  4.0%
    [libx264 @ 0x38843c0] ref B L0: 99.4%  0.5%  0.1%
    [libx264 @ 0x38843c0] ref B L1: 99.4%  0.6%
    [libx264 @ 0x38843c0] kb/s:238.73
    

    The camera is pretty cheap (from China) so it's likely I'm getting bad data from it or it's cutting out for a few seconds at a time. Ideally I would need ffmpeg to handle this well (ignore bad data, wait as long as necessary for good data to resume encoding)

    Using ffplay to check out the RTSP stream, I get output like the following:

    $> ffplay -i rtsp://@10.0.0.16:554/1/h264major
    ffplay version N-90057-g7c82e0f Copyright (c) 2003-2018 the FFmpeg developers
      built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.6) 20160609
      configuration: --prefix=/home/sbarnett/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/sbarnett/ffmpeg_build/include --extra-ldflags=-L/home/sbarnett/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/sbarnett/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libspeex --enable-nonfree
      libavutil      56.  7.101 / 56.  7.101
      libavcodec     58. 11.101 / 58. 11.101
      libavformat    58.  9.100 / 58.  9.100
      libavdevice    58.  1.100 / 58.  1.100
      libavfilter     7. 12.100 /  7. 12.100
      libswscale      5.  0.101 /  5.  0.101
      libswresample   3.  0.101 /  3.  0.101
      libpostproc    55.  0.100 / 55.  0.100
    Input #0, rtsp, from 'rtsp://@10.0.0.16:554/1/h264major':0B f=0/0
      Metadata:
        title           : h264major
        comment         : h264major
      Duration: N/A, start: 0.320000, bitrate: N/A
        Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 720x480, 25 fps, 25 tbr, 90k tbn, 50 tbc
    [swscaler @ 0x7f6bbc093180] deprecated pixel format used, make sure you did set range correctly
    [rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
    [rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
    [h264 @ 0x7f6bc0041080] error while decoding MB 44 28, bytestream -37
    [h264 @ 0x7f6bc0041080] concealing 95 DC, 95 AC, 95 MV errors in I frame
    [rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
    [rtsp @ 0x7f6bc0000940] RTP: missed 1 packets
    [h264 @ 0x7f6bc0041080] error while decoding MB 43 29, bytestream -49
    [h264 @ 0x7f6bc0041080] concealing 51 DC, 51 AC, 51 MV errors in I frame
    [rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
    [rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
    [h264 @ 0x7f6bc0041080] Increasing reorder buffer to 1
    [rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
    [rtsp @ 0x7f6bc0000940] RTP: missed 3 packets
    [h264 @ 0x7f6bc02c3600] error while decoding MB 27 29, bytestream -24
    [h264 @ 0x7f6bc02c3600] concealing 67 DC, 67 AC, 67 MV errors in I frame
    [rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
    [rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
    [rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
    [rtsp @ 0x7f6bc0000940] RTP: missed 42 packets
    [rtsp @ 0x7f6bc0000940] max delay reached. need to consume packet
    [rtsp @ 0x7f6bc0000940] RTP: missed 2 packets
    

    Then eventually the video just freezes. The first time it froze after around 5 minutes, but I wasn't able to say definitively if it froze the instant 44 packets were dropped or if it froze randomly later. So the second time I stared intently.... for 21 minutes. Then I got bored of it not freezing, turned to pet my cat, and when I looked back 15 seconds later it was frozen. I think it only breaks when no one is watching it.

    What I can say definitively is:

    • While running normally, M-V hovers around 0 (anywhere between -0.01 and +0.01)
    • Once frozen, M-V begins to count down into negative numbers without stopping - although at a rate slower than -1 per second
    • While running normally, aq is 0KB and vq is a positive number (I think it was 30KB or so?)
    • Once frozen, vq is also 0KB

    It's a really cheap camera with a crummy power supply that goes out if you breathe on it, so it's likely the camera is going temporarily offline during this time -- but I'd like ffmpeg to wait out a timeout and resume streaming when it sees the camera again.

  • Process won't stop

    14 mai 2018, par Srdjan M.

    The process goes in infinite loop or it's waiting something and I don't know what. It won't pass WaitForExit methode.

    FFmpeg:

    -ss 0 -i output.mp4 -t 10 -an -y test.mp4
    

    C# Code:

    using (Process process = new Process())
    {
         process.StartInfo.UseShellExecute = false;
         process.StartInfo.RedirectStandardOutput = true;
         process.StartInfo.RedirectStandardError = true;
         process.StartInfo.FileName = FileName; // ffmpeg.exe
         process.StartInfo.Arguments = Arguments; //-ss 0 -i output.mp4 -t 10 -an -y test.mp4
         process.Start();
         process.WaitForExit(); // stops here and waits
    
         return process.StandardOutput.ReadToEnd();
    }
    

    Edit:

    Adding -loglevel quiet to my ffmpeg query made my problem disappear. Why?