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

时间:2019-01-07 13:11:34

标签: ffmpeg video-streaming hls transcoding mpeg2-ts

我正在构建使用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。毋庸置疑,尽管命令本身可以运行并且可以完成我需要的操作(但质量差),但我还是把它搞砸了。谁能帮助我优化此命令,以使其转码的视频损失更少?

1 个答案:

答案 0 :(得分:0)

我修复了它。我有两个问题:每个输出的比特率太低,并且命令本身是错误的,因为我对所有输出都使用-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"