gpt4 book ai didi

Ffmpeg 转换为 HLS - 视频质量极低

转载 作者:行者123 更新时间:2023-12-04 22:55:24 25 4
gpt4 key购买 nike

我正在构建一个使用 FFMPEG 的流式网络应用程序。客户端通过 RTMP 使用 FFMPEG 发送网络摄像头视频(在此过程中将 webm 流转换为 mpeg-ts),媒体服务器接收 mpeg-ts 流,将其转码为具有多个 ABR 质量级别的 HLS(使用主播放列表) .

到目前为止,我已经完成了所有这些工作,只是我的转码命令创建了质量极低的 HLS 段;视频非常像素化,最好的质量水平(1080p)看起来就像 240p 放大到 1080p。为了测试我的 FFMPEG 命令,我将一个高质量的 1080p 电影样本重新混合到 mpeg-ts 中(我检查了质量,它看起来与原版相同),我正在使用这个命令将这部电影转码为 HLS 以进行测试:

ffmpeg.exe -threads 4 -filter_complex_threads 4 -vsync 1 -i output.ts -filter_complex 
"[v:0]split=5[s0][s1][s2][s3][s4];
[s0]scale=w=1920:h=1080:flags=lanczos,yadif[v0];
[s1]scale=w=1280:h=720:flags=lanczos,yadif[v1];
[s2]scale=w=854:h=480:flags=lanczos,yadif[v2];
[s3]scale=w=480:h=360:flags=lanczos,yadif[v3];
[s4]scale=w=426:h=240:flags=lanczos,yadif[v4]"
-map "[v0]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v 3400k -preset medium -profile:v baseline -keyint_min 24 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v1]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v 1725k -preset medium -profile:v baseline -keyint_min 24 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v2]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v 960k -preset medium -profile:v baseline -keyint_min 24 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v3]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v 510k -preset medium -profile:v baseline -keyint_min 24 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v4]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v 320k -preset medium -profile:v baseline -keyint_min 24 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map a:0 -map a:0 -map a:0 -map a:0 -map a:0 -c:a aac -b:a 96k -af “aresample=async=1:min_hard_comp=0.100000:first_pts=0”
-f hls -var_stream_map "v:0,a:0 v:1,a:1, v:2,a:2, v:3,a:3, v:4,a:4"
-hls_wrap 24 -hls_time 10 -master_pl_name master.m3u8 "C:/Users/John/Desktop/ffmpeg-20181218-978c935-win64-static/bin/vs%v/manifest.m3u8"

我对 FFMPEG 很陌生,我提到了 this视频选项的文章,并将其修改为创建 HLS 而不是 mp4。不用说我把这个搞砸了,尽管命令本身可以工作并且可以满足我的需要(除了糟糕的质量)。谁能帮我优化此命令以使其转码有损视频少得多?

最佳答案

我修好了它。我有两个问题:每个输出的比特率太低,并且命令本身是错误的,因为我对所有输出都使用了 -b:v [bitrate] 而不是像 -b:v:0 [比特率]。正确的工作输出命令是这样的:

ffmpeg.exe -threads 4 -filter_complex_threads 4 -vsync 1 -i output.ts -filter_complex 
"[v:0]split=5[s0][s1][s2][s3][s4];
[s0]scale=w=1920:h=1080:flags=lanczos,yadif[v0];
[s1]scale=w=1280:h=720:flags=lanczos,yadif[v1];
[s2]scale=w=854:h=480:flags=lanczos,yadif[v2];
[s3]scale=w=480:h=360:flags=lanczos,yadif[v3];
[s4]scale=w=426:h=240:flags=lanczos,yadif[v4]"
-map "[v0]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v:0 12M -preset medium -profile:v baseline -keyint_min 24 -level 3.0 -s 1920:h=1080 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v1]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v:1 7.5M -preset medium -profile:v baseline -keyint_min 24 -level 3.0 -s 1280:h=720 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v2]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v:2 4M -preset medium -profile:v baseline -keyint_min 24 -level 3.0 -s 854:h=480 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v3]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v:3 1.5M -preset medium -profile:v baseline -keyint_min 24 -level 3.0 -s 480:h=360 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map "[v4]" -pix_fmt yuv420p -r 23.976 -vcodec libx264 -b:v:4 1M -preset medium -profile:v baseline -keyint_min 24 -level 3.0 -s 426:h=240 -g 48 -x264opts no-scenecut -strict experimental -map_metadata -1
-map a:0 -map a:0 -map a:0 -map a:0 -map a:0 -c:a aac -b:a 96k -af “aresample=async=1:min_hard_comp=0.100000:first_pts=0”
-f hls -var_stream_map "v:0,a:0 v:1,a:1, v:2,a:2, v:3,a:3, v:4,a:4"
-hls_wrap 24 -hls_time 10 -master_pl_name master.m3u8 "C:/Users/John/Desktop/ffmpeg-20181218-978c935-win64-static/bin/vs%v/manifest.m3u8"

关于Ffmpeg 转换为 HLS - 视频质量极低,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54075090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com