FFmpeg透明PNG黑色轮廓问题

问题描述 投票:0回答:2

我正在使用 ffmpeg 对透明 PNG 视频进行编码。我注意到图像周围有一个轻微的黑色轮廓。有什么办法可以去掉吗

输出图像: image

透明PNG示例: image

我的 ffmpeg 命令

ffmpeg -hide_banner -y -ss 0.0 -t 8.5 -i C:\Users\Admin\Desktop\test_movies\6.mp4 -i C:\Users\Admin\Desktop\test_movies\text_and_emoji.png -filter_complex [0:v]setpts=PTS-STARTPTS,scale=640:640:force_original_aspect_ratio=decrease,pad=640:640:(ow-iw)/2:(oh-ih)/2:color=#18ffff[0v];[1:v]scale=556.24744:141.41884[1v];[0v][1v]overlay=(W-w)/2-(W/2-325.33328):(H-h)/2-(H/2-567.7075):enable='between(t,0.0,8.5)' -ac 2 -ar 44100 -vcodec libx264 -g 75 -r 20 -preset ultrafast -strict experimental C:\Users\Admin\Desktop\test_movies\test.mp4

最后编辑1:

我尝试不使用

[1:v]scale=556.24744:141.41884[1v]
,输出仍然有轻微的轮廓

输出示例: image

示例代码:

ffmpeg -hide_banner -y -ss 0.0 -t 8.5 -i C:\Users\Admin\Desktop\test_movies\white.mp4 -i C:\Users\Admin\Desktop\test_movies\text_and_emoji.png -filter_complex [0:v]scale=640:640:force_original_aspect_ratio=decrease,pad=640:640:(ow-iw)/2:(oh-ih)/2:color=#18ffff[0v];[0v][1:v]overlay=(W-w)/2-(W/2-325.33328):(H-h)/2-(H/2-567.7075):enable='between(t,0.0,8.5)' -ac 2 -ar 44100 -vcodec libx264 -preset ultrafast -strict experimental C:\Users\Admin\Desktop\test_movies\test.mp4

最后编辑2:

我尝试了另一种,添加了

alpha=premultiplied
和最新的 ffmpeg 版本。它以某种方式消除了轮廓,但图片的质量下降了很多,直到看起来像素化。加。图像背面还有另一个未知的白色层。

输出视频

示例代码:

C:\Users\Admin\Downloads\ffmpeg-20180102-57d0c24-win64-static\bin\ffmpeg -y -ss 0.0 -t 8.5 -i C:\Users\Admin\Desktop\test_movies\white.mp4 -i C:\Users\Admin\Desktop\test_movies\text_and_emoji.png -filter_complex [0:v]scale=640:640:force_original_aspect_ratio=decrease,pad=640:640:(ow-iw)/2:(oh-ih)/2:color=#00ffff[0v];[1:v]scale=480:120[1v];[0v][1v]overlay=(W-w)/2-(W/2-325.33328):(H-h)/2-(H/2-567.7075):alpha=premultiplied:enable='between(t,0.0,8.5)' -ac 2 -ar 44100 -vcodec libx264 C:\Users\Admin\Desktop\test_movies\test.mp4

最新编辑3:

按照@Mulvya的建议,我将他的代码与

alpha=premultiplied
结合起来,现在看起来好多了,有非常轻微的黑色轮廓(几乎不可见)

输出视频:

示例代码:

C:\Users\Admin\Downloads\ffmpeg-20180102-57d0c24-win64-static\bin\ffmpeg -y -ss 0.0 -t 8.5 -i C:\Users\Admin\Desktop\test_movies\white.mp4 -i C:\Users\Admin\Desktop\test_movies\text_and_emoji.png -filter_complex [0:v]setpts=PTS-STARTPTS,scale=640:640:force_original_aspect_ratio=decrease,pad=640:640:(ow-iw)/2:(oh-ih)/2:color=#18ffff[0v];[1:v]premultiply=inplace=1,scale=480:120[1v];[0v][1v]overlay=(W-w)/2-(W/2-325.33328):(H-h)/2-(H/2-567.7075):alpha=premultiplied:enable='between(t,0.0,8.5)':format=rgb,format=yuv420p -ac 2 -ar 44100 -vcodec libx264 C:\Users\Admin\Desktop\test_movies\test.mp4
ffmpeg outline
2个回答
1
投票

这是由于覆盖过滤器中的错误造成的,现已修复。将您的过滤器图表更改为此,

"[0:v]setpts=PTS-STARTPTS,scale=640:640:force_original_aspect_ratio=decrease,pad=640:640:(ow-iw)/2:(oh-ih)/2:color=#18ffff[0v];[1:v]premultiply=inplace=1,scale=556.24744:141.41884[1v];[0v][1v]overlay=(W-w)/2-(W/2-325.33328):(H-h)/2-(H/2-567.7075):enable='between(t,0.0,8.5)':format=rgb,format=yuv420p"

为此,您需要 2017 年 12 月 16 日之后的 FFmpeg 版本。


0
投票

我遇到这种情况是因为使用叠加滤镜时颜色定义丢失。

覆盖过滤器的默认格式是

yuv420

yuv420
格式会降低颜色清晰度,从而增加传输时间。将格式更改为
rgb
yuv444
将使用全色度修复出现的黑色轮廓问题。

YUV 是一种颜色空间,通常用作彩色图像管道的一部分。 它对彩色图像或视频进行编码,将人类的感知纳入其中 帐户,允许减少色度分量的带宽, 从而通常会导致传输错误或压缩 与人类感知相比,伪影更有效地被掩盖 使用“直接”RGB 表示。但是,YUV 4:2:2 和 YUV 4:2:0 子采样对色度信息的分辨率低于 亮度信息,导致颜色清晰度丢失。

© www.soinside.com 2019 - 2024. All rights reserved.