如何使用 cuda 在 ffmpeg 中分割和缩放流?

如何使用 cuda 在 ffmpeg 中分割和缩放流?

因此,我想为 hls 流式传输创建多种分辨率的流。以下是我迄今为止尝试过的方法:

ffmpeg -vsync 0 -hwaccel cuvid -i input.mkv -c:a aac -c:v h264_nvenc \
-c:s webvtt -crf 20 -filter_complex \
'[v:0]hwupload_cuda,split=2[vtemp001][vout002]:[vtemp001]hwupload_cuda,scale_npp=w=960:h=540:format=yuv420p:interp_algo=lanczos,hwdownload,format=yuv420p[vout001]'  \
-map "[vout001]" -b:v:0 2000k -map "[vout002]" \
-b:v:1 6000k -map 0:v -map 0:a -map 0:s -map 0:v \ 
-map 0:a -map 0:s -var_stream_map 'v:0,a:0,s:0 v:1,a:1,s:1' \ 
-force_key_frames:v "expr:gte(t,n_forced*2.000)" -hls_time 6 -hls_playlist_type event -hls_flags \
delete_segments+independent_segments+discont_start+program_date_time \
-master_pl_name master.m3u8 -hls_segment_filename \
fire/segment_%v/file%06d.ts fire/stream_%v.m3u8

运行此程序时,我收到以下错误:

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

当我在没有 gpu 的情况下执行相同的操作时,我收到内存不足错误,这听起来像是没有 gpu 就无法执行此操作(即我必须运行单独的 ffmpeg 命令才能在 CPU 上运行)。想知道是否有人有任何见解或建议。

我在这里尝试了一些更容易理解的东西:

ffmpeg -vsync 0 -hwaccel cuvid -i input.mkv -c:v h264_nvenc -filter_complex \
'[v:0]hwupload_cuda,split=2[vtemp001][vout002];[vtemp001]hwupload_cuda,scale_npp=w=960:h=540:format=yuv420p:interp_algo=lanczos,hwdownload,format=yuv420p[vout001]' \
-map "[vout001]" -b:v:0 2000k output1.mkv -map "[vout002]" -b:v:1 6000k output2.mkv

上述内容给出了相同的错误,对我来说,这表明问题出在过滤器复合体上。

答案1

类似这样的事情最终对我有用

ffmpeg -hwaccel_output_format cuda -i input.mkv -c:a aac -c:v h264_nvenc -c:s webvtt -crf 20 \
-vf hwupload_cuda,yadif_cuda=0:-1:0,scale_npp=w=960:h=540:interp_algo=linear \
    -b:v 2000k -force_key_frames:v "expr:gte(t,n_forced*2.000)" -hls_time 6 -hls_playlist_type event -hls_flags \
    delete_segments+independent_segments+discont_start+program_date_time \
    -hls_segment_filename out/file_960_%06d.ts out/stream960.m3u8 \
-vf scale=w=1280:h=720 \
    -b:v 2800k -force_key_frames:v "expr:gte(t,n_forced*2.000)" -hls_time 6 -hls_playlist_type event -hls_flags \
    delete_segments+independent_segments+discont_start+program_date_time \
    -hls_segment_filename out/file_1280_%06d.ts out/stream1280.m3u8

相关内容