Newest 'ffmpeg' Questions - Stack Overflow

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

Articles published on the website

  • libav ffmpeg - streaming from both a mkv and input stream

    20 January, by kealist

    I am trying to use ffmpeg libraries in C# with AutoGen bindings. The overall issue is that I am taking a collection of sources, some streams, and some .mkv containing recordings of a stream. As for now, they are all h264 and only video. For input streams, I am able to adjust the packets and broad cast them and that works fine, but any time I try to call av_interleaved_write_frame with packets from the MKV file, I get the error Error occurred: Invalid data found when processing input.

    Here is the main loop, where the error happens for mkv files. Is there an extra step?

    /* read all packets */
    while (true)
    {
        if ((ret = ffmpeg.av_read_frame(ifmt_ctx, &packet)) < 0)
        {
            Console.WriteLine("Unable to read packet");
            break;
        }
        stream_index = (uint)packet.stream_index;
        type = ifmt_ctx->streams[packet.stream_index]->codecpar->codec_type;
        Console.WriteLine($"Demuxer gave frame of stream_index %{stream_index}");
    
    
        /* remux this frame without reencoding */
        ffmpeg.av_packet_rescale_ts(&packet,
            ifmt_ctx->streams[stream_index]->time_base,
            ofmt_ctx->streams[stream_index]->time_base);
    
        if (packet.stream_index < 0)
        {
            Console.WriteLine("Packet stream error");
        }
    
    
    
        ret = ffmpeg.av_write_frame(ofmt_ctx, &packet);
        if (ret < 0)
        {
            goto end;
        }
        else
        {
            ffmpeg.av_packet_unref(&packet);
        }
    }
    

    Anything need to be different for MKV files?

    I get some contradictory error output where it claims it is annex b but also isn't:

    [AVBSFContext @ 00000220eb657080] The input looks like it is Annex B already
    Automatically inserted bitstream filter 'h264_mp4toannexb'; args=''
    [mpegts @ 00000220ebace300] H.264 bitstream malformed, no startcode found, use the video bitstream filter 'h264_mp4toannexb' to fix it ('-bsf:v h264_mp4toannexb' option with ffmpeg)
    

    Verbose output from ffplay from an MKV file:

    ffplay version git-2020-01-13-7225479 Copyright (c) 2003-2020 the FFmpeg developers
      built with gcc 9.2.1 (GCC) 20200111
      configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
      libavutil      56. 38.100 / 56. 38.100
      libavcodec     58. 65.103 / 58. 65.103
      libavformat    58. 35.102 / 58. 35.102
      libavdevice    58.  9.103 / 58.  9.103
      libavfilter     7. 71.100 /  7. 71.100
      libswscale      5.  6.100 /  5.  6.100
      libswresample   3.  6.100 /  3.  6.100
      libpostproc    55.  6.100 / 55.  6.100
    Initialized direct3d renderer.
    [h264 @ 00000165ed18d140] Reinit context to 640x480, pix_fmt: yuv444p
    Input #0, matroska,webm, from '.\webcam_14_Test1.mkv':   0B f=0/0
      Metadata:
        ENCODER         : Lavf58.12.100
      Duration: 00:00:39.30, start: 0.000000, bitrate: 1943 kb/s
        Stream #0:0: Video: h264 (High 4:4:4 Predictive), 1 reference frame, yuv444p(progressive, left), 640x480 [SAR 1:1 DAR 4:3], 1k fps, 30 tbr, 1k tbn, 60 tbc (default)
        Metadata:
          DURATION        : 00:00:39.299000000
    [h264 @ 00000165f424e200] Reinit context to 640x480, pix_fmt: yuv444p
    [ffplay_buffer @ 00000165f52ea840] w:640 h:480 pixfmt:yuv444p tb:1/1000 fr:30/1 sar:1/1
    [auto_scaler_0 @ 00000165ed1d2c80] w:iw h:ih flags:'bicubic' interl:0
    [ffplay_buffersink @ 00000165f424ef00] auto-inserting filter 'auto_scaler_0' between the filter 'ffplay_buffer' and the filter 'ffplay_buffersink'
    [auto_scaler_0 @ 00000165ed1d2c80] w:640 h:480 fmt:yuv444p sar:1/1 -> w:640 h:480 fmt:yuv420p sar:1/1 flags:0x4
    Created 640x480 texture with SDL_PIXELFORMAT_IYUV.
    [AVIOContext @ 00000165ed179a40] Statistics: 9547965 bytes read, 0 seeks
    
  • ffmpeg how to reduce bass and increase treble like audacity

    20 January, by Santhosh Yedidi

    I have an mp3 file. I want to reduce bass and increase treble. I am trying:

    ffmpeg -y -i original.mp3 -af "treble=g=10" test1.mp3

    but its not same as the effect of Audacity->Effect->bass and treble (increase treble and reduce bass)

    below is the image from audacity:

    enter image description here

  • Merge a sequence of JPEG images into a grid losslessly with FFmpeg

    20 January, by Mody

    I have a sequence of images that are blocks of a larger image, which together make up the whole image. The blocks are the result of splitting the original image along evenly spaced horizontal and vertical lines, so they don't have weird dimensions.

    Is there a way to combine them with FFmpeg (or something else like ImageMagick) without re-encoding the images?

    This answer suggests the hstack or vstack FFmpeg filter, but my image blocks aren't necessarily the full width or the full height of the original image.


    Like this:

    Six blocks of differing sizes in a 3-row, 2-column grid

    Perhaps this could be achieved with multiple FFmpeg commands using hstack or vstack (I'd prefer just one command though). Or with a complex filter?


    e.g. Mona Lisa split into six distinct blocks, then arranged together


    Edit: I tried using filter_complex with FFmpeg:

    ffmpeg -i 0.jpg -i 1.jpg -i 2.jpg -i 3.jpg -i 4.jpg -i 5.jpg \
    -filter_complex "[0][1]hstack=inputs=2[row 0]; \
                     [2][3]hstack=inputs=2[row 1]; 
                     [4][5]hstack=inputs=2[row 2]; 
                     [row 0][row 1][row 2]vstack=inputs=3[out]" \
    -map "[out]" -c copy out.jpg
    

    but it can't filter and copy streams at the same time.

  • Remove portion of some frames from a video

    20 January, by FlafyMation

    Here is what I'm trying to do: Imagine a video with 10 frames (0 = 1 frame)

    0 0 0 0 0 0 0 0 0 0

    with some frames selected(1 = 1 selected frame)

    0 1 1 1 0 0 0 0 0 0

    and the end results should be this(all selected frames got removed from the video)

    0 0 0 0 0 0 0

    this is what I'm trying to do in python(with frames not times). Does anybody knows how I can do that?

  • PowerShell doesn't recognize string correctly

    20 January, by fdroid

    I'm passing a command to powershell

    Dim command As String
    command = "ffmpeg -vsync 0 –hwaccel cuvid -c:v h264_cuvid –resize 1280x720 -i D:\Imagens\nova\bol.mkv -c:a copy -c:v h264_nvenc -b:v 5M D:\Imagens\nova\bol_encod.mkv"
    

    with

    Dim powerShell As String = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
        Process.Start("powershell", "-noexit " + command)
    

    but powershell returns

    Unable to find a suitable output format for 'ÔÇôhwaccel' ÔÇôhwaccel: Invalid argument

    where I believe 'ÔÇôhwaccel' to be –hwaccel; That's completely strange, once when I past the code directly on PowerShell it works fine.

    Is that a problem with my string?

    thank you!