Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • merge (video and sound) with (background music)

    27 novembre 2016, par Nir di

    i have video file vid.mpg that contain video and audio(speaking) and audio file aud.wav that contain background music.

    now, i want to merge them together.

    here is the command that i use:

    ffmpeg -i vid.mpg -i aud.mp3 -c:v copy  -filter_complex "[0:a]aformat = fltp:44100:stereo,apad[0a];[1]aformat=fltp:44100:stereo,volume=0.1[1a];[0a][1a]amerge[a]" -map 0:v -map "[a]" -ac 2 -t 0 out.mpg
    

    and this is the error that i get as response:

    [Parsed_amerge_4 @ 00000000003a36e0] No channel layout for input 1
    [Parsed_amerge_4 @ 00000000003a36e0] Input channel layouts overlap: output layou
    t will be determined by the number of distinct input channels
    [mpeg @ 000000000289a4e0] VBV buffer size not set, using default size of 130KB
    If you want the mpeg file to be compliant to some specification
    Like DVD, VCD or others, make sure you set the correct buffer size
    

    in addition i add the full log:

    C:\bina\ffmpeg\bin>ffmpeg -i vid.mpg -i
    aud.mp3 -c:v copy  -filter_complex "[1:a]aform
    at = fltp:44100:stereo,apad[0a];[1]aformat=fltp:44100:stereo,volume=0.1[1a];[0a]
    [1a]amerge[a]" -map 0:v -map "[a]" -ac 2 -t 0 out.mpg
    ffmpeg version N-78949-g6f5048f Copyright (c) 2000-2016 the FFmpeg developers
      built with gcc 5.3.0 (GCC)
      configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
    isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
    le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
    enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
    ibilbc --enable-libmodplug --enable-libmfx --enable-libmp3lame --enable-libopenc
    ore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --ena
    ble-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable
    -libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --ena
    ble-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx
    264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable
    -lzma --enable-decklink --enable-zlib
      libavutil      55. 19.100 / 55. 19.100
      libavcodec     57. 27.101 / 57. 27.101
      libavformat    57. 28.100 / 57. 28.100
      libavdevice    57.  0.101 / 57.  0.101
      libavfilter     6. 39.100 /  6. 39.100
      libswscale      4.  0.100 /  4.  0.100
      libswresample   2.  0.101 /  2.  0.101
      libpostproc    54.  0.100 / 54.  0.100
    Input #0, mpeg, from 'vid.mpg':
      Duration: 00:00:33.62, start: 0.529978, bitrate: 22407 kb/s
        Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 1920x1080 [SAR 1:
    1 DAR 16:9], max. 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
        Stream #0:1[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16p, 192 kb/s
    [mp3 @ 00000000003e3c20] Skipping 0 bytes of junk at 253.
    Input #1, mp3, from 'aud.mp3':
      Metadata:
        encoder         : Lavf57.28.100
      Duration: 00:01:03.03, start: 0.025057, bitrate: 128 kb/s
        Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 128 kb/s
        Metadata:
          encoder         : Lavc57.27
    File 'out.mpg' already exists. Overwrite
     ? [y/N] y
    [Parsed_amerge_4 @ 00000000003a36e0] No channel layout for input 1
    [Parsed_amerge_4 @ 00000000003a36e0] Input channel layouts overlap: output layou
    t will be determined by the number of distinct input channels
    [mpeg @ 000000000289a4e0] VBV buffer size not set, using default size of 130KB
    If you want the mpeg file to be compliant to some specification
    Like DVD, VCD or others, make sure you set the correct buffer size
    Output #0, mpeg, to 'out.mpg':
      Metadata:
        encoder         : Lavf57.28.100
        Stream #0:0: Video: mpeg2video, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-3
    1, max. 104857 kb/s, 25 fps, 25 tbr, 90k tbn, 25 tbc
        Stream #0:1: Audio: mp2, 44100 Hz, stereo, s16, 384 kb/s (default)
        Metadata:
          encoder         : Lavc57.27.101 mp2
    Stream mapping:
      Stream #1:0 (mp3) -> aformat
      Stream #1:0 (mp3) -> aformat
      Stream #0:0 -> #0:0 (copy)
      amerge -> Stream #0:1 (mp2)
    Press [q] to stop, [?] for help
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=234676 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=234676 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=236705 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=236705 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=238746 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=238746 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=240787 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=240787 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=242828 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=242828 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=244869 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=244869 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=246910 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=246910 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=248951 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=248951 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=250992 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=250992 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=253033 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=253033 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=255074 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=255074 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=257115 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=257115 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=259156 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=259156 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=261197 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=261197 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=263238 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=263238 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=265279 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=265279 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=267320 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=267320 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=269361 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=269361 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=271402 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=271402 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=273443 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=273443 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=275484 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=275484 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=277525 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=277525 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=279566 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=279566 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=281607 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=281607 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=283648 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=283648 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=285689 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=285689 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=287730 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=287730 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=289771 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=289771 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=291812 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=291812 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=293853 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=293853 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=295894 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=295894 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=297935 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=297935 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=299976 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=299976 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=302017 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=302017 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=304058 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=304058 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=306099 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=306099 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=308140 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=308140 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=310181 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=310181 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=312222 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=312222 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=314263 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=314263 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=316304 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=316304 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=318345 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=318345 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=320386 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=320386 size=322616
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=322427 size=322616
    [mpeg @ 000000000289a4e0] packet too large, ignoring buffer limits to mux it
    [mpeg @ 000000000289a4e0] buffer underflow st=0 bufi=322427 size=322616
    frame=    1 fps=0.0 q=-1.0 Lsize=     318kB time=00:00:00.00 bitrate=N/A speed=
      0x
    video:315kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing o
    verhead: 0.934858%
    
    C:\bina\ffmpeg\bin>ffmpeg -i vid.mpg -i
    aud.mp3 -c:v copy  -filter_complex "[0:a]aform
    at = fltp:44100:stereo,apad[0a];[1]aformat=fltp:44100:stereo,volume=0.1[1a];[0a]
    [1a]amerge[a]" -map 0:v -map "[a]" -ac 2 -t 0 out.mpg
    

    what am i doing wrong? and how can i solve it?

    please help.

  • ffmpeg custom audio mixing filter

    27 novembre 2016, par esposito

    I need to mix 2 files: A and B and the result is part of file A and part of File B.

    In detail I like that the output is the sum of the upper part of the file A and the lower part of file B.

    I need something like this:

    ffmpeg -i A.flac -i B.flac -af "copy all from 0 to -25 dB from 'A', copy all from -25dB to -infinite from file 'B' and put these 2 parts on the output" output.flac
    

    -25dB is variable that I can adjust, I like to keep the volume of file 'A'.

    In short I like to replace the soft background of file 'A' with file 'B'.

    there is a way to do this ?

    thank you !!!!

  • ffmpeg sidechaingate more example

    27 novembre 2016, par esposito

    I' like to see how work the new filter 'sidechaingate' but I haven't found any example on ffmpeg documentation.

    I don't sure if this can useful in my case.

    I need to do this:

    if the signal 'A' have a very low volume compared to signal 'B' apply the gate on signal A (or simply switch to signal 'B' that is the best solution in my case)

    To be honest the ideal is:

    if the volume of signal 'A' is less than -45 dB (for example) switch to signal 'B'

    Is possible do it in some way ?

    thank you !!

  • ffmpeg create RTP stream

    27 novembre 2016, par DankMemes

    I'm trying to encode and stream using ffmpeg (libavcodec/libavformat - MSVC x64 with Zeranoe builds)

    Here is my code, largely adapted from the encoding example, error handling removed

    #include "stdafx.h"
    extern "C" {
    #include avformat.h>
    #include avcodec.h>
    
    #include opt.h>
    #include channel_layout.h>
    #include common.h>
    #include imgutils.h>
    #include mathematics.h>
    #include samplefmt.h>
    }
    #pragma comment(lib, "avformat.lib")
    #pragma comment(lib, "avutil.lib")
    #pragma comment(lib, "avcodec.lib")
    
    int main() {
        avcodec_register_all();
        av_register_all();
        avformat_network_init();
    
        AVCodecID codec_id = AV_CODEC_ID_H264;
        AVCodec *codec;
        AVCodecContext *c = NULL;
        int i, ret, x, y, got_output;
        AVFrame *frame;
        AVPacket pkt;
    
        codec = avcodec_find_encoder(codec_id);
        c = avcodec_alloc_context3(codec);
    
        c->bit_rate = 400000;
        c->width = 352;
        c->height = 288;
        c->time_base.num = 1;
        c->time_base.den = 25;
        c->gop_size = 25;
        c->max_b_frames = 1;
        c->pix_fmt = AV_PIX_FMT_YUV420P;
        c->codec_type = AVMEDIA_TYPE_VIDEO;
        c->flags = CODEC_FLAG_GLOBAL_HEADER;
    
        if (codec_id == AV_CODEC_ID_H264) {
            ret = av_opt_set(c->priv_data, "preset", "ultrafast", 0);
            ret = av_opt_set(c->priv_data, "tune", "zerolatency", 0);
        }
    
        avcodec_open2(c, codec, NULL)
    
        frame = av_frame_alloc();
        frame->format = c->pix_fmt;
        frame->width = c->width;
        frame->height = c->height;
        ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height,
            c->pix_fmt, 32);
    
        AVFormatContext* avfctx;
        AVOutputFormat* fmt = av_guess_format("rtp", NULL, NULL);
    
        ret = avformat_alloc_output_context2(&avfctx, fmt, fmt->name,
            "rtp://127.0.0.1:49990");
    
        printf("Writing to %s\n", avfctx->filename);
    
        avio_open(&avfctx->pb, avfctx->filename, AVIO_FLAG_WRITE)
    
        struct AVStream* stream = avformat_new_stream(avfctx, codec);
        stream->codecpar->bit_rate = 400000;
        stream->codecpar->width = 352;
        stream->codecpar->height = 288;
        stream->codecpar->codec_id = AV_CODEC_ID_H264;
        stream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
        stream->time_base.num = 1;
        stream->time_base.den = 25;
    
        avformat_write_header(avfctx, NULL);
        char buf[200000];
        AVFormatContext *ac[] = { avfctx };
        av_sdp_create(ac, 1, buf, 20000);
        printf("sdp:\n%s\n", buf);
        FILE* fsdp;
        fopen_s(&fsdp, "test.sdp", "w");
        fprintf(fsdp, "%s", buf);
        fclose(fsdp);
        system("PAUSE");
        system("start "" \"C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe\" test.sdp");
    
        int j = 0;
        for (i = 0; i < 10000; i++) {
            av_init_packet(&pkt);
            pkt.data = NULL;    // packet data will be allocated by the encoder
            pkt.size = 0;
            fflush(stdout);
            /* prepare a dummy image */
            /* Y */
            for (y = 0; y < c->height; y++) {
                for (x = 0; x < c->width; x++) {
                    frame->data[0][y * frame->linesize[0] + x] = x + y + i * 3;
                }
            }
            /* Cb and Cr */
            for (y = 0; y < c->height / 2; y++) {
                for (x = 0; x < c->width / 2; x++) {
                    frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2;
                    frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5;
                }
            }
            frame->pts = i;
            /* encode the image */
            ret = avcodec_send_frame(c, frame);
            ret = avcodec_receive_packet(c, &pkt);
    
            if (ret == AVERROR_EOF) {
                got_output = false;
                printf("Stream EOF\n");
            } else if(ret == AVERROR(EAGAIN)) {
                got_output = false;
                printf("Stream EAGAIN\n");
            } else {
                got_output = true;
            }
    
            if (got_output) {
                printf("Write frame %3d (size=%5d)\n", j++, pkt.size);
                av_interleaved_write_frame(avfctx, &pkt);
                av_packet_unref(&pkt);
            }
    
            Sleep(40);
        }
    
        // end
        ret = avcodec_send_frame(c, NULL);
    
        /* get the delayed frames */
        for (; ; i++) {
            fflush(stdout);
            ret = avcodec_receive_packet(c, &pkt);
            if (ret == AVERROR_EOF) {
                printf("Stream EOF\n");
                break;
            } else if (ret == AVERROR(EAGAIN)) {
                printf("Stream EAGAIN\n");
                got_output = false;
            } else {
                got_output = true;
            }
    
            if (got_output) {
                printf("Write frame %3d (size=%5d)\n", j++, pkt.size);
                av_interleaved_write_frame(avfctx, &pkt);
                av_packet_unref(&pkt);
            }
        }
    
        avcodec_close(c);
        av_free(c);
        av_freep(&frame->data[0]);
        av_frame_free(&frame);
        printf("\n");
        system("pause");
        return 0;
    }
    

    However VLC (opened with the generated SDP file) isn't able to play the stream. Messages has this

    core error: ES_OUT_RESET_PCR called
    

    followed by repeated

    packetizer_h264 warning: waiting for SPS/PPS
    core debug: Buffering %
    

    What am I doing wrong?

  • Unusual results extracting VP9 pkt_size with ffprobe as compared to H.264

    26 novembre 2016, par Jeff S.

    I'm trying to graph the bitrate over time for H.264 and VP9 videos by extracting the frame size with ffprobe, but many of the VP9 videos are showing significantly lower bitrate and total size than both the file size would indicate and that ffprobe reports.

    Can someone point me in the right direction for finding the missing bytes?

    For example:

    # The extracted values and the ffprobe values are very close for mp4
    Video Codec: h264
    Video Bitrate: 0.668869
    Frame Bitrate: 0.665552571931
    Video Size: 6381536.0
    Frame Total Size: 6349891
    
    # The extracted values and the ffprobe values are very different for some vp9 videos
    Video Codec: vp9
    Video Bitrate: 0.600966
    Frame Bitrate: 0.375144984531
    Video Size: 5730519.0
    Frame Total Size: 3577195
    

    Below is what I'm using for validation. Note that the sample videos do not contain audio.

    import subprocess
    import json
    
    def export_video_info(video_id):
        proc = subprocess.Popen(['ffprobe',
            '-v', 'quiet', '-print_format', 
            'json', '-show_format',
            '-show_streams', '-show_frames',
            video_id
            ],
            stdout=subprocess.PIPE,
        )
        return proc.communicate()[0]
    
    # Example video:  https://www.youtube.com/watch?v=g_OdgCrnzYo
    # youtube-dl --id -f 135 https://www.youtube.com/watch?v=g_OdgCrnzYo
    # youtube-dl --id -f 244 https://www.youtube.com/watch?v=g_OdgCrnzYo
    video_list = ['g_OdgCrnzYo.mp4', 'g_OdgCrnzYo.webm']
    
    '''
    Format for every frame: 
    
        {
            "media_type": "video",
            "key_frame": 0,
            "pkt_pts": 84484,
            "pkt_pts_time": "84.484000",
            "pkt_dts": 84484,
            "pkt_dts_time": "84.484000",
            "best_effort_timestamp": 84484,
            "best_effort_timestamp_time": "84.484000",
            "pkt_duration": 33,
            "pkt_duration_time": "0.033000",
            "pkt_pos": "7103361",
            "pkt_size": "28",
            "width": 854,
            "height": 480,
            "pix_fmt": "yuv420p",
            "sample_aspect_ratio": "1:1",
            "pict_type": "P",
            "coded_picture_number": 0,
            "display_picture_number": 0,
            "interlaced_frame": 0,
            "top_field_first": 0,
            "repeat_pict": 0
        },
    '''
    
    
    # NOTE: videos do not include audio
    for video in video_list:
        output = json.loads(export_video_info(video))
        ff_bitrate = float(output['format']['bit_rate']) / 10**6
        ff_duration = float(output['format']['duration'])
        ff_codec = output['streams'][0]['codec_name']
        ff_size = float(output['format']['size'])
        frame_size_sum = 0
        for val, items in enumerate(output['frames']):
            if output['frames'][val]['media_type'] == 'video': 
                frame_size_sum += int(output['frames'][val]['pkt_size'])
    
        frame_bitrate = frame_size_sum / ff_duration * 8 / 10**6
        print('Video Codec: {}\nVideo Bitrate: {}\nFrame Bitrate: {}\nVideo Size: {}\nFrame Total Size: {}\n\n'.format(ff_codec, ff_bitrate, frame_bitrate, ff_size, frame_size_sum))