Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to fix "Cannot find a valid font for the family Sans' while adding text on image using react-native-ffmpeg

    13 mai, par coffee

    I am trying to add text on image using the code below RNFFmpeg .execute(`-y -i ${input} -vf "drawtext=text='Hello World':fontcolor=white:fontsize=75:x=0:y=0" ${output}`);

    I am not using any custom font but still get this error.

    Error:

    [Parsed_drawtext_0 @ 0x7f87a1ce40] Cannot find a valid font for the family Sans

    index.js:115 [AVFilterGraph @ 0x7f6765e760] Error initializing filter 'drawtext' index.js:115 [AVFilterGraph @ 0x7f6765e760] with args 'text=Hello World:fontcolor=white:fontsize=75:x=0:y=0' index.js:115 [AVFilterGraph @ 0x7f6765e760]

    index.js:115 Error reinitializing filters!

    index.js:115 Failed to inject frame into filter network: No such file or directory

    index.js:115 Error while processing the decoded data for stream #0:0

    Note:

    I also tried using a custom font but not able to do it. When I use RNFFmpegConfig.setFontDirectory('../../assets/fonts') function and with it the following code to add text on image RNFFmpeg .execute(`-y -i ${input} -vf "drawtext=text='Hello World':fontfile='../../assets/fonts/MyFont.ttf':fontcolor=white:fontsize=75:x=0:y=0" ${output}`);

    It gives me the same error.

    How can I fix this issue.

  • Nix package : Pass build flag —extra-cflags to ffmpeg at compile time

    13 mai, par catleeball

    I'm a little inexperienced with Nix and NixOS and am struggling a bit with this ffmpeg source build. Any advice is appreciated!

    Goal

    Build ffmpeg from source with --extra-cflags="-pipe -O3 -march=znver3 -ffat-lto-objects", ideally using a flake or overlay or similar so that I can build off the existing ffmpeg nix package and maybe even reproducible builds.

    Attempts

    I've been trying to follow different advice I've seen online, but looking at ffmpeg in nixpkgs, I'm not sure what I could patch or override. Since configureFlags happens inside the stdenv.mkderivation block, when I try to override it, it doesn't seem to have scope into this variable (and since the derivation explicitly sets onfigurePlatforms = [];, I'm not sure if that would clobber the override changes unless I tried to override the whole long derivation).

    Looking at the ffmpeg configure script, it seemed like environment variable cflags / cxxflags won't be respected, but it will take them from the --extra-cflags argument, but I could be missing something.

    Flake attempt

    Here's an example flake.nix I forked from an example I saw at this github repo

    {
      description = "A full build of ffmpeg, including the proprietary stuff";
    
      inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
      inputs.flake-utils.url = "github:numtide/flake-utils";
    
      outputs = { self, nixpkgs, flake-utils }:
        flake-utils.lib.eachDefaultSystem (system:
          let
            pkgs = import nixpkgs {
              inherit system;
              config.allowUnfree = true;
            };
    
            overrides = {
              ffmpeg = pkgs.ffmpeg-full;
              # If this did work, I'm not sure how it would combine with the derivation in the existing package, e.g. if it would get overridden
              configureFlags = [ "--extra-cflags -march=znver3 -O3 -pipe -ffat-lto-objects" ];
              withHeadlessDeps = true;
              nonfreeLicensing = true;
              # more options here once things are working above
            };
          in
          rec {
            packages.ffmpeg-custom = pkgs.ffmpeg-full.override overrides;
            defaultPackage = packages.ffmpeg-custom;
          }
        );
    }
    

    when building with nix profile install, I encounter the error:

           error: function 'anonymous lambda' called with unexpected argument 'configureFlags'
    
           at /nix/store/d9wpzgyjlpw1424kw2lyilah6690fnk3-source/pkgs/development/libraries/ffmpeg-full/default.nix:1:1:
    
                1| { lib, stdenv, buildPackages, ffmpeg, addOpenGLRunpath, pkg-config, perl, texinfo, yasm
                 | ^
                2| /*
    

    presumably since configureFlags is defined in the derivation in the original package.

    Overlay in configuration.nix attempt

    I tried adding this to my /etc/nixos/configuration.nix also without success:

    nixpkgs.overlays = [
      (self: super: {
        ffmpeg-full = super.ffmpeg-full.override {
          configureFlags = [
            "--enable-hardcoded-tables"
            "--extra-cflags -march=znver3 -O3 -pipe -ffat-lto-objects"
          ] ++ super.ffmpeg-full.configureFlags;
        };
      })
    ];
    

    when building with nixos-rebuild switch I get the same error:

           error: function 'anonymous lambda' called with unexpected argument 'configureFlags'
    
           at /nix/store/amxbqlhq11xfrbs4vdsyi04fap0abx0v-nixos-23.11/nixos/pkgs/development/libraries/ffmpeg/generic.nix:3:1:
    
                2|
                3| { lib, stdenv, buildPackages, removeReferencesTo, addOpenGLRunpath, pkg-config, perl, texinfo, yasm
                 | ^
                4|
    

    Context

    I have a NixOS machine that does very long-running ffmpeg encodes nearly all the time. I was hoping to rebuild headless ffmpeg with more aggressive cflags and maybe some extra options. I hope to benchmark performance differences between different builds.

    I'll probably use this as an excuse to also build ffmpeg with some extra nonfree dependencies too.

  • D3D11 hardware screen recording with ffmpeg using Intel H264 QSV hardware encoding

    13 mai, par Cactus

    I'm trying to screen record using ffmpeg and having it all done via hardware on my Intel integrated graphics.

    Specs

    For reference, here are my specs:

    • Windows 11 Pro Version 10.0.22631 Build 22631
    • Model: Dell Inc. OptiPlex 3090
    • Processor: 11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz, 2995 Mhz, 2 Core(s), 4 Logical Processor(s)
    • Terminal: Windows Terminal using Windows Powershell

    In this wiki, it looked like I could use the "Windows 8+ Desktop Duplication API" to be "directly encoded by a compatible hardware encoder" — so I thought that I could use h264_qsv to encode, allowing me to record without much performance overhead costs.

    Attempt 1

    I've tried copying one of the command examples, but it didn't work:

    ffmpeg -init_hw_device d3d11va -filter_complex ddagrab=0 
    

    Output:

    ffmpeg version 2024-05-02-git-71669f2ad5-full_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers
      built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
      configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxeve --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
      libavutil      59. 16.101 / 59. 16.101
      libavcodec     61.  5.103 / 61.  5.103
      libavformat    61.  3.103 / 61.  3.103
      libavdevice    61.  2.100 / 61.  2.100
      libavfilter    10.  2.101 / 10.  2.101
      libswscale      8.  2.100 /  8.  2.100
      libswresample   5.  2.100 /  5.  2.100
      libpostproc    58.  2.100 / 58.  2.100
    Stream mapping:
      ddagrab:default -> Stream #0:0 (h264_qsv)
    Press [q] to stop, [?] for help
    Impossible to convert between the formats supported by the filter 'Parsed_ddagrab_0' and the filter 'auto_scale_0'
    [fc#0 @ 000001e4ed4393c0] Error configuring filter graph: Function not implemented
    [fc#0 @ 000001e4ed4393c0] Task finished with error code: -40 (Function not implemented)
    [fc#0 @ 000001e4ed4393c0] Terminating thread with return code -40 (Function not implemented)
    [vost#0:0/h264_qsv @ 000001e4ed454000] Could not open encoder before EOF
    [vost#0:0/h264_qsv @ 000001e4ed454000] Task finished with error code: -22 (Invalid argument)
    [vost#0:0/h264_qsv @ 000001e4ed454000] Terminating thread with return code -22 (Invalid argument)
    [out#0/matroska @ 000001e4ed453280] Nothing was written into output file, because at least one of its streams received no packets.
    frame=    0 fps=0.0 q=0.0 Lsize=       0KiB time=N/A bitrate=N/A speed=N/A
    Conversion failed!
    

    Attempt 2

    I then tried copying one of the command examples in the linked ddagrab wiki page, but also no luck.

    ffmpeg -f lavfi -i ddagrab -c:v h264_qsv output.mkv
    

    Output:

    ffmpeg version 2024-05-02-git-71669f2ad5-full_build-www.gyan.dev Copyright (c) 2000-2024 the FFmpeg developers
      built with gcc 13.2.0 (Rev5, Built by MSYS2 project)
      configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libxevd --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxeve --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-dxva2 --enable-d3d11va --enable-d3d12va --enable-ffnvcodec --enable-libvpl --enable-nvdec --enable-nvenc --enable-vaapi --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
      libavutil      59. 16.101 / 59. 16.101
      libavcodec     61.  5.103 / 61.  5.103
      libavformat    61.  3.103 / 61.  3.103
      libavdevice    61.  2.100 / 61.  2.100
      libavfilter    10.  2.101 / 10.  2.101
      libswscale      8.  2.100 /  8.  2.100
      libswresample   5.  2.100 /  5.  2.100
      libpostproc    58.  2.100 / 58.  2.100
    Input #0, lavfi, from 'ddagrab':
      Duration: N/A, start: 0.000000, bitrate: N/A
      Stream #0:0: Video: wrapped_avframe, d3d11, 1920x1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 1000k tbn
    File 'output.mkv' already exists. Overwrite? [y/N] y
    Stream mapping:
      Stream #0:0 -> #0:0 (wrapped_avframe (native) -> h264 (h264_qsv))
    Press [q] to stop, [?] for help
    Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scale_0'
    [vf#0:0 @ 00000115e105bd40] Error reinitializing filters!
    [vf#0:0 @ 00000115e105bd40] Task finished with error code: -40 (Function not implemented)
    [vf#0:0 @ 00000115e105bd40] Terminating thread with return code -40 (Function not implemented)
    [vost#0:0/h264_qsv @ 00000115e105aa00] Could not open encoder before EOF
    [vost#0:0/h264_qsv @ 00000115e105aa00] Task finished with error code: -22 (Invalid argument)
    [vost#0:0/h264_qsv @ 00000115e105aa00] Terminating thread with return code -22 (Invalid argument)
    [out#0/matroska @ 00000115e1054b80] Nothing was written into output file, because at least one of its streams received no packets.
    frame=    0 fps=0.0 q=0.0 Lsize=       0KiB time=N/A bitrate=N/A speed=N/A
    Conversion failed!
    

    My main problem is that I don't know how to use really any of these encoders and the examples I've found above don't work with me. What command should I use to screen record all with hardware acceleration on my Intel system? I don't care about any presets or other options at the moment.

    Is there also a way to record audio? When I tried to use -f dshow -i audio="Stereo Mix (Realtek(R) Audio)" by itself, which I made sure was turned on in Windows' settings and named correctly, it didn't work (is it because I'm using Bluetooth headphones that isn't connected to Realtek's system?). Should this question be made separately than this one?

  • Why every audio part is louder in FFmpeg when I join them in one audio ?

    13 mai, par Volodymyr Bilovus

    I trying to make dubbing for audio. I have original audio track and I want to put translated audio parts on top of the original.

    translated audio 100% vol: --p1--- ---p2-- -----p3--- --p4--

    original audio 5% vol: -----------------------------------------

    Here is my FFmpeg command with filter_complex

    ffmpeg -i video_wpmXlZF4XiE.opus -i 989-audio.mp3 -i 989-audio.mp3 -i 989-audio.mp3 -i 989-audio.mp3 \
    -filter_complex "\
    [0:a]loudnorm=I=-14:TP=-2:LRA=7, volume=0.05[original]; \
    [1:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=5000|5000, volume=1.0[sent1]; \
    [2:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=10000|10000, volume=1.0[sent2]; \
    [3:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=20000|20000, volume=1.0[sent3]; \
    [4:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=30000|30000, volume=1.0[sent4]; \
    [original][sent1][sent2][sent3][sent4]amix=inputs=5:duration=longest[out]" \
    -map "[out]" output.mp3
    

    Audios I put on top of the original audio track is the same -i 989-audio.mp3 I made it by purpose to show the problem And here is the audio levels on final generated track. enter image description here

    As you can see, first and second only slightly different but third and fourth have totally different(higher) volume level (Notice, audio is the same). Why it's happened? And how can I workaround this odd behaviour?

  • Why every audio part louder in FFmpeg while I join them in one audio ?

    13 mai, par Volodymyr Bilovus

    I trying to make dubbing for audio. I have original audio track and I want to put translated audio parts on top of the original.

    translated audio 100% vol: --p1--- ---p2-- -----p3--- --p4--

    original audio 5% vol: -----------------------------------------

    Here is my FFmpeg command with filter_complex

    ffmpeg -i video_wpmXlZF4XiE.opus -i 989-audio.mp3 -i 989-audio.mp3 -i 989-audio.mp3 -i 989-audio.mp3 \
    -filter_complex "\
    [0:a]loudnorm=I=-14:TP=-2:LRA=7, volume=0.05[original]; \
    [1:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=5000|5000, volume=1.0[sent1]; \
    [2:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=10000|10000, volume=1.0[sent2]; \
    [3:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=20000|20000, volume=1.0[sent3]; \
    [4:a]loudnorm=I=-14:TP=-2:LRA=7, adelay=30000|30000, volume=1.0[sent4]; \
    [original][sent1][sent2][sent3][sent4]amix=inputs=5:duration=longest[out]" \
    -map "[out]" output.mp3
    

    Audios I put on top of the original audio track is the same -i 989-audio.mp3 I made it by purpose to show the problem And here is the audio levels on final generated track. enter image description here

    As you can see, first and second only slightly different but third and fourth have totally different(higher) volume level (Notice, audio is the same). Why it's happened. And how can I workaround this odd behaviour?