ffmpegnvenc

ffmpeg scaling nvenc maintaining aspect ratio


I want to fully hw transcode mkv files to mp4 and up- /downscale the content maintaning the aspect ratio.

With CPU based transcoding you just add:

scale=1920:1080:force_original_aspect_ratio=decrease

With HW (CUDA) transcoding either -resize on Decoding side or -scale_npp on encoding side is possible but both dont seem to be capable to force original acpect ratio.

I want to for instance upscale 1920x800 file to 1920x1080 while filling the rest with black bars so I can overlay subtitles over the bars for instance...

With this i can fully transcoding using GPU power reather than utilizing cpu. any ideas?


Solution

  • With scale_npp, you can implement force_original_aspect_ratio manually.

    Assuming your max size is 1920x1080,

    it would be

    scale_npp=w='if(gt(a\,1920/1080)\,1920\,oh*a)':h='if(gt(a\,1920/1080)\,ow/a\,1080)'
    

    However, neither scale nor scale_npp will pad the input. That requires use of the s/w pad filter.