From 2c13cc9a565bff4718f0053e36f9c49f2dd3f90a Mon Sep 17 00:00:00 2001 From: Ronag Date: Thu, 18 Aug 2011 21:50:25 +0000 Subject: [PATCH] 2.0 ffmper_producer: started refactoring into fix_meta_data method. git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@1220 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d --- modules/ffmpeg/producer/util.cpp | 51 ++++++++++++++++++++++++++++++++ modules/ffmpeg/producer/util.h | 3 ++ 2 files changed, 54 insertions(+) diff --git a/modules/ffmpeg/producer/util.cpp b/modules/ffmpeg/producer/util.cpp index de20fe2ef..e52997a3e 100644 --- a/modules/ffmpeg/producer/util.cpp +++ b/modules/ffmpeg/producer/util.cpp @@ -2,6 +2,8 @@ #include "util.h" +#include "format/flv.h" + #include #include @@ -14,6 +16,9 @@ #include +#include +#include + #if defined(_MSC_VER) #pragma warning (push) #pragma warning (disable : 4244) @@ -22,6 +27,7 @@ extern "C" { #include #include + #include } #if defined(_MSC_VER) #pragma warning (pop) @@ -209,4 +215,49 @@ safe_ptr make_write_frame(const void* tag, const safe_ptr -1) + { + auto& video_stream = *context.streams[video_index]; + + if(video_stream.time_base.num == 1) + video_stream.time_base.num = static_cast(std::pow(10.0, static_cast(std::log10(static_cast(video_stream.time_base.den)))-1)); + + if(boost::filesystem2::path(context.filename).extension() == ".flv") + { + try + { + //auto meta = read_flv_meta_info(context.filename); + //fps_ = boost::lexical_cast(meta["framerate"]); + //video_stream.nb_frames = static_cast(boost::lexical_cast(meta["duration"])*fps_); + } + catch(...){} + } + else + { + if(video_stream.nb_frames == 0) + video_stream.nb_frames = video_stream.duration; + } + + if(!is_sane_frame_rate(video_stream.time_base)) + { + if(audio_index > -1) + { + video_stream.time_base.num = video_stream.nb_frames; + video_stream.time_base.den = context.streams[audio_index]->duration / context.streams[audio_index]->codec->sample_rate; + } + } + } +} + } \ No newline at end of file diff --git a/modules/ffmpeg/producer/util.h b/modules/ffmpeg/producer/util.h index 4a0951321..5d01bd195 100644 --- a/modules/ffmpeg/producer/util.h +++ b/modules/ffmpeg/producer/util.h @@ -11,6 +11,7 @@ extern "C" } struct AVFrame; +struct AVFormatContext; namespace caspar { @@ -30,4 +31,6 @@ core::pixel_format_desc get_pixel_format_desc(PixelFormat pix_fmt, size_t width int make_alpha_format(int format); // NOTE: Be careful about CASPAR_PIX_FMT_LUMA, change it to PIX_FMT_GRAY8 if you want to use the frame inside some ffmpeg function. safe_ptr make_write_frame(const void* tag, const safe_ptr& decoded_frame, const safe_ptr& frame_factory, int hints); +void fix_meta_data(AVFormatContext& context); + } \ No newline at end of file -- 2.39.2