diff --git a/aegisub/src/include/aegisub/video_provider.h b/aegisub/src/include/aegisub/video_provider.h index e82ae0479..c5db29f9e 100644 --- a/aegisub/src/include/aegisub/video_provider.h +++ b/aegisub/src/include/aegisub/video_provider.h @@ -64,6 +64,10 @@ public: virtual agi::vfr::Framerate GetFPS() const=0; ///< Get frame rate virtual std::vector GetKeyFrames() const=0;///< Returns list of keyframes + /// Get the source colorspace of the video before it was converted to RGB + /// @return A string describing the source colorspace or empty if it is + /// unknown or meaningless + virtual wxString GetColorSpace() const { return ""; } /// @brief Use this to set any post-loading warnings, such as "being loaded with unreliable seeking" virtual wxString GetWarning() const { return ""; } diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 58d137078..85c89da6e 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -252,6 +252,7 @@ void VideoContext::OnSubtitlesCommit() { void VideoContext::OnSubtitlesSave() { if (!IsLoaded()) { context->ass->SetScriptInfo("Video File", ""); + context->ass->SetScriptInfo("Video Colorspace", ""); context->ass->SetScriptInfo("Video Aspect Ratio", ""); context->ass->SetScriptInfo("Video Position", ""); context->ass->SetScriptInfo("VFR File", ""); @@ -266,6 +267,7 @@ void VideoContext::OnSubtitlesSave() { ar = wxString::Format("%d", arType); context->ass->SetScriptInfo("Video File", MakeRelativePath(videoFile, context->ass->filename)); + context->ass->SetScriptInfo("Video Colorspace", videoProvider->GetColorSpace()); context->ass->SetScriptInfo("Video Aspect Ratio", ar); context->ass->SetScriptInfo("Video Position", wxString::Format("%d", frame_n)); context->ass->SetScriptInfo("VFR File", MakeRelativePath(GetTimecodesName(), context->ass->filename)); diff --git a/aegisub/src/video_provider_cache.h b/aegisub/src/video_provider_cache.h index 98962cd33..3956c2d29 100644 --- a/aegisub/src/video_provider_cache.h +++ b/aegisub/src/video_provider_cache.h @@ -71,12 +71,13 @@ public: virtual ~VideoProviderCache(); // Override the following methods: - virtual int GetPosition() const { return master->GetPosition(); } - virtual int GetFrameCount() const { return master->GetFrameCount(); } - virtual int GetWidth() const { return master->GetWidth(); } - virtual int GetHeight() const { return master->GetHeight(); } - virtual agi::vfr::Framerate GetFPS() const { return master->GetFPS(); } - virtual std::vector GetKeyFrames() const { return master->GetKeyFrames(); } - virtual wxString GetWarning() const { return master->GetWarning(); } - virtual wxString GetDecoderName() const { return master->GetDecoderName(); } + int GetPosition() const { return master->GetPosition(); } + int GetFrameCount() const { return master->GetFrameCount(); } + int GetWidth() const { return master->GetWidth(); } + int GetHeight() const { return master->GetHeight(); } + agi::vfr::Framerate GetFPS() const { return master->GetFPS(); } + std::vector GetKeyFrames() const { return master->GetKeyFrames(); } + wxString GetWarning() const { return master->GetWarning(); } + wxString GetDecoderName() const { return master->GetDecoderName(); } + wxString GetColorSpace() const { return master->GetColorSpace(); } }; diff --git a/aegisub/src/video_provider_ffmpegsource.cpp b/aegisub/src/video_provider_ffmpegsource.cpp index 045bc59db..7bf156bb1 100644 --- a/aegisub/src/video_provider_ffmpegsource.cpp +++ b/aegisub/src/video_provider_ffmpegsource.cpp @@ -223,6 +223,14 @@ void FFmpegSourceVideoProvider::LoadVideo(wxString filename) { Width = TempFrame->EncodedWidth; Height = TempFrame->EncodedHeight; + switch (TempFrame->ColorSpace) { + case FFMS_CS_RGB: ColorSpace = "RGB"; break; + case FFMS_CS_BT709: ColorSpace = "BT.709"; break; + case FFMS_CS_BT470BG: ColorSpace = "BT.601"; break; + case FFMS_CS_UNSPECIFIED: ColorSpace = Width > 1024 || Height >= 600 ? "BT.709" : "BT.601"; break; + default: ColorSpace = ""; break; + } + #if FFMS_VERSION >= ((2 << 24) | (15 << 16) | (3 << 8) | 0) const int TargetFormat[] = { FFMS_GetPixFmt("bgra"), -1 }; if (FFMS_SetOutputFormatV2(VideoSource, TargetFormat, Width, Height, FFMS_RESIZER_BICUBIC, &ErrInfo)) { @@ -266,8 +274,6 @@ void FFmpegSourceVideoProvider::LoadVideo(wxString filename) { FrameNumber = 0; } -/// @brief Close video -/// void FFmpegSourceVideoProvider::Close() { if (VideoSource) FFMS_DestroyVideoSource(VideoSource); #ifdef WIN32 @@ -276,10 +282,6 @@ void FFmpegSourceVideoProvider::Close() { #endif } -/// @brief Get frame -/// @param _n -/// @return -/// const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int n) { FrameNumber = mid(0, n, GetFrameCount() - 1); @@ -292,4 +294,5 @@ const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int n) { CurFrame.SetTo(SrcFrame->Data[0], Width, Height, SrcFrame->Linesize[0]); return CurFrame; } + #endif /* WITH_FFMS2 */ diff --git a/aegisub/src/video_provider_ffmpegsource.h b/aegisub/src/video_provider_ffmpegsource.h index 4d5b61177..ad40d07b6 100644 --- a/aegisub/src/video_provider_ffmpegsource.h +++ b/aegisub/src/video_provider_ffmpegsource.h @@ -46,21 +46,21 @@ /// @class FFmpegSourceVideoProvider /// @brief Implements video loading through the FFMS library. class FFmpegSourceVideoProvider : public VideoProvider, FFmpegSourceProvider { -private: - FFMS_VideoSource *VideoSource; /// video source object - const FFMS_VideoProperties *VideoInfo; /// video properties + FFMS_VideoSource *VideoSource; ///< video source object + const FFMS_VideoProperties *VideoInfo; ///< video properties - int Width; /// width in pixels - int Height; /// height in pixels - int FrameNumber; /// current framenumber - std::vector KeyFramesList; /// list of keyframes - agi::vfr::Framerate Timecodes; /// vfr object - bool COMInited; /// COM initialization state - - AegiVideoFrame CurFrame; /// current video frame - - char FFMSErrMsg[1024]; /// FFMS error message - FFMS_ErrorInfo ErrInfo; /// FFMS error codes/messages + int Width; ///< width in pixels + int Height; ///< height in pixels + int FrameNumber; ///< current framenumber + std::vector KeyFramesList; ///< list of keyframes + agi::vfr::Framerate Timecodes; ///< vfr object + bool COMInited; ///< COM initialization state + wxString ColorSpace; ///< Colorspace name + + AegiVideoFrame CurFrame; ///< current video frame + + char FFMSErrMsg[1024]; ///< FFMS error message + FFMS_ErrorInfo ErrInfo; ///< FFMS error codes/messages void LoadVideo(wxString filename); void Close(); @@ -77,6 +77,8 @@ public: int GetHeight() const { return Height; } agi::vfr::Framerate GetFPS() const { return Timecodes; } + wxString GetColorSpace() const { return ColorSpace; } + /// @brief Gets a list of keyframes /// @return Returns a wxArrayInt of keyframes. std::vector GetKeyFrames() const { return KeyFramesList; };