Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg memory usage, or memory leaks

    26 janvier, par happycoding-boy

    I'v write a simple program to get audio waveform data, which using ffmpeg version 6.1. And program works fine. But I get a problem: when program running at begin, system report using about 6MB memory, but when I call the function and cleanup the resouce alloced, system report about 9MB memory used. In my theory, after cleanup, it should be 6MB again. [I'm sure, I freed the AVPacket when read stream, and AVFrame for decoding.] My question is: Is this normal or not?

    int main(int argc, char *argv[])
    {
        // breakpoint here: ~= 6MB
        get_audio_waveform();
        // breakpoint here: ~= 9MB
    }
    

    The ffmpeg struct I used:

    AVFormatContext*    p_input_fmt_ctx = nullptr;
    AVCodecContext*     p_input_cdc_ctx = nullptr;
    SwrContext*         p_resampler_ctx = nullptr;
    AVAudioFifo*        p_audio_fifo    = nullptr;
    uint8_t**           p_converted_input = nullptr;
    uint8_t**           p_converted_output = nullptr;
    

    The cleanup func:

    void _cleanup()
    {
        avformat_close_input(&p_input_fmt_ctx);
        avcodec_free_context(&p_input_cdc_ctx);
        swr_free(&p_resampler_ctx);
        
        if (p_audio_fifo)
        {
            av_audio_fifo_reset(p_audio_fifo);
            av_audio_fifo_free(p_audio_fifo);
            p_audio_fifo = nullptr;
        }
        
        if (p_converted_input)
        {
            av_freep(&p_converted_input[0]);
            free(p_converted_input);
            p_converted_input = nullptr;
        }
        
        if (p_converted_output)
        {
            av_freep(&p_converted_output[0]);
            free(p_converted_output);
            p_converted_output = nullptr;
        }
    }
    

    In my opinion,If this function have about 3MB memory leaks[6MB -> 9MB]. when I run this function 5-times, it should be about 15MB memory leaks.[6MB -> 21MB]. But when I run this function 5-times. After that, system just reports about 10-11 memory used. I doubt wheather program uses runtime library (i.e. libc or equivalent) and the library allocates some memory for own needs? I do not known which step is wrong!:(

  • FFMPEG - Fading text with background

    25 janvier, par Helder Santos

    I'm trying to fade a text in and out (the text has a background), at the moment, what I have is this command:

    1. Blend command

    ffmpeg -y -i input.mp4 -filter_complex "drawtext=fontfile=HelveticaNeue.ttf:text='Testing': fontcolor=white:fontsize=40: box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2[subtitles];[subtitles][0:v]blend=all_expr='A*(if(between(T,1,2),(T-1),0))+B*(1-(if(between(T,1,2),(T-1),0)))'[out]"  -map '[out]' -map 0:a output.mp4
    

    The command above successfully fades in the drawtext (aka subtitles in this filter), but I haven't managed to make it fade them out for some reason, because changing the numeric values of it don't quite have the result I expect.

    I've also tried a command that is less complex but doesn't work too for other reasons:

    2. Fade command

    ffmpeg -y -i input.mp4 -filter_complex "drawtext=fontfile=HelveticaNeue.ttf:text='Testing': fontcolor=white:fontsize=40: box=1: boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2[subtitles]; [subtitles]fade=t=in:st=2:d=1,fade=t=out:st=3:d=1[out]"  -map '[out]' -map 0:a output.mp4
    

    This second command fades in and out, but applies to the entire video and not the subtitles part alone.

    Any way someone can give me a hand with this?

  • ffmpeg batch reencode with subfolders

    25 janvier, par Alan

    I am trying to reencode a few hundred videos to X265 but there are many directories that have spaces in the filenames as do some of the files. I have looked at a bunch of scripts and am struggling to find one that works with the spaces and the different directory levels.

    This one works, as long as there is no sub directories:

    #!/bin/bash
    for i in *.avi;
    do 
        ffmpeg -i "$i" -c:v libx265 -c:a copy X265_"$i"
    done
    

    I have been trying to work with this bash script, but it fails with the whitespaces I am guessing.

    #!/bin/bash
    inputdir=$PWD
    outputdir=$PWD
    while IFS= read -r file ; do
      video=`basename "$file"`
      dir=`dirname "$file"`
     ffmpeg -fflags +genpts -i "$file" -c:v libx265 -c:a copy "$dir"/X265_"$video"
    done < <(find "$inputdir" -name "*.avi" | head -100)
    

    On this thread it looks like a good solution for windows users, but not linux. FFMPEG - Batch convert subfolders

    FOR /r %%i in (*.mp4) DO ffmpeg32 -i "%%~fi" -map 0:0 -map 0:1 -map 0:1 -c:v copy -c:a:0 aac -b:a 128k -ac 2 -strict -2 -cutoff 15000 -c:a:1 copy "%%~dpni(2)%%~xi"

    If you can point me to the right solution that is appropriate for bash, I would appreciate it.

  • ffmpeg using an expression for tile filter [closed]

    25 janvier, par kaarch

    Is there any way to supply the 'tile' filter of ffmpeg with an expression? I've tried about every combination I can think of using different escape characters and quotes, but it won't accept anything other than an explicit string like '10x10'. See the example below that works:

    ffmpeg -i "big_buck_bunny.mp4" -vf "tile=10x10" grid_%d.jpg
    

    I'd like to be able to do something like:

    ffmpeg -i "big_buck_bunny.mp4" -vf "tile=expr(n*2)x10" grid_%d.jpg
    

    Where 'n' is the current frame number. This isn't the exact expression I'm looking to use, but wanted to start with a simple example that I can then adapt to a more complex expression. Everything I've tried gives me an error like the following:

    [tile @ 0x7facc1d000c0] Unable to parse option value "expr(n*2)x10" as image size
    

    Can tile simply not accept an expression? Or is there some sort of concatenate function that I should be trying?

  • FFmpeg : canvas and crop work separately but result in black screen when combined

    25 janvier, par didi00

    I'm working on a video processing pipeline with FFmpeg, where I:

    • Create a black canvas using the color filter.
    • Crop a region from my video input.
    • Overlay the cropped region onto the black canvas.

    Both the canvas and the crop display correctly when tested individually. However, when I attempt to combine them (overlay the crop onto the canvas), the result is a black screen. What Works:

    Black Canvas Alone:

    ffmpeg -filter_complex "color=c=black:s=1920x1080[out]" -map "[out]" -f nut - | ffplay 
    -
    

    This shows a plain black screen, as expected.

    Cropped Region Alone:

    ffmpeg -f v4l2 -input_format yuyv422 -framerate 60 -video_size 1920x1080 -i /dev/video0 
    \ -vf "crop=1024:192:0:0" -f nut - | ffplay -
    

    This shows the cropped region of the video correctly.

    When I combine these steps to overlay the crop onto the black canvas, I get a black screen:

    ffmpeg -f v4l2 -input_format yuyv422 -framerate 60 -video_size 1920x1080 -i /dev/video0 
    \-filter_complex "color=c=black:s=1920x1080,format=yuv420p[background]; \
    [0:v]crop=1024:192:0:0,format=yuv420p[region0]; \
    [background][region0]overlay=x=0:y=0[out]" \
    -map "[out]" -f nut - | ffplay -
    

    Environment:

    • OS: Linux (Debian-based)
    • FFmpeg Version: [Insert version, e.g., 4.x or 5.x]
    • Capture Card Format: yuyv422

    Question:

    Why does the pipeline result in a black screen when combining the canvas and the crop, even though both work separately? Is this an issue with pixel format compatibility, or is there something I'm overlooking in the overlay filter setup?