Skip to content

Commit

Permalink
Shorten encoder pix_fmt logic
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Sep 18, 2023
1 parent af46768 commit 0219e0f
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 200 deletions.
7 changes: 2 additions & 5 deletions auto_editor/render/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ def render_av(

apply_video_later = True

if args.video_codec in encoders:
apply_video_later = encoders[args.video_codec]["pix_fmt"].isdisjoint(
allowed_pix_fmt
)

if args.scale != 1:
apply_video_later = False
elif args.video_codec in encoders:
apply_video_later = set(encoders[args.video_codec]).isdisjoint(allowed_pix_fmt)

log.debug(f"apply video quality settings now: {not apply_video_later}")

Expand Down
328 changes: 133 additions & 195 deletions auto_editor/utils/encoder.py
Original file line number Diff line number Diff line change
@@ -1,197 +1,135 @@
encoders = {
"libx264": {
"pix_fmt": {
"yuv420p",
"yuvj420p",
"yuv422p",
"yuvj422p",
"yuv444p",
"yuvj444p",
"nv12",
"nv16",
"nv21",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"nv20le",
"gray",
"gray10le",
},
},
"libx264rgb": {
"pix_fmt": {"bgr0", "bgr24", "rgb24"},
},
"h264_videotoolbox": {
"pix_fmt": {"videotoolbox_vld", "nv12", "yuv420p"},
},
"h264": {
"pix_fmt": {"videotoolbox_vld", "nv12", "yuv420p"},
},
"libx265": {
"pix_fmt": {
"yuv420p",
"yuvj420p",
"yuv422p",
"yuvj422p",
"yuv444p",
"yuvj444p",
"gbrp",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"gbrp10le",
"yuv420p12le",
"yuv422p12le",
"yuv444p12le",
"gbrp12le",
"gray",
"gray10le",
"gray12le",
},
},
"hevc_videotoolbox": {
"pix_fmt": {"videotoolbox_vld", "nv12", "yuv420p", "bgra", "p010le"},
},
"hevc": {
"pix_fmt": {
"yuv420p",
"yuvj420p",
"yuv422p",
"yuvj422p",
"yuv444p",
"yuvj444p",
"gbrp",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"gbrp10le",
"yuv420p12le",
"yuv422p12le",
"yuv444p12le",
"gbrp12le",
"gray",
"gray10le",
"gray12le",
},
},
"hevc_nvenc": {
"pix_fmt": {
"yuv420p",
"nv12",
"p010le",
"yuv444p",
"p016le",
"yuv444p16le",
"bgr0",
"rgb0",
"gbrp",
"gbrp16le",
"cuda",
"d3d11",
},
},
"hevc_amf": {
"pix_fmt": {
"yuv420p",
"nv12",
"d3d11",
"dxva2_vld",
},
},
"h264_nvenc": {
"pix_fmt": {
"yuv420p",
"nv12",
"p010le",
"yuv444p",
"p016le",
"yuv444p16le",
"bgr0",
"rgb0",
"gbrp",
"gbrp16le",
"cuda",
"d3d11",
},
},
"h264_amf": {
"pix_fmt": {
"yuv420p",
"nv12",
"d3d11",
"dxva2_vld",
},
},
"hevc_qsv": {
"pix_fmt": {
"nv12",
"p010le",
"yuyv422",
"y210le",
"qsv",
"bgra",
"x2rgb10le",
},
},
"h264_qsv": {
"pix_fmt": {
"nv12",
"p010le",
"qsv",
},
},
"vp9": {
"pix_fmt": {
"yuv420p",
"yuva420p",
"yuv422p",
"yuv440p",
"yuv444p",
"yuv420p10le",
"yuv422p10le",
"yuv440p10le",
"yuv444p10le",
"yuv420p12le",
"yuv422p12le",
"yuv440p12le",
"yuv444p12le",
"gbrp",
"gbrp10le",
"gbrp12le",
},
},
"vp8": {
"pix_fmt": {"yuv420p", "yuva420p"},
},
"prores": {
"pix_fmt": {"yuv422p10le", "yuv444p10le", "yuva444p10le"},
},
"av1": {
"pix_fmt": {
"yuv420p",
"yuv422p",
"yuv444p",
"gbrp",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"yuv420p12le",
"yuv422p12le",
"yuv444p12le",
"gbrp10le",
"gbrp12le",
"gray",
"gray10le",
"gray12le",
},
},
"mpeg4": {
"pix_fmt": {"yuv420p"},
},
"mpeg2video": {
"pix_fmt": {"yuv420p", "yuv422p"},
},
"mjpeg": {
"pix_fmt": {"yuvj420p", "yuvj422p", "yuvj444p"},
},
"libx264": (
"yuv420p",
"yuvj420p",
"yuv422p",
"yuvj422p",
"yuv444p",
"yuvj444p",
"nv12",
"nv16",
"nv21",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"nv20le",
"gray",
"gray10le",
),
"libx264rgb": ("bgr0", "bgr24", "rgb24"),
"h264_videotoolbox": ("videotoolbox_vld", "nv12", "yuv420p"),
"h264": ("videotoolbox_vld", "nv12", "yuv420p"),
"libx265": (
"yuv420p",
"yuvj420p",
"yuv422p",
"yuvj422p",
"yuv444p",
"yuvj444p",
"gbrp",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"gbrp10le",
"yuv420p12le",
"yuv422p12le",
"yuv444p12le",
"gbrp12le",
"gray",
"gray10le",
"gray12le",
),
"hevc_videotoolbox": ("videotoolbox_vld", "nv12", "yuv420p", "bgra", "p010le"),
"hevc": (
"yuv420p",
"yuvj420p",
"yuv422p",
"yuvj422p",
"yuv444p",
"yuvj444p",
"gbrp",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"gbrp10le",
"yuv420p12le",
"yuv422p12le",
"yuv444p12le",
"gbrp12le",
"gray",
"gray10le",
"gray12le",
),
"hevc_nvenc": (
"yuv420p",
"nv12",
"p010le",
"yuv444p",
"p016le",
"yuv444p16le",
"bgr0",
"rgb0",
"gbrp",
"gbrp16le",
"cuda",
"d3d11",
),
"hevc_amf": ("yuv420p", "nv12", "d3d11", "dxva2_vld"),
"h264_nvenc": (
"yuv420p",
"nv12",
"p010le",
"yuv444p",
"p016le",
"yuv444p16le",
"bgr0",
"rgb0",
"gbrp",
"gbrp16le",
"cuda",
"d3d11",
),
"h264_amf": ("yuv420p", "nv12", "d3d11", "dxva2_vld"),
"hevc_qsv": ("nv12", "p010le", "yuyv422", "y210le", "qsv", "bgra", "x2rgb10le"),
"h264_qsv": ("nv12", "p010le", "qsv"),
"vp9": (
"yuv420p",
"yuva420p",
"yuv422p",
"yuv440p",
"yuv444p",
"yuv420p10le",
"yuv422p10le",
"yuv440p10le",
"yuv444p10le",
"yuv420p12le",
"yuv422p12le",
"yuv440p12le",
"yuv444p12le",
"gbrp",
"gbrp10le",
"gbrp12le",
),
"vp8": ("yuv420p", "yuva420p"),
"prores": ("yuv422p10le", "yuv444p10le", "yuva444p10le"),
"av1": (
"yuv420p",
"yuv422p",
"yuv444p",
"gbrp",
"yuv420p10le",
"yuv422p10le",
"yuv444p10le",
"yuv420p12le",
"yuv422p12le",
"yuv444p12le",
"gbrp10le",
"gbrp12le",
"gray",
"gray10le",
"gray12le",
),
"mpeg4": ("yuv420p"),
"mpeg2video": ("yuv420p", "yuv422p"),
"mjpeg": ("yuvj420p", "yuvj422p", "yuvj444p"),
}

0 comments on commit 0219e0f

Please sign in to comment.