diff --git a/aegisub/src/include/aegisub/video_provider.h b/aegisub/src/include/aegisub/video_provider.h index de9599d57..7b6570af4 100644 --- a/aegisub/src/include/aegisub/video_provider.h +++ b/aegisub/src/include/aegisub/video_provider.h @@ -60,6 +60,7 @@ public: virtual int GetFrameCount() const=0; ///< Get total number of frames virtual int GetWidth() const=0; ///< Returns the video width in pixels virtual int GetHeight() const=0; ///< Returns the video height in pixels + virtual double GetDAR() const=0; ///< Returns the video display aspect ratio virtual agi::vfr::Framerate GetFPS() const=0; ///< Get frame rate virtual std::vector GetKeyFrames() const=0;///< Returns list of keyframes diff --git a/aegisub/src/video_context.cpp b/aegisub/src/video_context.cpp index 51d3cfd5e..8d6e8897c 100644 --- a/aegisub/src/video_context.cpp +++ b/aegisub/src/video_context.cpp @@ -186,6 +186,11 @@ void VideoContext::SetVideo(const wxString &filename) { } } + // Set aspect ratio + double dar = videoProvider->GetDAR(); + if (dar > 0) + SetAspectRatio(4, dar); + // Set filename config::mru->Add("Video", STD_STR(filename)); StandardPaths::SetPathValue("?video", wxFileName(filename).GetPath()); diff --git a/aegisub/src/video_provider_avs.h b/aegisub/src/video_provider_avs.h index 8353435dc..08dfd465e 100644 --- a/aegisub/src/video_provider_avs.h +++ b/aegisub/src/video_provider_avs.h @@ -70,6 +70,7 @@ public: agi::vfr::Framerate GetFPS() const { return fps; }; int GetWidth() const { return vi.width; }; int GetHeight() const { return vi.height; }; + double GetDAR() const { return 0; } std::vector GetKeyFrames() const { return KeyFrames; }; wxString GetWarning() const { return warning; } wxString GetDecoderName() const { return decoderName; } diff --git a/aegisub/src/video_provider_cache.h b/aegisub/src/video_provider_cache.h index 387a495fe..d05a8805b 100644 --- a/aegisub/src/video_provider_cache.h +++ b/aegisub/src/video_provider_cache.h @@ -68,6 +68,7 @@ public: int GetFrameCount() const { return master->GetFrameCount(); } int GetWidth() const { return master->GetWidth(); } int GetHeight() const { return master->GetHeight(); } + double GetDAR() const { return master->GetDAR(); } agi::vfr::Framerate GetFPS() const { return master->GetFPS(); } std::vector GetKeyFrames() const { return master->GetKeyFrames(); } wxString GetWarning() const { return master->GetWarning(); } diff --git a/aegisub/src/video_provider_dummy.h b/aegisub/src/video_provider_dummy.h index 7871c732b..c586865c3 100644 --- a/aegisub/src/video_provider_dummy.h +++ b/aegisub/src/video_provider_dummy.h @@ -88,6 +88,7 @@ public: int GetFrameCount() const { return framecount; } int GetWidth() const { return width; } int GetHeight() const { return height; } + double GetDAR() const { return 0; } agi::vfr::Framerate GetFPS() const { return fps; } std::vector GetKeyFrames() const { return std::vector(); }; wxString GetDecoderName() const { return "Dummy Video Provider"; } diff --git a/aegisub/src/video_provider_ffmpegsource.cpp b/aegisub/src/video_provider_ffmpegsource.cpp index 966291254..1cfc2d49d 100644 --- a/aegisub/src/video_provider_ffmpegsource.cpp +++ b/aegisub/src/video_provider_ffmpegsource.cpp @@ -167,11 +167,15 @@ void FFmpegSourceVideoProvider::LoadVideo(wxString filename) { VideoInfo = FFMS_GetVideoProperties(VideoSource); const FFMS_Frame *TempFrame = FFMS_GetFrame(VideoSource, 0, &ErrInfo); - if (TempFrame == NULL) { + if (!TempFrame) throw VideoOpenError(std::string("Failed to decode first frame: ") + ErrInfo.Buffer); - } - Width = TempFrame->EncodedWidth; - Height = TempFrame->EncodedHeight; + + Width = TempFrame->EncodedWidth; + Height = TempFrame->EncodedHeight; + if (VideoInfo->SARDen > 0 && VideoInfo->SARNum > 0) + DAR = double(Width * VideoInfo->SARNum) / (Height * VideoInfo->SARDen); + else + DAR = double(Width) / Height; switch (TempFrame->ColorSpace) { case FFMS_CS_RGB: ColorSpace = "RGB"; break; diff --git a/aegisub/src/video_provider_ffmpegsource.h b/aegisub/src/video_provider_ffmpegsource.h index a19c4cfb0..f6ea22865 100644 --- a/aegisub/src/video_provider_ffmpegsource.h +++ b/aegisub/src/video_provider_ffmpegsource.h @@ -52,6 +52,7 @@ class FFmpegSourceVideoProvider : public VideoProvider, FFmpegSourceProvider { int Width; ///< width in pixels int Height; ///< height in pixels + double DAR; ///< display aspect ratio int FrameNumber; ///< current framenumber std::vector KeyFramesList; ///< list of keyframes agi::vfr::Framerate Timecodes; ///< vfr object @@ -72,6 +73,7 @@ public: int GetFrameCount() const { return VideoInfo->NumFrames; } int GetWidth() const { return Width; } int GetHeight() const { return Height; } + double GetDAR() const { return DAR; } agi::vfr::Framerate GetFPS() const { return Timecodes; } wxString GetColorSpace() const { return ColorSpace; } diff --git a/aegisub/src/video_provider_yuv4mpeg.h b/aegisub/src/video_provider_yuv4mpeg.h index 9df68903e..afe989497 100644 --- a/aegisub/src/video_provider_yuv4mpeg.h +++ b/aegisub/src/video_provider_yuv4mpeg.h @@ -146,6 +146,7 @@ public: int GetFrameCount() const { return num_frames; } int GetWidth() const { return w; } int GetHeight() const { return h; } + double GetDAR() const { return 0; } agi::vfr::Framerate GetFPS() const { return fps; } std::vector GetKeyFrames() const { return std::vector(); }; wxString GetDecoderName() const { return "YU4MPEG"; };