Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • use audio in video to write video subtitles [on hold]

    17 septembre 2015, par armoured

    wanted to know how to extract audio from a video clip, then convert the audio to text, and use the text as the subtitles to the video, which is to be broken into smaller clips. The idea was to have several clips of the same video with different subtitles, and then combine the clips into one nic video. I am doing this using python, and moviepy in particular. Tried it, but don't know how to extract change audio in a video to text in moviepy, please help

  • FFMPEG improve MP4 encoding speed [on hold]

    17 septembre 2015, par Kim T

    My input files are MP4, which are combined with an overlay to one MP4 video file. How can I improve the speed of these FFMPEG commands?

    ./ffmpeg -y -i intro.mp4 -f mpegts 0.ts
    ./ffmpeg -y -i record.mp4 -i overlay.png -filter_complex "[0:v][1:v] overlay=0:0" -ac 2 -f mpegts 1.ts
    ./ffmpeg -y -i outro.mp4 -f mpegts 2.ts
    ./ffmpeg -y -i "concat:0.ts|1.ts|2.ts" -vcodec libx264 -preset ultrafast -strict -2 output.mp4
    

    Commands that improved speed:

    • upgrading ffmpeg to version 2.42 with neon support for my device
    • -f mpegts = converts videos to transport streams which process faster
    • -preset ultrafast = tells encoder to use fastest encoding preset
    • -ss before -i = seeks straight to start point without processing frames

    Commands where I saw no speed improvement:

    • -c copy = copies the stream, but this doesn't seem to work on overlay filters and concats :(
    • -threads 2 = tells FFMPEG to use more threads, but don't noticed an improvement over the default
  • capture my webcam and encode to mp4 with ffmpeg, but the x264 works bad

    17 septembre 2015, par zhangxm1991

    here is my version: ffmpeg version: 2.3.3 libx264 version:142.x

    I wat to capture my video and use ffmpeg and x264 to a mp4 file. the solution is 320x240. But i found that the video file is so big. Then i found that the P frame and B frame is very big, even nearly equal to the I frame.I do not know why.

    here is my code:

        c->codec_id = codec_id;
        c->bit_rate = 400000;
        c->width    = 320;
        c->height   = 240;
        c->time_base.den = 10;
        c->time_base.num = 1;
        c->pix_fmt       = AV_PIX_FMT_YUV420P;
    

    Here is my program output:

    [libx264 @ 0xb6200fc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX 
    
    [libx264 @ 0xb6200fc0] profile High, level 1.3
    
    [libx264 @ 0xb6200fc0] 264 - core 142 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - 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=10 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=400 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    
    Output #0, mp4, to '/home/2014_09_12/0002b6429579/5/2014_09_12_18_39_12_600.mp4':
    
        Stream #0:0: Video: h264 (libx264), yuv420p, 320x240, q=-1--1, 400 kb/s, 10 tbc
    
        Stream #0:1: Audio: aac, 8000 Hz, mono, fltp, 32 kb/s
    
    [mp4 @ 0xb62005e0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
    
    [mp4 @ 0xb62005e0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
    
    [mp4 @ 0xb62005e0] Encoder did not produce proper pts, making some up.
    
    [libx264 @ 0xb6200fc0] frame I:3     Avg QP: 2.79  size: 72996
    
    [libx264 @ 0xb6200fc0] frame P:383   Avg QP: 0.14  size: 54075
    
    [libx264 @ 0xb6200fc0] frame B:216   Avg QP: 1.95  size: 64784
    
    [libx264 @ 0xb6200fc0] consecutive B-frames: 30.1% 63.2%  6.0%  0.7%
    
    [libx264 @ 0xb6200fc0] mb I  I16..4: 16.1% 12.7% 71.2%
    
    [libx264 @ 0xb6200fc0] mb P  I16..4:  3.5%  5.1% 15.9%  P16..4: 20.3% 22.8% 14.0%  0.0%  0.0%    skip:18.3%
    
    [libx264 @ 0xb6200fc0] mb B  I16..4:  0.4%  2.5%  8.2%  B16..8: 32.6% 19.8% 13.5%  
    direct:22.2%  skip: 0.8%  L0:25.5% L1:12.8% BI:61.6%
    
    [libx264 @ 0xb6200fc0] final ratefactor: -32.89
    
    [libx264 @ 0xb6200fc0] 8x8 transform intra:21.0% inter:29.6%
    
    [libx264 @ 0xb6200fc0] coded y,uvDC,uvAC intra: 100.0% 100.0% 100.0% inter: 83.3% 80.9% 80.9%
    
    [libx264 @ 0xb6200fc0] i16 v,h,dc,p:  5%  7% 42% 46%
    
    [libx264 @ 0xb6200fc0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 14% 12% 23%  8%  6%  6%  8%  9% 14%
    
    [libx264 @ 0xb6200fc0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 12% 11% 19% 10%  8%  8% 10% 10% 12%
    
    [libx264 @ 0xb6200fc0] i8c dc,h,v,p: 78%  3%  4% 15%
    
    [libx264 @ 0xb6200fc0] Weighted P-Frames: Y:0.5% UV:0.3%
    
    [libx264 @ 0xb6200fc0] ref P L0: 43.4% 14.6% 19.0% 22.9%  0.1%
    
    [libx264 @ 0xb6200fc0] ref B L0: 63.3% 35.7%  1.1%
    
    [libx264 @ 0xb6200fc0] ref B L1: 97.0%  3.0%
    
    [libx264 @ 0xb6200fc0] kb/s:4.53
    
    [aac @ 0xb6201ba0] 2 frames left in the queue on closing
    
  • How to get width and height from the H264 SPS using ffmpeg

    17 septembre 2015, par mpromonet

    I am trying to initialize an FFMPEG H264 codec context filling the extradata field with the SPS frame like this :

    #include avcodec.h>
    #include avformat.h>   
    
    int main()
    {
        const char sps[] = {0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x0a, 0xf8, 0x41, 0xa2};  
        av_register_all();
        av_log_set_level(AV_LOG_DEBUG);
    
        AVCodec *const codec = avcodec_find_decoder(CODEC_ID_H264);
        if (codec != NULL) 
        {               
            AVCodecContext* ctx = avcodec_alloc_context3(codec);
            ctx->debug = ~0;
            ctx->extradata = (uint8_t *)av_malloc(sizeof(sps) + FF_INPUT_BUFFER_PADDING_SIZE);
            ctx->extradata_size = sizeof(sps);
            memcpy(ctx->extradata,sps,sizeof(sps)); 
            memset(&ctx->extradata[ctx->extradata_size], 0, FF_INPUT_BUFFER_PADDING_SIZE); 
    
            if (avcodec_open2(ctx, codec, NULL) < 0) 
            {
                fprintf(stderr, "Failed to open codec\n");
            }
            else
            {   
                char buf[1024];
                avcodec_string(buf,sizeof(buf),ctx,1);
                fprintf(stderr, "%s\n", buf);
            }
            avcodec_close(ctx);
            av_free(ctx);
        }
    }
    

    The output of the program is :

    [h264 @ 0xc74010] NAL 7/3 at 4/11 length 6
    [h264 @ 0xc74010] sps:0 profile:66/10 poc:0 ref:0 8x6 FRM crop:0/0/0/0 420 0/0 b8 reo:-1
    Video: h264, 1 reference frame, none(left), q=2-31, 200 kb/s

    The output show that sps was decoded with the needed information to compute width and height by h264_ps.c (mb_width=8, mb_height=6, crop_left=crop_right=crop_top=crop_bottom=0).

    Then I was expecting to get the width and the height calling avcodec_string.
    Is there a way to do this without decoding frames ?

  • FFMPEG : Output to a new file after certain period of time with creation time stamp ?

    17 septembre 2015, par Anakooter

    Suppose I have a command:

    ffmpeg -f v4l2 -framerate 30 -video_size 640x480 -i /dev/video1 -c:v libx265 -x265-params bitrate=60:vbv-maxrate=60:vbv-bufsize=16:keyint=10:qcomp=0.5 -tune zerolatency -s 640x480 -preset ultrafast -pix_fmt yuv420p -r 5 -strict experimental -f somedate.ts
    

    What I want to do is that after 30 minutes ffmpeg starts writing the stream to new file with filename as time of creation of new file.