English 中文(简体)
如何利用FFMPEG与Nvidia Endion(Nvenc)在子标题中硬编码/烧伤
原标题:How to use FFMPEG with Nvidia Acceleration (Nvenc) to hardcode / burn in subtitles

因此,Im试图利用Nvenc加速录像编码。 目的是有1个投入视频文档和1个投入分标题,并在不同决议中获得多种产出,并用硬编码或焚烧录像带。 我尝试了多种办法,但可以说明如何这样做。

这里指挥我目前使用的是:

ffmpeg -hwaccel cuvid -i 3030025890-TEST.mp4 -i output_ar.srt  -filter_complex "[0:v]scale_npp=1920:1080, hwdownload,format=nv12[base], [base]subtitles=output_ar.srt[marked]" -map "[marked]" -c:v h264_nvenc -map 0:v:0 -map 0:a:0 -g 50 -b:v 5M -maxrate 5.5M -minrate 4M -bufsize 5M -preset fast 1080_output.mp4

并在此列出产出:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from  3030025890-TEST.mp4 :
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: isomavc1mp42
    creation_time   : 2021-01-05T13:45:58.000000Z
  Duration: 00:45:04.28, start: 0.000000, bitrate: 5574 kb/s
    Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 5000 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2021-01-05T13:45:58.000000Z
      handler_name    : ETI ISO Video Media Handler
      encoder         : Elemental H.264
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2021-01-05T13:45:58.000000Z
      handler_name    : ETI ISO Audio Media Handler
    Stream #0:2(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2021-01-05T13:45:58.000000Z
      handler_name    : ETI ISO Audio Media Handler
    Stream #0:3(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2021-01-05T13:45:58.000000Z
      handler_name    : ETI ISO Audio Media Handler
    Stream #0:4(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2021-01-05T13:45:58.000000Z
      handler_name    : ETI ISO Audio Media Handler
    Stream #0:5(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2021-01-05T13:45:58.000000Z
      handler_name    : ETI ISO Audio Media Handler
    Stream #0:6(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2021-01-05T13:45:58.000000Z
      handler_name    : ETI ISO Audio Media Handler
Input #1, srt, from  output_ar.srt :
  Duration: N/A, bitrate: N/A
    Stream #1:0: Subtitle: subrip
[Parsed_subtitles_3 @ 0x5601070b1dc0] Shaper: FriBidi 0.19.7 (SIMPLE)
Fontconfig error: Cannot load default config file
[Parsed_subtitles_3 @ 0x5601070b1dc0] No usable fontconfig configuration file found, using fallback.
Fontconfig error: Cannot load default config file
[Parsed_subtitles_3 @ 0x5601070b1dc0] Using font provider fontconfig
Stream mapping:
  Stream #0:0 (h264) -> scale_npp (graph 0)
  subtitles (graph 0) -> Stream #0:0 (h264_nvenc)
  Stream #0:0 -> #0:1 (h264 (native) -> h264 (h264_nvenc))
  Stream #0:1 -> #0:2 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[h264 @ 0x56010792f980] Error creating a NVDEC decoder: 1
[h264 @ 0x56010792f980] Failed setup for format cuda: hwaccel initialisation returned error.
[Parsed_subtitles_3 @ 0x560107364cc0] Shaper: FriBidi 0.19.7 (SIMPLE)
Fontconfig error: Cannot load default config file
[Parsed_subtitles_3 @ 0x560107364cc0] No usable fontconfig configuration file found, using fallback.
Fontconfig error: Cannot load default config file
[Parsed_subtitles_3 @ 0x560107364cc0] Using font provider fontconfig
Impossible to convert between the formats supported by the filter  graph 0 input from stream 0:0  and the filter  auto_scaler_0 
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:0
[aac @ 0x56010734d400] Qavg: 65536.000
[aac @ 0x56010734d400] 2 frames left in the queue on closing
Conversion failed!

Edit: Made some progress. I now no longer get an error, but upon viewing the output, there s no subtitles burned in. Command:

ffmpeg -hwaccel cuvid -c:v h264_cuvid -i 3030025890-TEST.mp4  -c:v h264_nvenc -map 0:v:0 -map 0:a:0 -g 50 -b:v 5M -maxrate 5.5M -minrate 4M -bufsize 5M -vf "scale_npp=1920:1080, hwdownload, format=nv12, subtitles=output_ar.srt, hwupload" -preset fast 1080_output.mp4
问题回答

奥基,因此我已设法解决这个问题。 我正在一个拖车集装箱内行刺,并提出了自己的一套问题。

  1. If you re using linux and see something such as "Fontconfig error: Cannot load default config file" then make sure you have fontconfig installed. On Ubuntu:
sudo apt-get update -y
sudo apt-get install -y fontconfig-config

如果与我一样,你再使用一个cker子集装箱,去掉上述错误,那么,你就会确保把以下指挥器添加到你的cker子中:

RUN apt-get update -y
RUN apt-get install -y fontconfig-config

  1. If you re planning on running any filters on your CPU (some filters such as subtitles and libass are unsupported on the GPU / using hardware acceleration), then you ll have to download the frames (only if using the -hwaccel flag) after decoding onto your RAM before applying the filters and re-uploading to the GPU VRAM. In my case I won t be using the -hwaccel flag as this makes it simpler to run CPU bound filters as per Nvidia s documentation. In my tests, it also makes things a bit faster. The filter command then becomes:

-vf “底部”

  1. Combine the above points and you arrive at the following command. Note the absence of the -hwaccel flag.

ffmpeg -threads 16 -vsync 0 -c:v h264_cuvid -i 3030025890-TEST.mp4 -c:v h264_nvenc -vf “底部” 1080p_output.mp4 -vf "subtitles=mysubtitles.srt, hwupload_cuda, scale_npp=1280:720" -c:v h264_nvenc -preset fast 720p_output.mp4

Edit:Wasn不满意上述指挥系统的表现,因此,我花了一些时间试图优化这一指挥。 我所发现的是,你可以使用分裂的过滤器将产出流分开。 我基本上采用的是使用万国邮联的编码,然后下载到万国邮联的记忆中,采用一次过滤器,将其上载到万国邮联,将产出流分成到2个(1080p产出1,720p产出1),然后让万国邮联处理加编码。 与先前的指挥相比,这种编码速度增加了5x。

这就是我目前使用的指令(指出,还有其他旗帜,例如,主机间隔和——b:五)设定目标比值,这取决于您的用途情况:

ffmpeg -i Input.mp4 -c:v h264_nvenc - 地图:0 -g 50 -b:v 5.0M -maxrate 5.5M - minrate 4.2M - bufize 4.5M -filter_complex “[0:v]subsessions=“my Subs.srt”,hwupload_cuda,split=2[c0][c1];[c0]pl_npp=1920:1080[1080];[c1]pl_npp=1280:720[720];” -map “[1080]” -presetge “1080p_output.mp4” -c:v264_nvenc - 地图0:a:0 -g 50 -b:v 3.4M -maxrate 3.7M -minrate 2.8M -bufsize 3.1M -map “[720]” -presetspe “720p_output.mp4”

我在此认为,我是个先天原因,在使用“pu”时,我只想发现它甚至没有发现新的发现灯。 (crying emoji)

由于上述一些原因,我不得不把工作削减到:

ffmpeg -threads 12 -vsync 0 -c:v h264_cuvid -i 1.mp4 -c:v h264_nvenc -vf “sub entitleds=1.ass, hwupload_cuda” 1080p_output.mp4

Maybe something with the type of sub file not being srt etc? I m semi clueless when it comes to coding so... there s also that.





相关问题
Non-linear video editing tool/API?

Can anyone recommend a good library that would enable me to write an application that can blend multiple input videos into one output video (for example into a split screen). I don t care about the ...

WPF playing a video, shopping up, can I preload?

Im showing a video int my application, but its being chopped up, its locally on disc so I dont understand why this is so... any way i can start to preload it before playing it - so the content would ...

FLVs on timeline are glitching out

I have a Movieclip with about five FLV movies embedded on its timeline, one after another. I am loading multiple instances (about 5-10) of this movieclip onto the stage. Once added to the stage, they ...

Get the dimensions of a H.264 MP4

Does anybody know a ready-made, reliable way to tell the dimensions (width x height) of a MP4 encoded using the H.264 codec without ffmpeg or similar extensions, in pure PHP? Thanks for all the ...

热门标签