From 32a46076736cbcceae2c66d726d2d5f3b44869a4 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Wed, 11 Nov 2020 19:38:57 +0100 Subject: [PATCH] Fixed loading and playing of GIF animation --- MediaPlayer.cpp | 27 ++++++++++++++++++--------- MediaPlayer.h | 9 ++++++--- UserInterfaceManager.cpp | 31 ------------------------------- 3 files changed, 24 insertions(+), 43 deletions(-) diff --git a/MediaPlayer.cpp b/MediaPlayer.cpp index 18f34b1..a912609 100644 --- a/MediaPlayer.cpp +++ b/MediaPlayer.cpp @@ -138,14 +138,13 @@ static MediaInfo UriDiscoverer_(std::string uri) if ( !video_stream_info.isimage ) { video_stream_info.timeline.setEnd( gst_discoverer_info_get_duration (info) ); video_stream_info.seekable = gst_discoverer_info_get_seekable (info); - guint frn = gst_discoverer_video_info_get_framerate_num(vinfo); - guint frd = gst_discoverer_video_info_get_framerate_denom(vinfo); - if (frn == 0 || frd == 0) { - frn = 25; - frd = 1; + video_stream_info.framerate_n = gst_discoverer_video_info_get_framerate_num(vinfo); + video_stream_info.framerate_d = gst_discoverer_video_info_get_framerate_denom(vinfo); + if (video_stream_info.framerate_n == 0 || video_stream_info.framerate_d == 0) { + video_stream_info.framerate_n = 25; + video_stream_info.framerate_d = 1; } - video_stream_info.framerate = static_cast(frn) / static_cast(frd); - video_stream_info.timeline.setStep( (GST_SECOND * static_cast(frd)) / (static_cast(frn)) ); + video_stream_info.timeline.setStep( (GST_SECOND * static_cast(video_stream_info.framerate_d)) / (static_cast(video_stream_info.framerate_n)) ); } // try to fill-in the codec information GstCaps *caps = gst_discoverer_stream_info_get_caps (tmpinf); @@ -223,7 +222,17 @@ void MediaPlayer::execute_open() string description = "uridecodebin uri=" + uri_ + " ! "; if (media_.interlaced) description += "deinterlace method=2 ! "; - description += "videoconvert chroma-resampler=2 n-threads=2 ! appsink name=sink"; + description += "videoconvert chroma-resampler=2 n-threads=2 ! "; + + // hack to compensate for lack of PTS in gif animations + if (media_.codec_name.compare("image/gst-libav-gif") == 0){ + description += "videorate ! video/x-raw,framerate="; + description += std::to_string(media_.framerate_n) + "/"; + description += std::to_string(media_.framerate_d) + " ! "; + } + + // set app sink + description += "appsink name=sink"; // parse pipeline descriptor GError *error = NULL; @@ -938,7 +947,7 @@ std::string MediaPlayer::filename() const double MediaPlayer::frameRate() const { - return media_.framerate; + return static_cast(media_.framerate_n) / static_cast(media_.framerate_d);; } double MediaPlayer::updateFrameRate() const diff --git a/MediaPlayer.h b/MediaPlayer.h index 88d0694..232cd87 100644 --- a/MediaPlayer.h +++ b/MediaPlayer.h @@ -27,7 +27,8 @@ struct MediaInfo { guint par_width; // width to match pixel aspect ratio guint height; guint bitrate; - gdouble framerate; + guint framerate_n; + guint framerate_d; std::string codec_name; bool isimage; bool interlaced; @@ -38,7 +39,8 @@ struct MediaInfo { width = par_width = 640; height = 480; bitrate = 0; - framerate = 0.0; + framerate_n = 1; + framerate_d = 25; codec_name = "unknown"; isimage = false; interlaced = false; @@ -56,7 +58,8 @@ struct MediaInfo { this->par_width = b.par_width; this->height = b.height; this->bitrate = b.bitrate; - this->framerate = b.framerate; + this->framerate_n = b.framerate_n; + this->framerate_d = b.framerate_d; this->codec_name = b.codec_name; this->valid = b.valid; this->isimage = b.isimage; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 5f39d46..69085e6 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -707,23 +707,6 @@ void UserInterface::NewFrame() fileDialogPending_ = false; } } -// if (sessionFileDialogLoadFinished_) { -// sessionFileDialogLoadFinished_ = false; -// if (!sessionFileDialogFilename_.empty()) { -// if (sessionFileDialogImport_) -// Mixer::manager().import(sessionFileDialogFilename_); -// else -// Mixer::manager().open(sessionFileDialogFilename_); -// Settings::application.recentSessions.path = SystemToolkit::path_filename(sessionFileDialogFilename_); -// } -// } -// if (sessionFileDialogSaveFinished_) { -// sessionFileDialogSaveFinished_ = false; -// if (!sessionFileDialogFilename_.empty()) { -// Mixer::manager().saveas(sessionFileDialogFilename_); -// Settings::application.recentSessions.path = SystemToolkit::path_filename(sessionFileDialogFilename_); -// } -// } // overlay to ensure file dialog is modal if (fileDialogPending_){ @@ -741,20 +724,6 @@ void UserInterface::NewFrame() void UserInterface::Render() { -// ImVec2 geometry(static_cast(Rendering::manager().Width()), static_cast(Rendering::manager().Height())); -// // file modal dialog -// geometry.x *= 0.4f; -// geometry.y *= 0.4f; -// if ( !currentFileDialog.empty() && FileDialog::Instance()->Render(currentFileDialog.c_str(), geometry)) { -// if (FileDialog::Instance()->IsOk == true) { -// std::string filePathNameText = FileDialog::Instance()->GetFilepathName(); -// // done -// currentFileDialog = ""; -// } -// FileDialog::Instance()->CloseDialog(currentFileDialog.c_str()); -// } -// FileDialog::RenderCurrent(); - // warning modal dialog Log::Render();