rosenbjerg/FFMpegCore

Cannot use HardwareAccelerationDevice.Auto with ffmpeg 6.1.0

blfuentes opened this issue · 1 comments

Windows 1 22h2
.net 8 8.0.100
ffmpeg 6.1.0
ffmpegcore 5.1.0

I created a command line program that I use to convert from different formats to mp3 with ffmpeg.
It was working fine in 6.0.0 but since I've updated I get the following error for some files:

FFMpegCore.Exceptions.FFMpegException: 'ffmpeg exited with non-zero exit-code (69 - ffmpeg version 6.1-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --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-libzvbi --enable-librav1e --enable-libsvtav1 
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --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-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 
--enable-d3d11va --enable-libvpl --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      58. 29.100 / 58. 29.100
  libavcodec     60. 31.102 / 60. 31.102
  libavformat    60. 16.100 / 60. 16.100
  libavdevice    60.  3.100 / 60.  3.100
  libavfilter     9. 12.100 /  9. 12.100
  libswscale      7.  5.100 /  7.  5.100
  libswresample   4. 12.100 /  4. 12.100
  libpostproc    57.  3.100 / 57.  3.100
Input #0, flac, from 'D:\test\04. Red Giant.flac':
  Metadata:
    ARTIST          : Hippie Death Cult
    TITLE           : Red Giant
    ALBUM           : Helichrysum
    DATE            : 2023
    album_artist    : Hippie Death Cult
    track           : 4
    TRACKTOTAL      : 7
    disc            : 1
    DISCTOTAL       : 1
  Duration: 00:04:47.67, start: 0.000000, bitrate: 910 kb/s
  Stream #0:0: Audio: flac, 44100 Hz, stereo, s16
  Stream #0:1: Video: mjpeg (Progressive), yuvj420p(pc, bt470bg/unknown/unknown), 1400x1400 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn (attached pic)
    Metadata:
      comment         : Cover (front)
Using auto hwaccel type cuda with new default device.
Stream mapping:
  Stream #0:1 -> #0:0 (mjpeg (native) -> png (native))
  Stream #0:0 -> #0:1 (flac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
[mjpeg @ 0000015b83cc1b80] decoder->cvdl->cuvidDecodePicture(decoder->decoder, &ctx->pic_params) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid
[vist#0:1/mjpeg @ 0000015b83cc19c0] Error submitting packet to decoder: Generic error in an external library
[swscaler @ 0000015b8cf21c40] deprecated pixel format used, make sure you did set range correctly
[vost#0:0/png @ 0000015b838bd5c0] No filtered frames for output stream, trying to initialize anyway.
Output #0, mp3, to 'D:\test\output\Hippie Death Cult - Helichrysum\04. Red Giant.mp3':
  Metadata:
    TPE1            : Hippie Death Cult
    TIT2            : Red Giant
    TALB            : Helichrysum
    TDRC            : 2023
    TPE2            : Hippie Death Cult
    TRCK            : 4
    TRACKTOTAL      : 7
    TPOS            : 1
    DISCTOTAL       : 1
    TSSE            : Lavf60.16.100
  Stream #0:0: Video: png, rgb24(progressive), 1400x1400 [SAR 1:1 DAR 1:1], q=2-31, 200 kb/s, 90k fps, 90k tbn (attached pic)
    Metadata:
      comment         : Cover (front)
      encoder         : Lavc60.31.102 png
  Stream #0:1: Audio: mp3, 44100 Hz, stereo, s16p, 192 kb/s
    Metadata:
      encoder         : Lavc60.31.102 libmp3lame
frame=    0 fps=0.0 q=0.0 size=       0kB time=00:04:46.98 bitrate=   0.0kbits/s speed=21.2x    
[vist#0:1/mjpeg @ 0000015b83cc19c0] Decode error rate 1 exceeds maximum 0.666667
[mp3 @ 0000015b838b9d00] No packets were sent for some of the attached pictures.
[out#0/mp3 @ 0000015b838bbe00] video:0kB audio:6743kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.012484%
frame=    0 fps=0.0 q=0.0 Lsize=    6744kB time=00:04:47.66 bitrate= 192.1kbits/s speed=20.5x    
Conversion failed!)'

And this is the code I use to generate that conversion (It's F#, but I think it's easy enough to understand...)

let getConversionOutputOptions (options: FFMpegArgumentOptions) (codec: string) =
    match codec with
    | "mp3" ->  options.WithAudioBitrate(AudioQuality.Good)
                        .WithAudioCodec(AudioCodec.LibMp3Lame) |> ignore
    | "ac3" ->  options.WithAudioBitrate(AudioQuality.Good)
                        .WithAudioCodec(AudioCodec.Ac3) |> ignore
    | "ogg" ->  options.WithAudioBitrate(AudioQuality.Good)
                        .WithAudioCodec(AudioCodec.LibVorbis) |> ignore
    | "avi" -> options
                        .WithVideoCodec(VideoCodec.LibX264)
                        .WithAudioCodec(AudioCodec.LibMp3Lame)
                        .UsingMultithreading(true)
                        .UsingThreads(System.Environment.ProcessorCount)
                        .WithAudioBitrate(AudioQuality.Normal)
                        //.WithVideoBitrate(5000) // reduction of ~85%. Around 50% with 25000
                        .WithFastStart()
                        |> ignore
    | _ -> options.WithAudioBitrate(AudioQuality.Normal)
                    .WithAudioCodec(AudioCodec.LibMp3Lame) |> ignore

let getConversioInputOptions (options: FFMpegArgumentOptions) (codec: string) =
    options
        .WithHardwareAcceleration(HardwareAccelerationDevice.Auto)
        .UsingMultithreading(true)
        .UsingThreads(System.Environment.ProcessorCount)
        |> ignore

let processFile (codec: string) (outputfolder: string) (inputext: string) (file:string)=
    async {
        printfn "Processing file '%s' ..." file
        let outputFile = Path.Join([|outputfolder; (Path.GetFileName(file).Replace(inputext, codec)) |]) 
        if outputFile.EndsWith(codec) then
            let inputOptions = fun input -> getConversioInputOptions input codec
            let outputOptions = fun options -> getConversionOutputOptions options codec
            let processor = FFMpegArguments
                                .FromFileInput(file, true, inputOptions)
                                .OutputToFile(outputFile, true, outputOptions)

            processor.ProcessSynchronously() |> ignore
        else
            printfn "Skipping file '%s' as its format is not the expected." outputFile
        printfn "Processed! File saved to '%s' %s" outputFile System.Environment.NewLine
    }

If I change the line .WithHardwareAcceleration(HardwareAccelerationDevice.Auto) switching to D3D11VA for example, then I get no exception.

As I said, it was working before with the ffmpeg 6.0.0, but checking the changelog I have no idea how to adapt my code leaving the hardware acceleration to auto (or is this a bad idea?)

version 6.1:
- libaribcaption decoder
- Playdate video decoder and demuxer
- Extend VAAPI support for libva-win32 on Windows
- afireqsrc audio source filter
- arls filter
- ffmpeg CLI new option: -readrate_initial_burst
- zoneplate video source filter
- command support in the setpts and asetpts filters
- Vulkan decode hwaccel, supporting H264, HEVC and AV1
- color_vulkan filter
- bwdif_vulkan filter
- nlmeans_vulkan filter
- RivaTuner video decoder
- xfade_vulkan filter
- vMix video decoder
- Essential Video Coding parser, muxer and demuxer
- Essential Video Coding frame merge bsf
- bwdif_cuda filter
- Microsoft RLE video encoder
- Raw AC-4 muxer and demuxer
- Raw VVC bitstream parser, muxer and demuxer
- Bitstream filter for editing metadata in VVC streams
- Bitstream filter for converting VVC from MP4 to Annex B
- scale_vt filter for videotoolbox
- transpose_vt filter for videotoolbox
- support for the P_SKIP hinting to speed up libx264 encoding
- Support HEVC,VP9,AV1 codec in enhanced flv format
- apsnr and asisdr audio filters
- OSQ demuxer and decoder
- Support HEVC,VP9,AV1 codec fourcclist in enhanced rtmp protocol
- CRI USM demuxer
- ffmpeg CLI '-top' option deprecated in favor of the setfield filter
- VAAPI AV1 encoder
- ffprobe XML output schema changed to account for multiple
  variable-fields elements within the same parent element
- ffprobe -output_format option added as an alias of -of

I've found, that if I add the selectstream to the output options and get the Audio one, I can use the auto in hardwareacceleration...
.SelectStream(0, 0, Channel.Audio)

Why would be this?