]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/util.cpp
2.0 ffmper_producer: started refactoring into fix_meta_data method.
[casparcg] / modules / ffmpeg / producer / util.cpp
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