diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-06-30 11:09:34 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-06-30 11:09:34 +0100 |
| commit | 937240f9e360e434b36c418656ae6fe8cc6afea9 (patch) | |
| tree | b2af5fe0116bcbbdc7f3d1959662970ba1cef560 /src/lib/ffmpeg.cc | |
| parent | 78bc6f9286864052b304a1871739479c16e393dd (diff) | |
Write FFmpeg log output to our log file.
Diffstat (limited to 'src/lib/ffmpeg.cc')
| -rw-r--r-- | src/lib/ffmpeg.cc | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index f5d114e8f..63fe9c9d8 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -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 @@ -17,26 +17,31 @@ */ -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) @@ -76,10 +81,36 @@ avio_seek_wrapper (void* data, int64_t offset, int 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); |
