fix: FFmpeg mjpeg 缩略图/封面生成添加 format=yuvj420p #1330

Merged
xiaoxia merged 1 commits from fix/thumbnail-yuv-format into develop 2026-08-10 11:44:31 +08:00
5 changed files with 9 additions and 5 deletions
+3 -1
View File
@@ -215,7 +215,7 @@ class CoverService:
import subprocess
# scale + crop 实现 cover 裁剪
vf = f"scale={width}:{height}:force_original_aspect_ratio=increase," f"crop={width}:{height}"
vf = f"scale={width}:{height}:force_original_aspect_ratio=increase," f"crop={width}:{height},format=yuvj420p"
command = [
"ffmpeg",
@@ -258,6 +258,8 @@ class CoverService:
"1",
"-q:v",
str(quality),
"-pix_fmt",
"yuvj420p",
"-f",
"mjpeg",
str(output_path),
@@ -93,7 +93,7 @@ class CoverGenerator:
time_sec = 0
# scale + crop 实现 cover 裁剪(铺满输出尺寸)
vf = f"scale={width}:{height}:force_original_aspect_ratio=increase," f"crop={width}:{height}"
vf = f"scale={width}:{height}:force_original_aspect_ratio=increase," f"crop={width}:{height},format=yuvj420p"
command = [
FFMPEG_BIN,
@@ -281,7 +281,7 @@ class CoverGenerator:
output_path.parent.mkdir(parents=True, exist_ok=True)
# scale + crop 实现 cover 裁剪
vf = f"scale={width}:{height}:force_original_aspect_ratio=increase," f"crop={width}:{height}"
vf = f"scale={width}:{height}:force_original_aspect_ratio=increase," f"crop={width}:{height},format=yuvj420p"
command = [
FFMPEG_BIN,
+1 -1
View File
@@ -159,7 +159,7 @@ class VideoProcessor:
try:
(
ffmpeg.input(video_path, ss=timestamp)
.output(output_path, vframes=1, format="image2", vcodec="mjpeg")
.output(output_path, vframes=1, format="image2", vcodec="mjpeg", pix_fmt="yuvj420p")
.overwrite_output()
.run(capture_stdout=True, capture_stderr=True)
)
@@ -60,7 +60,7 @@ def extract_first_frame(
# -ss 放在 -i 前面(input seeking,更快但精度稍低,缩略图够用)
# -vframes 1 只取一帧
# -q:v 2 jpeg 高质量
scale_filter = f"scale={width}:{height}:force_original_aspect_ratio=decrease"
scale_filter = f"scale={width}:{height}:force_original_aspect_ratio=decrease,format=yuvj420p"
cmd = [
FFMPEG_BIN,
"-y",
@@ -157,6 +157,8 @@ class AssetAnalyzer:
"1",
"-q:v",
"2", # 高质量
"-pix_fmt",
"yuvj420p", # mjpeg 需要全范围 YUV
"-f",
"image2",
output_path,