Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Movie with png images in ffmpeg

    7 août 2018, par Madara Uchiha

    I have png images as alpha_water_10.png, alpha_water_20.png, upto alpha_water_2780.png. Now I want to make a movie with ffmpeg using this, but the ffmpeg -r 30 -start_number 10 -i alpha_water_%04d.png -c:v libx264 volfrac1.mp4 seems to give the video but it is not in the ascending order. The images at lets stay 270 will be right after the 20th image. Would anyone know its fix.

  • NodeJS spawning FFMPEG process does not understand arguments right

    7 août 2018, par 4D48

    I am writing code to speed up video using FFMPEG with multiplier. 5X for five times faster video, 0.5X for twice slower video etc.

    This code has worked previously in other use case, but it looks like there is something wrong with args array.

    var spawn = require('child_process').spawn;
    var cmd = 'node_modules\\ffmpeg-binaries\\bin\\ffmpeg.exe';
    
    speedupFilename = tmpdir + vts + 'speedup.mp4';
    
    var args = ['-i', filename, '-filter:v ', '"setpts=PTS/' + multiplier + '"', speedupFilename];
    console.log(cmd + ' ' + args.join(' '));
    
    var proc = spawn(cmd, args);
    
    /* code that reads stdout and print it out to console */
    

    This prints out in console:

    node_modules\ffmpeg-binaries\bin\ffmpeg.exe -i C:\Users\User\AppData\Local\Temp\1533658543video.mp4 -filter:v  "setpts=PTS/0.10" C:\Users\User\AppData\Local\Temp\1533658543speedup.mp4
    ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
    built with gcc 5.4.0 (GCC)
    
       configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
    libavutil      55. 34.100 / 55. 34.100
    libavcodec     57. 64.100 / 57. 64.100
    libavformat    57. 56.100 / 57. 56.100
    libavdevice    57.  1.100 / 57.  1.100
    libavfilter     6. 65.100 /  6. 65.100
    libswscale      4.  2.100 /  4.  2.100
    libswresample   2.  3.100 /  2.  3.100
    libpostproc    54.  1.100 / 54.  1.100
    
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\User\AppData\Local\Temp\1533658543video.mp4':
    Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: 
    script.js:337 isomiso2avc1mp41
        encoder         : Lavf57.56.100
    Duration: 00:00:00.12, start: 0.000000, bitrate: 9398 kb/s
        Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 9340 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
        Metadata:
        handler_name    : VideoHandler
    
    [AVFilterGraph @ 05c67dc0] No such filter: '"setpts'
    Error opening filters!
    

    I have setpts filter in my FFMPEG, I have looked into ffmpeg -filters.

    If I run command (first line in output) in console, it works fine.

    If I change -filter:v ', '"setpts=PTS/' + multiplier + '"' to -filter:v "setpts=PTS/' + multiplier + '"' in args array (remove ', ' to connect those two array items), then it just says At least one output file must be specified:

    ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
    built with gcc 5.4.0 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
    
    libavutil      55. 34.100 / 55. 34.100
    libavcodec     57. 64.100 / 57. 64.100
    libavformat    57. 56.100 / 57. 56.100
    libavdevice    57.  1.100 / 57.  1.100
    libavfilter     6. 65.100 /  6. 65.100
    libswscale      4.  2.100 /  4.  2.100
    libswresample   2.  3.100 /  2.  3.100
    libpostproc    54.  1.100 / 54.  1.100
    Trailing options were found on the commandline.
    
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\User\AppData\Local\Temp\1533659280video.mp4':
    Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands:
    isomiso2avc1mp41
        encoder         : Lavf57.56.100
    Duration: 00:00:00.12, start: 0.000000, bitrate: 9398 kb/s
        Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720, 9340 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
        Metadata:
        handler_name    : VideoHandler
    At least one output file must be specified
    
  • FFMPEG combining many files and filters at once

    7 août 2018, par Vadim

    I need to make 1 video from 5 different pieces (mp4,mp3,png):

    [0] input.mp4 (120fps 4 sec)

    1 sequence of .png (2 sec and its looped)

    [2] sound.mp3 (3 minutes, but i only need the same time as input.mp4)

    [3] Title1.mp4 (30fps its sets in begining)

    [4] Title2.mp4 (30 fps its sets in the end)


    I tried to explain in picture below: enter image description here

    Its too hard for me to understand the filtergraph syntex as i thinks my steps must be like this:


    1. I need slow Input.mp4 to 30 frames "setpts=PTS*10,fps=30"and " boxblur=luma_radius=2:luma_power=1 boxblur=2:1" ill get outMain.mp4 [outMain]
    2. Then i overlay .png and .mp3 there is i have a problem, maybe "overlay=shorters=1" and "-loop 1" ill get outMain2.mp4[outMain2]
    3. And the final ill need to Concat it all in order "[3][outMain2][4]concat=n=3 out output.mp4"

    How to make it in one action and add a -ultrafast preset, speed is important for me? Thanks

    I understood how to use filtegraph a bit: But it appears another question in comments with looping overlay after slowing video in one action...

    In first i slow video:

    ffmpeg -i input.mp4  -r 24 -vf "setpts=(10/1)*PTS" -c:v libx264 -preset ultrafast -crf 26 -c:a copy output.mp4
    

    Then Overlay png and add .mp3:

    ffmpeg -i input.mp4 -i alpha.png -i dorn.mp3 -filter_complex "[0:v][1:v]overlay" -c:v libx264 -preset ultrafast -crf 26 -c:a copy -y -map 2:a -shortest out.mp4
    

    Add begin title and final title:

    ffmpeg -i input.mp4 -i preroll.mp4 -filter_complex "[1][0][1]concat=n=3" -preset ultrafast -crf 26 -c:a copy output.mp4
    

    But it freezes with "Buffer queue overflow, dropping" Will try to resolve problem. The key to the freeze was simple. If i want to paste [0] video in the begining and in the end i must specify one more "-i" for example:

    ffmpeg -i 0.mp4 -i 1.mp4 -i 0.mp4 -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0] concat=n=3:v=1:a=1 [v][a]" -map "[v]" -map "[a]" -c:v libx264 -preset ultrafast -crf 26 output_video.mp4
    
  • DTS and PTS are different, despite not having B-frames (ffmpeg)

    7 août 2018, par Damian

    Just a quick question in regards to video encoding/muxing a video file with ffmpeg. Basically, I have my muxer functioning and I'm trying to have my packets output the correct PTS/DTS.

    This is a portion of my code that encodes my AVFrame, muxing it to an output file:

    int ret;
    int got_packet = 0;
    
    AVPacket pkt = { 0 };
    av_init_packet(&pkt);
    
    pkt.data = NULL;
    pkt.size = 0;
    
    /* encode the image */
    ret = avcodec_encode_video2(cc, &pkt, frame, &got_packet);
    if (ret < 0)
    {
        fprintf(stderr, "error encoding video frame: %s\n", av_err2str(ret));
        exit(EXIT_FAILURE);
    }
    
    if (got_packet)
    {
        av_packet_rescale_ts(&pkt, cc->time_base, st->time_base);
    
        fprintf(stderr, "\npkt.pts     = %ld\n", pkt.pts);
        fprintf(stderr,   "pkt.dts     = %ld\n", pkt.dts);
        fprintf(stderr, "writing frame\n");
    
        ret = av_interleaved_write_frame(fmt_ctx, &pkt);
        av_packet_unref(&pkt);
    }
    else
    {
        ret = 0;
    }
    
    ...
    

    I'm then getting an output of the following:

    pkt.pts     = 0
    pkt.dts     = 0
    writing frame
    
    pkt.pts     = 1502
    pkt.dts     = 0
    writing frame
    
    pkt.pts     = 3003
    pkt.dts     = 1502
    writing frame
    
    pkt.pts     = 4505
    pkt.dts     = 3003
    writing frame
    
    ...
    

    My goal is to have my PST and DST both with the pattern: 1502, 3003, 4505, 6006, 7508, ...

    But it seems that the first DTS value is repeating once, and thus being off-sync with it's corresponding PTS value. It's also worth mentioning that the codec context was configured to have no b-frames, so only i- and p- frames are present here.

    Does anyone with more experience have some insight on this?

    Addition:

    I ran the following command in terminal to check if my DTS and PTS values were consistent to my print statements:

    sudo ./ffprobe -show_packets -print_format json mux_test.ts | less
    

    And I got the following:

    {
        "packets": [
            {
                "codec_type": "video",
                "stream_index": 0,
                "pts": 0,
                "pts_time": "0.000000",
                "dts": -1501,
                "dts_time": "-0.016678",
                "duration": 1501,
                "duration_time": "0.016678",
                "convergence_duration": "N/A",
                "convergence_duration_time": "N/A",
                "size": "55409",
                "pos": "564",
                "flags": "K"
            },
            {
                "codec_type": "video",
                "stream_index": 0,
                "pts": 1502,
                "pts_time": "0.016689",
                "dts": 0,
                "dts_time": "0.000000",
                "duration": 1501,
                "duration_time": "0.016678",
                "convergence_duration": "N/A",
                "convergence_duration_time": "N/A",
                "size": "46574",
                "pos": "60160",
                "flags": "_"
            },
            {
                "codec_type": "video",
                "stream_index": 0,
                "pts": 3003,
                "pts_time": "0.033367",
                "dts": 1502,
                "dts_time": "0.016689",
                "duration": 1501,
                "duration_time": "0.016678",
                "convergence_duration": "N/A",
                "convergence_duration_time": "N/A",
                "size": "2544",
                "pos": "110356",
                "flags": "_"
            },
    
            ...
    

    Which doesn't show my first DTS value repeated, but continues to show my DTS one cycle behind my PTS.

  • Android convert exo to mp4 after download dash

    7 août 2018, par Ali

    I have downloaded a Dynamic Adaptive Streaming over HTTP (DASH) via android DashDownloader class that is provided by exo player.

    SimpleCache cache = new SimpleCache(file.getAbsoluteFile(), new NoOpCacheEvictor());
    DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory("ExoPlayer", null);
    DownloaderConstructorHelper constructorHelper = new DownloaderConstructorHelper(cache, factory);
    
    // Create a downloader for the first representation of the first adaptation set of the first
    // period.
    DashDownloader dashDownloader = new DashDownloader(Uri.parse(url), Collections.singletonList(new RepresentationKey(0, 0, 0)), constructorHelper);
    dashDownloader.download();
    

    Above code save many chunk .exo files into provided directory, How can i convert this files to single mp4 file?