0

我正在尝试使用 ffmpeg 创建一个可变的 HLS MBR 实时流,它将在 GPU 级别完全加速。这意味着加速解码、去隔行、缩放和编码。这是我破碎的例子......

ffmpeg -loglevel debug -hwaccel cuvid -c:v h264_cuvid -hwaccel_output_format cuda -vsync 0 -i "udp://@239.250.4.152:1234?fifo_size=1000000&overrun_nonfatal=1" \
-filter_complex "[0:v]yadif_cuda=0:-1:0,split=3[v1][v2][v3],[v1]copy[v1out],[v2]scale_npp=1280:720[v2out],[v3]scale_npp=720:405[v3out]" \
-map [v1out] -c:v:0 hevc_nvenc -b:v:0 4000k -g 48 \
-map [v2out] -c:v:1 hevc_nvenc -b:v:0 3000k -g 48 \
-map [v3out] -c:v:2 hevc_nvenc -b:v:0 2000k -g 48 \
-map a:0 -c:a:0 aac -b:a:0 128k -ac 2 \
-map a:0 -c:a:1 aac -b:a:1 96k -ac 2 \
-map a:0 -c:a:2 aac -b:a:2 64k -ac 2 \
-f hls \
-hls_playlist_type event \
-hls_segment_type mpegts \
-hls_time $seglen \
-hls_list_size $numsegs \
-hls_flags delete_segments+independent_segments \
-hls_segment_filename "$dst/stream_%v/$segments" \
-hls_base_url "$url" \
-master_pl_name "$dst/$index" \
-var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2" \
"$dst/$index"

注意:我的显卡可以处理超过 2 个并发编码。我收到一个经典错误“无法在过滤器'Parsed_split_1'和过滤器'auto_scaler_0'支持的格式之间进行转换”。

我的目标是真的吗?或者在这种情况下尽可能高效地使用 GPU 的正确方法是什么?谢谢您的帮助。

Stream mapping:
   Stream # 0: 3 (h264_cuvid) -> yadif_cuda (graph 0)
   copy (graph 0) -> Stream # 0: 0 (h264_nvenc)
   scale_npp (graph 0) -> Stream # 0: 1 (h264_nvenc)
   scale_npp (graph 0) -> Stream # 0: 2 (h264_nvenc)
   Stream # 0: 4 -> # 0: 3 (ac3 (native) -> aac (native))
   Stream # 0: 4 -> # 0: 4 (ac3 (native) -> aac (native))
   Stream # 0: 4 -> # 0: 5 (ac3 (native) -> aac (native))
4

1 回答 1

0

我有一个可行的解决方案。不幸的是,由于分割过滤器复制了视频轨道,我还无法避免在 VRAM 和 RAM 之间移动。

ffmpeg -vsync 0  -hwaccel cuvid -c:v h264_cuvid -hwaccel_output_format cuda -i "udp://@239.250.4.152:1234?fifo_size=1000000&overrun_nonfatal=1" \
-filter_complex "[0:v]yadif_cuda=0:-1:0,hwdownload,format=nv12,split=3[v1][v2][v3]; [v1]copy[v1out]; [v2]hwupload,scale_npp=1280:720[v2out]; [v3]hwupload,scale_npp=720:405[v3out]" \
-map [v1out] -c:v:0 h264_nvenc -b:v:0 4000k -g 48 \
-map [v2out] -c:v:1 h264_nvenc -b:v:0 3000k -g 48 \
-map [v3out] -c:v:2 h264_nvenc -b:v:0 2000k -g 48 \
-map a:0 -c:a:0 aac -b:a:0 128k -ac 2 \
-map a:0 -c:a:1 aac -b:a:1 96k -ac 2 \
-map a:0 -c:a:2 aac -b:a:2 64k -ac 2 \
-f hls \
-hls_segment_type mpegts \
-hls_playlist_type vod \
-hls_time $seglen \
-hls_list_size $numsegs \
-hls_flags delete_segments+independent_segments \
-hls_segment_filename "$dst/stream_%v/$segments" \
-master_pl_name "$index" \
-var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2" \
"$dst/stream_%v/mystream.m3u8"
于 2021-07-06T21:14:36.223 回答