Write FFmpeg log output to our log file.
authorCarl Hetherington <cth@carlh.net>
Tue, 30 Jun 2015 10:09:34 +0000 (11:09 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 30 Jun 2015 10:09:34 +0000 (11:09 +0100)
ChangeLog
src/lib/ffmpeg.cc
src/lib/ffmpeg.h
src/lib/ffmpeg_examiner.h

index bcbcd9b1355c3e56420a3d25173f013e2637000a..d623af21756a1c5cf964dcc73a12a29d48749dc5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-30  c.hetherington  <cth@carlh.net>
+
+       * Write FFmpeg messages of AV_LOG_WARNING and
+       below to the project's log file.
+
 2015-06-29  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.1.12 released.
index f5d114e8f946c59cecbcc8e4efb72c31d1eccc5e..63fe9c9d8a3cc1aa5a86364593f84835db08ffee 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-extern "C" {
-#include <libavcodec/avcodec.h>
-#include <libavformat/avformat.h>
-#include <libswscale/swscale.h>
-}
 #include "ffmpeg.h"
 #include "ffmpeg_content.h"
+#include "film.h"
 #include "ffmpeg_audio_stream.h"
 #include "ffmpeg_subtitle_stream.h"
 #include "exceptions.h"
 #include "util.h"
 #include "raw_convert.h"
+#include "log.h"
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavformat/avformat.h>
+#include <libswscale/swscale.h>
+}
+#include <boost/algorithm/string.hpp>
 
 #include "i18n.h"
 
 using std::string;
 using std::cout;
+using std::cerr;
 using boost::shared_ptr;
 
 boost::mutex FFmpeg::_mutex;
+boost::weak_ptr<Log> FFmpeg::_ffmpeg_log;
 
 FFmpeg::FFmpeg (boost::shared_ptr<const FFmpegContent> c)
        : _ffmpeg_content (c)
@@ -75,11 +80,37 @@ avio_seek_wrapper (void* data, int64_t offset, int whence)
        return reinterpret_cast<FFmpeg*>(data)->avio_seek (offset, whence);
 }
 
+void
+FFmpeg::ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl)
+{
+       if (level > AV_LOG_WARNING) {
+               return;
+       }
+
+       char line[1024];
+       static int prefix = 0;
+       av_log_format_line (ptr, level, fmt, vl, line, sizeof (line), &prefix);
+       shared_ptr<Log> log = _ffmpeg_log.lock ();
+       if (log) {
+               string str (line);
+               boost::algorithm::trim (str);
+               log->log (String::compose ("FFmpeg: %1", str), Log::TYPE_GENERAL);
+       } else {
+               cerr << line;
+       }
+}
+
 void
 FFmpeg::setup_general ()
 {
        av_register_all ();
 
+       /* This might not work too well in some cases of multiple FFmpeg decoders,
+          but it's probably good enough.
+       */
+       _ffmpeg_log = _ffmpeg_content->film()->log ();
+       av_log_set_callback (FFmpeg::ffmpeg_log_callback);
+
        _file_group.set_paths (_ffmpeg_content->paths ());
        _avio_buffer = static_cast<uint8_t*> (wrapped_av_malloc (_avio_buffer_size));
        _avio_context = avio_alloc_context (_avio_buffer, _avio_buffer_size, 0, this, avio_read_wrapper, 0, avio_seek_wrapper);
index 4299edc28ffdddd273e37dbd9b2a3714467d507e..9e9d5125aa02ecb033df751b6b8a872e9a65e53c 100644 (file)
@@ -26,19 +26,13 @@ extern "C" {
 #include "file_group.h"
 #include <boost/shared_ptr.hpp>
 #include <boost/thread/mutex.hpp>
-#include <vector>
 
-struct AVFilterGraph;
-struct AVCodecContext;
-struct AVFilterContext;
 struct AVFormatContext;
 struct AVFrame;
-struct AVBufferContext;
-struct AVCodec;
-struct AVStream;
 struct AVIOContext;
 
 class FFmpegContent;
+class Log;
 
 class FFmpeg
 {
@@ -80,6 +74,9 @@ protected:
 private:
        void setup_general ();
        void setup_decoders ();
+
+       static void ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl);
+       static boost::weak_ptr<Log> _ffmpeg_log;
 };
 
 #endif
index f2bdea0c29374495107a14103e10066c0defa64d..f5ee95acfe82e10a956df807186646d6fcbf317a 100644 (file)
@@ -21,6 +21,8 @@
 #include "video_examiner.h"
 #include <boost/optional.hpp>
 
+class AVStream;
+
 class FFmpegAudioStream;
 class FFmpegSubtitleStream;