如何在具有多个输入的硬件加速上使用ffmpeg?

时间:2019-03-20 12:39:07

标签: ffmpeg gpu multifile

我正在尝试通过使用GPU而不是CPU来加快视频的渲染速度。这段代码有效,但是我不知道我做的是否正确。

ffmpeg -hwaccel cuvid -c:v hevc_cuvid \
-i video.mp4 \
-i logo.png \
-i text.mov \
-c:v h264_nvenc \
-filter_complex " \
[0]scale_npp=1920:1080,hwdownload,format=nv12[bg0]; \
[bg0]trim=0.00:59.460,setpts=PTS-STARTPTS[bg0]; \
[1]scale=150:-1[logo1];[bg0][logo1]overlay=(W-w)-10:(H-h)-10[bg0]; \
[2]scale=500:-1[logo2];[logo2]setpts=PTS-STARTPTS[logo2]; \
[bg0][logo2]overlay=-150:-100[bg0]; \
[bg0]fade=in:00:30,fade=out:1750:30[bg0]" \
-map "[bg0]" -preset fast -y output.mp4 

我觉得我需要在那里的某个地方使用hwuplaod,但是我不确定。任何帮助,将不胜感激。

运行记录:

ffmpeg version 4.0 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
  configuration: --enable-gpl --enable-libx264 --enable-cuda --enable-nvenc --enable-cuvid --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include/ --extra-ldflags=-L/usr/local/cuda/lib64/
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
[hevc @ 0x3eb04c0] vps_num_hrd_parameters -1 is invalid
[hevc @ 0x3eb04c0] VPS 0 does not exist
[hevc @ 0x3eb04c0] SPS 0 does not exist.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.7.100
  Duration: 00:00:59.46, start: 0.000000, bitrate: 5894 kb/s
    Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 5891 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #1, png_pipe, from 'logo.png':
  Duration: N/A, bitrate: N/A
    Stream #1:0: Video: png, rgba(pc), 528x128 [SAR 11339:11339 DAR 33:8], 25 tbr, 25 tbn, 25 tbc
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'text.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf57.56.100
  Duration: 00:00:06.00, start: 0.000000, bitrate: 1276 kb/s
    Stream #2:0(eng): Video: qtrle (rle  / 0x20656C72), bgra, 1920x1080, 1274 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (default)
    Metadata:
      handler_name    : DataHandler
Stream mapping:
  Stream #0:0 (hevc_cuvid) -> scale_npp
  Stream #1:0 (png) -> scale
  Stream #2:0 (qtrle) -> scale
  fade -> Stream #0:0 (h264_nvenc)
Press [q] to stop, [?] for help
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.12.100
    Stream #0:0: Video: h264 (h264_nvenc) (Main) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 2000 kb/s, 29.97 fps, 30k tbn, 29.97 tbc (default)
    Metadata:
      encoder         : Lavc58.18.100 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 4000000 vbv_delay: -1
frame= 1783 fps=151 q=30.0 Lsize=   15985kB time=00:00:59.45 bitrate=2202.4kbits/s dup=4 drop=0 speed=5.04x    
video:15977kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.050389%

不确定如何处理,对于ffmpeg来说还很新。

1 个答案:

答案 0 :(得分:0)

请参阅此部分

Stream #0:0 (hevc_cuvid) -> scale_npp
Stream #1:0 (png) -> scale
Stream #2:0 (qtrle) -> scale
fade -> Stream #0:0 (h264_nvenc)

hevc_cuvid是输入流0:0的解码器,h264_nvenc是输出流0:0的编码器。两者都是硬件加速的。

其他两个输入视频流具有编解码器PNG和QTRLE,因此没有可用的硬件加速。