VideoHelp Forum

+ Reply to Thread
Results 1 to 2 of 2
Thread
  1. Hi!

    I need to convert a mkv file to an mp4 file with a specific bitrate and resolution . Down here you can find the string that I'm using right now:
    Code:
    ffmpeg -benchmark -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i input.mkv -map 0:v -map 0:a:m:language:ita -map -0:s -movflags +faststart -vf hwupload,scale_npp=640:-2 -c:a aac -b:a 64k -ac 2 c:v h264_nvenc -b:v 500k -bufsize 500k 360p.mp4
    With such conversion my GPU usage is 100% and the fps are beyond 500.
    Now I need to hard encode on the video the subtitles contained in a srt file and I'm using this string:
    Code:
    ffmpeg -benchmark -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i input.mkv -map 0:v -map 0:a:m:language:ita -map -0:s -movflags +faststart -vf hwupload,scale_npp=640:-2,hwdownload,format=nv12,subtitles=subtitle.srt -c:a aac -b:a 64k -ac 2 c:v h264_nvenc -b:v 500k -maxrate 500k -bufsize 500k 360p.mp4
    I know that hard encoding the subtitles involve a video re-encode, but my overall performance drop: the GPU usage is near 60% and the fps stay below 400.

    I don't know if my command can be improved in order to obtain better performance. If you have some advice please help me

    Thanks in advice,
    Alberto
    Quote Quote  
  2. ffmpeg -benchmark -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -i input.mkv -map 0:v -map 0:a:m:language:ita -map -0 -movflags +faststart -vf hwupload,scale_npp=640:-2,hwdownload,format=nv12,subtitles=subtitle.srt -c:a aac -b:a 64k -ac 2 c:v h264_nvenc -b:v 500k -maxrate 500k -bufsize 500k 360p.mp4

    I think this can be simplified.

    I've done re-encoding on a Cuda enabled PC (though without burning in subtitles) and on a QSV enabled PC (with subtitles.

    change -hwaccel cuda to -hwaccel dxva2

    Strip out most of the 'stuff' in the command line.

    Get a copy of Subtitle Edit https://github.com/SubtitleEdit/subtitleedit (if you have a system that will run it) or some other subtitle editing or conversion program. It will read subtitles that are in an MKV file and create the ASS file.

    Change your "SRT" titles to "ASS". The ASS file contains information about the fonts, character size, placement, etc, so you don't have to stuff it into the command line for ffmpeg.

    This works for me on a QSV system:

    ffmpeg -hide_banner -init_hw_device qsv=qsv -hwaccel qsv -vsync 1 "inputfile.mkv" -c:a aac -b:a 192k -ar 48000 ^
    -c:v h264_qsv -preset veryslow -vf "ass=subtitle_file.ass" -profile:v high -bsf:v h264_metadata=level=41 -movflags faststart -q:v 30 "output.mp4"

    The -profile and metadata_level specifications are there because I'm playing the created files through Roku Media Player and it chokes on anything that has a Level greater than 4.1 . If you don't have that problem, leave out -profile and -bsf .

    I have also found that it's much, much better to specify a quality factor than a bit rate for video.

    Changing my command line to this:

    ffmpeg -hide_banner -init_hw_device qsv=qsv -hwaccel qsv -vsync 1 "inputfile.mkv" -c:a aac -b:a 64k -ac 2 -c:v h264_nvenc -preset hp -vf "ass=subtitle_file.ass (plus whatever cropping you want to do)" -movflags faststart -q:v 30 "output.mp4"

    should do what you want with less trouble. The placement of audio compression first and video second seems to be important.

    If you can't easily mix a cuda enabled filter with a non-cuda filter you can go back to using your 'upload' and 'download' commands, but I've found for something like a simple crop or resize it's better to just use the normal "scale=" filter. By the time you go through all of the upload and download of frames you're not saving much, if anything, by using cuda_npp (at least this is true for QSV, but then, it's possible to mix QSV and non-QSV filters in -vp without going through all of the upload and download crap).

    If this doesn't work let me know and I can do some more tests on my CUDA system.
    Quote Quote  



Similar Threads