]> git.sesse.net Git - casparcg/commitdiff
2.0 ffmper_producer: started refactoring into fix_meta_data method.
authorRonag <Ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 18 Aug 2011 21:50:25 +0000 (21:50 +0000)
committerRonag <Ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 18 Aug 2011 21:50:25 +0000 (21:50 +0000)
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
modules/ffmpeg/producer/util.h

index de20fe2efc8fa50edfd9777d9d0557583eecf299..e52997a3e5a74e1bafa2499ea37ba63f087d7b7e 100644 (file)
@@ -2,6 +2,8 @@
 \r
 #include "util.h"\r
 \r
+#include "format/flv.h"\r
+\r
 #include <tbb/concurrent_unordered_map.h>\r
 #include <tbb/concurrent_queue.h>\r
 \r
@@ -14,6 +16,9 @@
 \r
 #include <tbb/parallel_for.h>\r
 \r
+#include <boost/filesystem.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+\r
 #if defined(_MSC_VER)\r
 #pragma warning (push)\r
 #pragma warning (disable : 4244)\r
@@ -22,6 +27,7 @@ extern "C"
 {\r
        #include <libswscale/swscale.h>\r
        #include <libavcodec/avcodec.h>\r
+       #include <libavformat/avformat.h>\r
 }\r
 #if defined(_MSC_VER)\r
 #pragma warning (pop)\r
@@ -209,4 +215,49 @@ safe_ptr<core::write_frame> make_write_frame(const void* tag, const safe_ptr<AVF
        }\r
 }\r
 \r
+bool is_sane_frame_rate(AVRational time_base)\r
+{\r
+       return true;\r
+}\r
+\r
+//TODO: Not finished\r
+void fix_meta_data(AVFormatContext& context)\r
+{\r
+       auto video_index = av_find_best_stream(&context, AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0);\r
+       auto audio_index = av_find_best_stream(&context, AVMEDIA_TYPE_AUDIO, -1, -1, 0, 0);\r
+\r
+       if(video_index > -1)\r
+       {\r
+               auto& video_stream  = *context.streams[video_index];\r
+\r
+               if(video_stream.time_base.num == 1)\r
+                       video_stream.time_base.num = static_cast<int>(std::pow(10.0, static_cast<int>(std::log10(static_cast<float>(video_stream.time_base.den)))-1));  \r
+                                       \r
+               if(boost::filesystem2::path(context.filename).extension() == ".flv")\r
+               {\r
+                       try\r
+                       {\r
+                               //auto meta = read_flv_meta_info(context.filename);\r
+                               //fps_ = boost::lexical_cast<double>(meta["framerate"]);\r
+                               //video_stream.nb_frames = static_cast<int64_t>(boost::lexical_cast<double>(meta["duration"])*fps_);\r
+                       }\r
+                       catch(...){}\r
+               }\r
+               else\r
+               {\r
+                       if(video_stream.nb_frames == 0)\r
+                               video_stream.nb_frames = video_stream.duration;\r
+               }\r
+\r
+               if(!is_sane_frame_rate(video_stream.time_base))\r
+               {\r
+                       if(audio_index > -1)\r
+                       {\r
+                               video_stream.time_base.num = video_stream.nb_frames;\r
+                               video_stream.time_base.den = context.streams[audio_index]->duration / context.streams[audio_index]->codec->sample_rate;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
 }
\ No newline at end of file
index 4a09513213d017436d184a6bd0968044f4b88849..5d01bd195af09ff16d5fabe21610c148ffe930ad 100644 (file)
@@ -11,6 +11,7 @@ extern "C"
 }\r
 \r
 struct AVFrame;\r
+struct AVFormatContext;\r
 \r
 namespace caspar {\r
 \r
@@ -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.\r
 safe_ptr<core::write_frame> make_write_frame(const void* tag, const safe_ptr<AVFrame>& decoded_frame, const safe_ptr<core::frame_factory>& frame_factory, int hints);\r
 \r
+void                                           fix_meta_data(AVFormatContext& context);\r
+\r
 }
\ No newline at end of file