From eceac482d06e3c82ce21068730197fa5423102b3 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 16 Apr 2012 23:55:15 +0000 Subject: [PATCH] Add BT.601/BT.709 guessing to the Avisynth video provider along with support for Force BT.601 Originally committed to SVN as r6707. --- aegisub/src/video_provider_avs.cpp | 29 ++++++++++++++++++++++++++--- aegisub/src/video_provider_avs.h | 2 ++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/aegisub/src/video_provider_avs.cpp b/aegisub/src/video_provider_avs.cpp index e2737faad..34ca006d2 100644 --- a/aegisub/src/video_provider_avs.cpp +++ b/aegisub/src/video_provider_avs.cpp @@ -38,6 +38,8 @@ #ifdef WITH_AVISYNTH +#include "video_provider_avs.h" + #ifndef AGI_PRE #include #include @@ -47,11 +49,12 @@ #include #endif +#include + #include "charset_conv.h" #include "compat.h" -#include +#include "main.h" #include "standard_paths.h" -#include "video_provider_avs.h" AvisynthVideoProvider::AvisynthVideoProvider(wxString filename) : last_fnum(-1) @@ -152,7 +155,27 @@ file_exit: if (!script.IsClip() || !script.AsClip()->GetVideoInfo().HasVideo()) throw VideoNotSupported("No usable video found"); - RGB32Video = (avs.GetEnv()->Invoke("Cache", avs.GetEnv()->Invoke("ConvertToRGB32", script))).AsClip(); + vi = script.AsClip()->GetVideoInfo(); + if (!vi.IsRGB()) { + /// @todo maybe read ColorMatrix hints for d2v files? + + AVSValue args[2] = { script, "Rec601" }; + if (!OPT_GET("Provider/Video/FFmpegSource/Force BT.601")->GetBool() && (vi.width > 1024 || vi.height >= 600)) { + args[1] = "Rec709"; + colorspace = "BT.709"; + } + else + colorspace = "BT.601"; + const char *argnames[2] = { 0, "matrix" }; + script = avs.GetEnv()->Invoke("ConvertToRGB32", AVSValue(args, 2), argnames); + } + else if (extension != ".avs") + colorspace = "RGB"; + // Don't set the colorspace to RGB if we're opening an Avisynth script + // as we can't tell RGB source video apart from a script that happens + // to convert to rgb + + RGB32Video = avs.GetEnv()->Invoke("Cache", script).AsClip(); vi = RGB32Video->GetVideoInfo(); fps = (double)vi.fps_numerator / vi.fps_denominator; } diff --git a/aegisub/src/video_provider_avs.h b/aegisub/src/video_provider_avs.h index 08dfd465e..636664b45 100644 --- a/aegisub/src/video_provider_avs.h +++ b/aegisub/src/video_provider_avs.h @@ -52,6 +52,7 @@ class AvisynthVideoProvider: public VideoProvider { agi::vfr::Framerate fps; std::vector KeyFrames; wxString warning; + wxString colorspace; PClip RGB32Video; VideoInfo vi; @@ -74,5 +75,6 @@ public: std::vector GetKeyFrames() const { return KeyFrames; }; wxString GetWarning() const { return warning; } wxString GetDecoderName() const { return decoderName; } + wxString GetColorSpace() const { return colorspace; } }; #endif