From f2415a4d658b90302d77c87e88aea1d0a912682d Mon Sep 17 00:00:00 2001 From: Karl Blomster Date: Wed, 24 Jun 2009 17:43:36 +0000 Subject: [PATCH] Implement timestamp reading from the container in the ffmpeg video provider. Updates #864. Originally committed to SVN as r3083. --- aegisub/src/video_provider_lavc.cpp | 19 +++++++++++++++++++ aegisub/src/video_provider_lavc.h | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/aegisub/src/video_provider_lavc.cpp b/aegisub/src/video_provider_lavc.cpp index 283e58876..dc9f45653 100644 --- a/aegisub/src/video_provider_lavc.cpp +++ b/aegisub/src/video_provider_lavc.cpp @@ -137,6 +137,25 @@ void LAVCVideoProvider::LoadVideo(Aegisub::String filename, double fps) { length = LAVCFrameData.GetNumFrames(); framesData = LAVCFrameData.GetFrameData(); + std::vector timecodesVector; + for (int i = 0; i < length; i++) { + int timestamp = (int)((framesData[i].DTS * (int64_t)lavcfile->fctx->streams[vidStream]->time_base.num * 1000) + / (int64_t)lavcfile->fctx->streams[vidStream]->time_base.den); + timecodesVector.push_back(timestamp); + } + timecodes.SetVFR(timecodesVector); + int OverrideTC = wxYES; + if (VFR_Output.IsLoaded()) { + OverrideTC = wxMessageBox(_("You already have timecodes loaded. Would you like to replace them with timecodes from the video file?"), _("Replace timecodes?"), wxYES_NO | wxICON_QUESTION); + if (OverrideTC == wxYES) { + VFR_Input.SetVFR(timecodesVector); + VFR_Output.SetVFR(timecodesVector); + } + } else { // no timecodes loaded, go ahead and apply + VFR_Input.SetVFR(timecodesVector); + VFR_Output.SetVFR(timecodesVector); + } + // Allocate frame frame = avcodec_alloc_frame(); diff --git a/aegisub/src/video_provider_lavc.h b/aegisub/src/video_provider_lavc.h index fd6f7369a..40050058d 100644 --- a/aegisub/src/video_provider_lavc.h +++ b/aegisub/src/video_provider_lavc.h @@ -91,6 +91,7 @@ private: AegiVideoFrame curFrame; bool validFrame; LAVCFrameInfoVector framesData; + FrameRate timecodes; uint8_t *buffer1; uint8_t *buffer2; @@ -119,8 +120,8 @@ public: double GetFPS(); bool AreKeyFramesLoaded() { return keyFramesLoaded; }; wxArrayInt GetKeyFrames() { return KeyFramesList; }; - bool IsVFR() { return false; }; // FIXME: bork? - FrameRate GetTrueFrameRate() { return FrameRate(); }; // nothing useful here + bool IsVFR() { return true; }; + FrameRate GetTrueFrameRate() { return timecodes; }; Aegisub::String GetDecoderName() { return L"FFMpeg/libavcodec"; } bool IsNativelyByFrames() { return true; } int GetDesiredCacheSize() { return 8; }