带有NVENC和DVB字幕和覆盖选项的FFMPEG

时间:2018-06-26 14:11:57

标签: ffmpeg nvenc

嗨,我对NVENC,DVB字幕和叠加功能有疑问。

我设法将dvb字幕刻录到输入视频中,但是我注意到这无法在GPU上完全执行,因为我使用的是FFMPEG的 Overlay 功能,该功能只有在软件中才能实现。

当前代码在应用叠加层之前,将字幕缩放为1920x1080。我注意到,这不仅仅将字幕直接覆盖在视频上,还占用了更多的CPU。问题是我想在中间底部中覆盖字幕。当前代码将字幕居中在屏幕中央(有点烦人)

最终我想要一个完整的硬件转码选项(猜测不可能吗?

我希望字幕在底部中央不缩放(CPU负载减少50%) 我希望字幕在中间底部缩放50%(cpu负载减少30%),这使字幕更易于阅读。

当前字幕的代码已按视频大小缩放(如何进行完整的硬件转码?):

-hwaccel_device 4 -hwaccel cuvid -vcodec h264_cuvid -resize 1920x1080 -deint 2 -drop_second_field 1 -i 'http://stream' -filter_complex "[i:0x1389]hwdownload,format=nv12[base];[i:0x13ee]scale=1920:1080[subtitle];[base][subtitle]overlay[v];[v]hwupload_cuda[v]" -map "[v]" -map i:0x1393 -acodec libfdk_aac -b:a 96k -c:v h264_nvenc -gpu 4 -preset llhq -vprofile high -rc:v vbr -qmin:v 26 -qmax:v 32 -b:v 4M -maxrate 4M -bufsize 8M -threads 0 -r 25 -g 100 -f flv 'rtmp://127.0.0.1:8001/input/nvenctest.stream'

代码字幕未缩放但居中。如何更改为中心底部:

-hwaccel_device 4 -hwaccel cuvid -vcodec h264_cuvid -resize 1920x1080 -deint 2 -drop_second_field 1 -i 'http://stream' -filter_complex "[i:0x1389]hwdownload,format=nv12[base];[base][i:0x13ee]overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2[v];[v]hwupload_cuda[k]" -map "[k]" -map i:0x1393 -acodec libfdk_aac -b:a 96k -c:v h264_nvenc -gpu 4 -preset llhq -vprofile high -rc:v vbr -qmin:v 26 -qmax:v 32 -b:v 4M -maxrate 4M -bufsize 8M -threads 0 -r 25 -g 100 -f flv 'rtmp://127.0.0.1:8001/input/nvenctest.stream'

ffprobe输出:

[mpegts @ 0x3786200] sub2video: using 1920x1080 canvas
[Parsed_showinfo_0 @ 0x3785340] config in time_base: 1/90000, frame_rate: 0/1
[Parsed_showinfo_0 @ 0x3785340] config out time_base: 0/0, frame_rate: 0/0
No information about the input framerate is available. Falling back to a default value of 25fps for output stream #0:0. Use the -r option if you want a different framerate.
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf58.3.100
    Stream #0:0: Video: wrapped_avframe, bgra, 1920x1080, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.9.100 wrapped_avframe
[Parsed_showinfo_0 @ 0x3785340] n:   0 pts:      0 pts_time:0       pos:       -1 fmt:bgra sar:0/1 s:1920x1080 i:P iskey:1 type:? checksum:00000000 plane_checksum:[00000000] mean:[0] stdev:[0.0]
[Parsed_showinfo_0 @ 0x3785340] n:   1 pts:      0 pts_time:0       pos:       -1 fmt:bgra sar:0/1 s:1920x1080 i:P iskey:1 type:? checksum:00000000 plane_checksum:[00000000] mean:[0] stdev:[0.0]
[Parsed_showinfo_0 @ 0x3785340] n:   2 pts:  39599 pts_time:0.439989 pos:       -1 fmt:bgra sar:0/1 s:1920x1080 i:P iskey:1 type:? checksum:00000000 plane_checksum:[00000000] mean:[0] stdev:[0.0]
[graph 0 input from stream 0:2 @ 0x37c9340] Changing frame properties on the fly is not supported by all filters.
Segmentation fault (core dumped)

1 个答案:

答案 0 :(得分:2)

要重新放置缩放的字幕,请提供x&y exprs:overlay=x=0:y=H/2

要重新放置未缩放的字幕,请overlay=x=(W-w)/2:y=H-h-20

可以使用OpenCL覆盖过滤器,但是由于字幕流仍需要在软件中进行解码,并且上传/下载步骤将占用资源,因此它不会提供太多好处。