Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Merging 2 videos with overlay causes async problems

    3 novembre 2014, par Gnagy

    I'm using following FFMPEG command to merge 2 MKV inputs with the overlay parameter. The result should be one output with input1 on top of input2. In the process, the output should be webm. Both inputs are of the same length (with a margin of a second).

    ffmpeg -i input1.mkv -i input2.mkv -y -filter_complex [0:v]select=1, setpts=PTS-STARTPTS, scale=400:300, pad=400:600 [top]; [1:v]select=1, setpts=PTS-STARTPTS, scale=400:300 [bottom]; [top][bottom] overlay=0:300 [out]; [0:a:0][1:a:0] amerge=inputs=2 [a]; [a] asetpts=PTS-STARTPTS [a] -map [a] -c:v libvpx -crf 10 -b:v 360K -q:v 7 -c:a libvorbis -b:a 32k -map [out] output.webm
    

    This command does what it's supposed to do.

    However, the 2 videos are not totally in sync.

    The input1 on the top plays decently while the input2 on the bottom has black frames, slows down or speeds up and causes the audio and video to be out of sync.

    To rule out the individual quality of the inputs, we switched the position of the videos and the top video always plays decently.

    How can we fix this?

  • Show first and last frame longer in ffmpeg

    3 novembre 2014, par Gert Gottschalk

    I am building a time-lapse animation from single frames and would like to show the first and last frames longer than the prescribe frame rate. My initial ffmpeg call looks like this and works quite well. It creates the basic time-lapse animation from single frames.

    ffmpeg -r 16  -threads 0 -f image2 -pattern_type glob -i './sofi_20141022/octave2reg/IMG_*_cent.png' -c:v libx264 -s 1440x1080 -crf 24 ./Video/20141022_Partial_Solar_Eclipse_crf24_16fps.mp4
    

    But how do I add controls to have the first and last frame show longer (i.e for sec) ??

    Thanks, Gert

  • How to feed FFMPEG AV_CODEC_ID_PCM_S16BE audio data to AudioQueue

    3 novembre 2014, par Kai

    I am using FFMPEG in combination with FFmpegAudioPlayer to do live streaming. The issue I am having is that, while the audio can be decoded and played, there's a constant clicking/screeching noise in the audio that isn't present when streaming the same source by other applications. So I am guess the issue arise due to how I process the FFMPEG AV_CODEC_ID_PCM_S16BE audio data before handing it to AudioQueue:

    audioFormat.mFormatID = kAudioFormatLinearPCM;            
    audioFormat.mFormatFlags = kAudioFormatFlagsCanonical;//kAudioFormatFlagIsBigEndian|kAudioFormatFlagIsAlignedHigh;
    audioFormat.mSampleRate = pAudioCodecCtx->sample_rate;
    audioFormat.mBitsPerChannel = 8*av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
    audioFormat.mChannelsPerFrame = pAudioCodecCtx->channels;
    audioFormat.mBytesPerFrame = pAudioCodecCtx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
    audioFormat.mBytesPerPacket= pAudioCodecCtx->channels * av_get_bytes_per_sample(AV_SAMPLE_FMT_S16);
    audioFormat.mFramesPerPacket = 1;
    audioFormat.mReserved = 0;
    
    pSwrCtx = swr_alloc_set_opts(pSwrCtx,
                                                 1,//pAudioCodecCtx->channel_layout,
                                                 AV_SAMPLE_FMT_S16,
                                                 pAudioCodecCtx->sample_rate,
                                                 1,//pAudioCodecCtx->channel_layout,
                                                 AV_SAMPLE_FMT_S16,
                                                 pAudioCodecCtx->sample_rate,
                                                 0,
                                                 0);
    outCount = swr_convert(pSwrCtx,
                                                 (uint8_t **)(&pOut),
                                                 in_samples,
                                                 (const uint8_t **)pAVFrame1->extended_data,
                                                 in_samples);
    

    Please also note that I've tried many different parameters for swr_alloc_set_opts, but either the audio became unrecognizable or the noise persisted.

    Here's a sample of the audio with clicking sound, if it helps.

  • Change the frame order/sequence of a video (avconv/ffmpeg)

    2 novembre 2014, par Simon Streicher

    I want to use Python and a similar method explained by http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg:

    import subprocess as sp
    command = [ 'ffmpeg',
            '-y', # (optional) overwrite output file if it exists
            '-f', 'rawvideo',
            '-vcodec','rawvideo',
            '-s', '420x360', # size of one frame
            '-pix_fmt', 'rgb24',
            '-r', '24', # frames per second
            '-i', '-', # The imput comes from a pipe
            '-an', # Tells FFMPEG not to expect any audio
            '-vcodec', 'mpeg'",
            'my_output_videofile.mp4' ]
    
    pipe = sp.Popen( command, stdin=sp.PIPE, stderr=sp.PIPE)
    pipe.proc.stdin.write(image_array.tostring())
    

    to write an image array as frames to ffmpeg. In my application I will write the frames to the buffer as they are completed (not all at once as above).

    want to apply time-distortion to the output video from a "frame-map":

    Frame order In : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    Frame order Out: [1, 1, 2, 3, 3.5, 4, 4.5, 6, 7, 8, 9.5 10]
    

    Is there any way I can pipe in the frame sequence?

    I know I can just program my script to sent the frames in the correct order, but I was kind of hoping to discard the frames as I am done with them (I am talking about long HD videos) and let avconv/ffmpeg handle the ordering and inter-frame averaging (for example frame 3.5).

    My other option is to read the input frames at the output frame speed (by playing catchup) and keep the last 300 frames or so. Beforehand I can make sure my pipe wouldn't need a 301-or-more-frames-back frame. I can even make it more robust by keeping track of any 301-or-more-frames-back frames and make an exception for storing them.

    So could ffmpeg/avconv handle all this drama on its own, or do I have to code this up?

  • Using ffmpeg to generate multiple resolutions with the exact same keyframe positions

    2 novembre 2014, par bacon overlord

    There are a bunch of resources on how to use ffmpeg to convert X to Y and so forth but I can't seem to be able to generate different resolutions of the same file with the same keyframe and frame positions.

    The keyframe positions are important because they allow the player to jump from one bitrate to another.

    These videos are intended for Flash.

    I keep on getting results like this from the validation tool.

    failed on frame 1670
    [FrameInfo 1670, type 9, timecode 23565, seekable 1670]
    [FrameInfo 1670, type 9, timecode 23565, seekable 1525]
    

    Even worse, sometimes it takes to re-ordering the frames

    failed on frame 1
    [FrameInfo 1, type 9, timecode 0, seekable 1]
    [FrameInfo 1, type 8, timecode 0, seekable -1]
    

    When trying to validate the sample videos that are installed with Adobe Flash Media Server they are ok

    Comparing files
    0: G:\VOD\sample1_150kbps.flv
    1: G:\VOD\sample1_500kbps.flv
    2: G:\VOD\sample1_700kbps.flv
    3: G:\VOD\sample1_1500kbps.flv
    Index, Keyframes, and Timecodes are Validated across all files
    

    Sample ffmpeg command I run at different resolutions. Adobe Media Encoder is also producing video with different keyframe positions so I don't know whats going on here.

    ffmpeg -i source.mp4 -vf scale=1270:720 -c:a copy output.flv
    

    ffmpeg 720p

    ffmpeg -i .\big_buck_bunny_1080p_surround.avi -vf scale=1280:720 -vcodec libx264 -profile:v main -acodec libvo_aacenc -b:a 128k -ac 2  big_buck_bunny_720.flv
    

    ffmpeg 480p

    ffmpeg -i .\big_buck_bunny_1080p_surround.avi -vf scale=854:480 -vcodec libx264 -profile:v main -acodec libvo_aacenc -b:a 128k -ac 2  big_buck_bunny_480.flv
    

    ffmpeg console output

    ffmpeg version N-59433-g4aa9c91 Copyright (c) 2000-2013 the FFmpeg developers
      built on Dec 29 2013 22:01:53 with gcc 4.8.2 (GCC)
      configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfi
    g --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopenco
    re-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-li
    bvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
      libavutil      52. 59.100 / 52. 59.100
      libavcodec     55. 47.100 / 55. 47.100
      libavformat    55. 22.100 / 55. 22.100
      libavdevice    55.  5.102 / 55.  5.102
      libavfilter     4.  0.103 /  4.  0.103
      libswscale      2.  5.101 /  2.  5.101
      libswresample   0. 17.104 /  0. 17.104
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, avi, from '.\big_buck_bunny_1080p_surround.avi':
      Metadata:
        encoder         : AVI-Mux GUI 1.17.7, Aug  8 2006  20:59:17
        JUNK            :
      Duration: 00:09:56.46, start: 0.000000, bitrate: 12455 kb/s
        Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 24 tbr, 24 tb
    n, 24 tbc
        Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s
    File 'big_buck_bunny_720.flv' already exists. Overwrite ? [y/N] Y
    [libx264 @ 029deec0] using SAR=1/1
    [libx264 @ 029deec0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
    [libx264 @ 029deec0] profile Main, level 3.1
    [libx264 @ 029deec0] 264 - core 140 r2377 1ca7bb9 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.or
    g/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 m
    e_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_thr
    eads=2 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=24 scenecut=40 intra_refresh=0 rc_lookahead=40 r
    c=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 'big_buck_bunny_720.flv':
      Metadata:
        JUNK            :
        encoder         : Lavf55.22.100
        Stream #0:0: Video: h264 (libx264) ([7][0][0][0] / 0x0007), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 1k tbn, 2
    4 tbc
        Stream #0:1: Audio: aac (libvo_aacenc) ([10][0][0][0] / 0x000A), 48000 Hz, stereo, s16, 128 kb/s
    Stream mapping:
      Stream #0:0 -> #0:0 (mpeg4 -> libx264)
      Stream #0:1 -> #0:1 (ac3 -> libvo_aacenc)
    Press [q] to stop, [?] for help
    frame=14315 fps= 73 q=-1.0 Lsize=  120952kB time=00:09:56.49 bitrate=1661.1kbits/s
    video:110887kB audio:9321kB subtitle:0 global headers:0kB muxing overhead 0.619082%
    [libx264 @ 029deec0] frame I:151   Avg QP:17.09  size:115286
    [libx264 @ 029deec0] frame P:5374  Avg QP:21.41  size: 14154
    [libx264 @ 029deec0] frame B:8790  Avg QP:25.91  size:  2284
    [libx264 @ 029deec0] consecutive B-frames: 11.5% 15.5% 13.3% 59.7%
    [libx264 @ 029deec0] mb I  I16..4: 24.0%  0.0% 76.0%
    [libx264 @ 029deec0] mb P  I16..4:  4.0%  0.0%  3.5%  P16..4: 29.3% 11.1%  7.1%  0.0%  0.0%    skip:45.1%
    [libx264 @ 029deec0] mb B  I16..4:  0.2%  0.0%  0.4%  B16..8: 22.4%  1.7%  0.4%  direct: 0.8%  skip:74.1%  L0:37.5% L1:5
    8.0% BI: 4.5%
    [libx264 @ 029deec0] coded y,uvDC,uvAC intra: 51.5% 64.4% 37.6% inter: 7.3% 10.1% 1.3%
    [libx264 @ 029deec0] i16 v,h,dc,p: 40% 23%  9% 28%
    [libx264 @ 029deec0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 23% 18% 15%  7%  8% 10%  7%  7%  6%
    [libx264 @ 029deec0] i8c dc,h,v,p: 51% 21% 17% 10%
    [libx264 @ 029deec0] Weighted P-Frames: Y:5.9% UV:3.6%
    [libx264 @ 029deec0] ref P L0: 62.4% 16.9% 15.2%  5.3%  0.1%
    [libx264 @ 029deec0] ref B L0: 89.3%  9.1%  1.7%
    [libx264 @ 029deec0] ref B L1: 94.3%  5.7%
    [libx264 @ 029deec0] kb/s:1522.96
    

    Validation Results

    Comparing files
    0: G:\VOD\big_buck_bunny_480.flv
    1: G:\VOD\big_buck_bunny_720.flv
    >> Comparison failed on frame 13181
    0: [FrameInfo 13181, type 9, timecode 185958, seekable 12794]
    1: [FrameInfo 13181, type 9, timecode 185958, seekable 13181]