From 35409488fd54aacefa6858dce4b02a576170e76e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 26 Jul 2020 02:27:12 +0200 Subject: [PATCH] Ignore FFmpeg warnings in a nicer way. --- src/lib/ffmpeg.cc | 8 ++++++++ src/lib/ffmpeg.h | 3 +++ src/lib/ffmpeg_decoder.cc | 10 ++++++++++ src/lib/ffmpeg_examiner.cc | 28 ++++++++++++++++++++++------ src/lib/ffmpeg_file_encoder.cc | 10 ++++++++++ src/lib/ffmpeg_image_proxy.cc | 5 ++++- src/lib/util.cc | 3 +++ src/lib/video_filter_graph.cc | 7 +++++-- 8 files changed, 65 insertions(+), 9 deletions(-) diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc index 8eb19816c..0802fa159 100644 --- a/src/lib/ffmpeg.cc +++ b/src/lib/ffmpeg.cc @@ -70,9 +70,11 @@ FFmpeg::~FFmpeg () { boost::mutex::scoped_lock lm (_mutex); +DCPOMATIC_DISABLE_WARNINGS for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { avcodec_close (_format_context->streams[i]->codec); } +DCPOMATIC_ENABLE_WARNINGS av_frame_free (&_frame); avformat_close_input (&_format_context); @@ -146,6 +148,7 @@ FFmpeg::setup_general () optional video_stream_undefined_frame_rate; +DCPOMATIC_DISABLE_WARNINGS for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { AVStream* s = _format_context->streams[i]; if (s->codec->codec_type == AVMEDIA_TYPE_VIDEO && avcodec_find_decoder(s->codec->codec_id)) { @@ -158,6 +161,7 @@ FFmpeg::setup_general () } } } +DCPOMATIC_ENABLE_WARNINGS /* Files from iTunes sometimes have two video streams, one with the avg_frame_rate.num and .den set to zero. Only use such a stream if there is no alternative. @@ -204,6 +208,7 @@ FFmpeg::setup_decoders () { boost::mutex::scoped_lock lm (_mutex); +DCPOMATIC_DISABLE_WARNINGS for (uint32_t i = 0; i < _format_context->nb_streams; ++i) { AVCodecContext* context = _format_context->streams[i]->codec; @@ -230,8 +235,10 @@ FFmpeg::setup_decoders () dcpomatic_log->log (String::compose ("No codec found for stream %1", i), LogEntry::TYPE_WARNING); } } +DCPOMATIC_ENABLE_WARNINGS } +DCPOMATIC_DISABLE_WARNINGS AVCodecContext * FFmpeg::video_codec_context () const { @@ -251,6 +258,7 @@ FFmpeg::subtitle_codec_context () const return _ffmpeg_content->subtitle_stream()->stream(_format_context)->codec; } +DCPOMATIC_ENABLE_WARNINGS int FFmpeg::avio_read (uint8_t* buffer, int const amount) diff --git a/src/lib/ffmpeg.h b/src/lib/ffmpeg.h index 10517055c..e6399c076 100644 --- a/src/lib/ffmpeg.h +++ b/src/lib/ffmpeg.h @@ -23,9 +23,12 @@ #include "file_group.h" #include "ffmpeg_subtitle_period.h" +#include "warnings.h" +DCPOMATIC_DISABLE_WARNINGS extern "C" { #include } +DCPOMATIC_ENABLE_WARNINGS #include #include diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index cfaf0361b..04c97ed3b 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -206,9 +206,11 @@ FFmpegDecoder::deinterleave_audio (shared_ptr stream) const { DCPOMATIC_ASSERT (bytes_per_audio_sample (stream)); +DCPOMATIC_DISABLE_WARNINGS int const size = av_samples_get_buffer_size ( 0, stream->stream(_format_context)->codec->channels, _frame->nb_samples, audio_sample_format (stream), 1 ); +DCPOMATIC_ENABLE_WARNINGS /* XXX: can't we just use _frame->nb_samples directly here? */ /* XXX: can't we use swr_convert() to do the format conversion? */ @@ -339,7 +341,9 @@ FFmpegDecoder::deinterleave_audio (shared_ptr stream) const AVSampleFormat FFmpegDecoder::audio_sample_format (shared_ptr stream) const { +DCPOMATIC_DISABLE_WARNINGS return stream->stream (_format_context)->codec->sample_fmt; +DCPOMATIC_ENABLE_WARNINGS } int @@ -401,9 +405,11 @@ FFmpegDecoder::seek (ContentTime time, bool accurate) avcodec_flush_buffers (video_codec_context()); } +DCPOMATIC_DISABLE_WARNINGS BOOST_FOREACH (shared_ptr i, ffmpeg_content()->ffmpeg_audio_streams()) { avcodec_flush_buffers (i->stream(_format_context)->codec); } +DCPOMATIC_ENABLE_WARNINGS if (subtitle_codec_context ()) { avcodec_flush_buffers (subtitle_codec_context ()); @@ -434,6 +440,7 @@ FFmpegDecoder::decode_audio_packet () return; } +DCPOMATIC_DISABLE_WARNINGS while (copy_packet.size > 0) { int frame_finished; @@ -493,6 +500,7 @@ FFmpegDecoder::decode_audio_packet () to_string(_pts_offset) ); } +DCPOMATIC_ENABLE_WARNINGS /* Give this data provided there is some, and its time is sane */ if (ct >= ContentTime() && data->frames() > 0) { @@ -511,9 +519,11 @@ FFmpegDecoder::decode_video_packet () DCPOMATIC_ASSERT (_video_stream); int frame_finished; +DCPOMATIC_DISABLE_WARNINGS if (avcodec_decode_video2 (video_codec_context(), _frame, &frame_finished, &_packet) < 0 || !frame_finished) { return false; } +DCPOMATIC_ENABLE_WARNINGS boost::mutex::scoped_lock lm (_filter_graphs_mutex); diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index 3fb9a53e4..cc6a62ff6 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -18,6 +18,14 @@ */ +#include "ffmpeg_examiner.h" +#include "ffmpeg_content.h" +#include "job.h" +#include "ffmpeg_audio_stream.h" +#include "ffmpeg_subtitle_stream.h" +#include "util.h" +#include "warnings.h" +DCPOMATIC_DISABLE_WARNINGS extern "C" { #include #include @@ -26,12 +34,7 @@ extern "C" { #include #include } -#include "ffmpeg_examiner.h" -#include "ffmpeg_content.h" -#include "job.h" -#include "ffmpeg_audio_stream.h" -#include "ffmpeg_subtitle_stream.h" -#include "util.h" +DCPOMATIC_ENABLE_WARNINGS #include #include @@ -44,6 +47,7 @@ using boost::shared_ptr; using boost::optional; using namespace dcpomatic; + /** @param job job that the examiner is operating in, or 0 */ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptr job) : FFmpeg (c) @@ -54,6 +58,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptrnb_streams; ++i) { AVStream* s = _format_context->streams[i]; +DCPOMATIC_DISABLE_WARNINGS if (s->codec->codec_type == AVMEDIA_TYPE_AUDIO) { /* This is a hack; sometimes it seems that _audio_codec_context->channel_layout isn't set up, @@ -119,6 +124,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptrstreams[_packet.stream_index]->codec; +DCPOMATIC_ENABLE_WARNINGS if (_video_stream && _packet.stream_index == _video_stream.get()) { video_packet (context); @@ -175,6 +181,7 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr c, shared_ptr= 0 && frame_finished) { +DCPOMATIC_ENABLE_WARNINGS if (!_first_video) { _first_video = frame_time (_format_context->streams[_video_stream.get()]); } @@ -197,6 +206,7 @@ FFmpegExaminer::video_packet (AVCodecContext* context) } } + void FFmpegExaminer::audio_packet (AVCodecContext* context, shared_ptr stream) { @@ -205,17 +215,22 @@ FFmpegExaminer::audio_packet (AVCodecContext* context, shared_ptr= 0 && frame_finished) { +DCPOMATIC_ENABLE_WARNINGS stream->first_audio = frame_time (stream->stream (_format_context)); } } + optional FFmpegExaminer::frame_time (AVStream* s) const { optional t; +DCPOMATIC_DISABLE_WARNINGS int64_t const bet = av_frame_get_best_effort_timestamp (_frame); +DCPOMATIC_ENABLE_WARNINGS if (bet != AV_NOPTS_VALUE) { t = ContentTime::from_seconds (bet * av_q2d (s->time_base)); } @@ -223,6 +238,7 @@ FFmpegExaminer::frame_time (AVStream* s) const return t; } + optional FFmpegExaminer::video_frame_rate () const { diff --git a/src/lib/ffmpeg_file_encoder.cc b/src/lib/ffmpeg_file_encoder.cc index 44ef3f072..f8bd14e76 100644 --- a/src/lib/ffmpeg_file_encoder.cc +++ b/src/lib/ffmpeg_file_encoder.cc @@ -113,11 +113,13 @@ FFmpegFileEncoder::FFmpegFileEncoder ( throw runtime_error ("could not create FFmpeg output audio stream"); } +DCPOMATIC_DISABLE_WARNINGS _video_stream->id = _video_stream_index; _video_stream->codec = _video_codec_context; _audio_stream->id = _audio_stream_index; _audio_stream->codec = _audio_codec_context; +DCPOMATIC_ENABLE_WARNINGS if (avcodec_open2 (_video_codec_context, _video_codec, &_video_options) < 0) { throw runtime_error ("could not open FFmpeg video codec"); @@ -239,7 +241,9 @@ FFmpegFileEncoder::flush () packet.size = 0; int got_packet; +DCPOMATIC_DISABLE_WARNINGS avcodec_encode_video2 (_video_codec_context, &packet, 0, &got_packet); +DCPOMATIC_ENABLE_WARNINGS if (got_packet) { packet.stream_index = 0; av_interleaved_write_frame (_format_context, &packet); @@ -252,7 +256,9 @@ FFmpegFileEncoder::flush () packet.data = 0; packet.size = 0; +DCPOMATIC_DISABLE_WARNINGS avcodec_encode_audio2 (_audio_codec_context, &packet, 0, &got_packet); +DCPOMATIC_ENABLE_WARNINGS if (got_packet) { packet.stream_index = 0; av_interleaved_write_frame (_format_context, &packet); @@ -307,9 +313,11 @@ FFmpegFileEncoder::video (shared_ptr video, DCPTime time) packet.size = 0; int got_packet; +DCPOMATIC_DISABLE_WARNINGS if (avcodec_encode_video2 (_video_codec_context, &packet, frame, &got_packet) < 0) { throw EncodeError ("FFmpeg video encode failed"); } +DCPOMATIC_ENABLE_WARNINGS if (got_packet && packet.size) { packet.stream_index = _video_stream_index; @@ -403,9 +411,11 @@ FFmpegFileEncoder::audio_frame (int size) packet.size = 0; int got_packet; +DCPOMATIC_DISABLE_WARNINGS if (avcodec_encode_audio2 (_audio_codec_context, &packet, frame, &got_packet) < 0) { throw EncodeError ("FFmpeg audio encode failed"); } +DCPOMATIC_ENABLE_WARNINGS if (got_packet && packet.size) { packet.stream_index = _audio_stream_index; diff --git a/src/lib/ffmpeg_image_proxy.cc b/src/lib/ffmpeg_image_proxy.cc index b54e29d44..f2b72059b 100644 --- a/src/lib/ffmpeg_image_proxy.cc +++ b/src/lib/ffmpeg_image_proxy.cc @@ -86,7 +86,7 @@ avio_seek_wrapper (void* data, int64_t offset, int whence) int FFmpegImageProxy::avio_read (uint8_t* buffer, int const amount) { - int const to_do = min(int64_t(amount), _data.size() - _pos); + int const to_do = min(static_cast(amount), static_cast(_data.size()) - _pos); if (to_do == 0) { return AVERROR_EOF; } @@ -115,6 +115,7 @@ FFmpegImageProxy::avio_seek (int64_t const pos, int whence) return _pos; } +DCPOMATIC_DISABLE_WARNINGS ImageProxy::Result FFmpegImageProxy::image (optional) const @@ -199,6 +200,8 @@ FFmpegImageProxy::image (optional) const return Result (_image, 0); } +DCPOMATIC_ENABLE_WARNINGS + void FFmpegImageProxy::add_metadata (xmlpp::Node* node) const { diff --git a/src/lib/util.cc b/src/lib/util.cc index 74951fc64..91a8ecb6e 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -45,6 +45,7 @@ #include "image.h" #include "text_decoder.h" #include "job_manager.h" +#include "warnings.h" #include #include #include @@ -356,8 +357,10 @@ dcpomatic_setup () SetUnhandledExceptionFilter(exception_handler); #endif +DCPOMATIC_DISABLE_WARNINGS av_register_all (); avfilter_register_all (); +DCPOMATIC_ENABLE_WARNINGS #ifdef DCPOMATIC_OSX /* Add our library directory to the libltdl search path so that diff --git a/src/lib/video_filter_graph.cc b/src/lib/video_filter_graph.cc index 6075500e9..9b297c87b 100644 --- a/src/lib/video_filter_graph.cc +++ b/src/lib/video_filter_graph.cc @@ -18,9 +18,10 @@ */ -#include "video_filter_graph.h" -#include "image.h" #include "compose.hpp" +#include "image.h" +#include "video_filter_graph.h" +#include "warnings.h" extern "C" { #include #include @@ -51,6 +52,7 @@ VideoFilterGraph::process (AVFrame* frame) { list, int64_t> > images; +DCPOMATIC_DISABLE_WARNINGS if (_copy) { images.push_back (make_pair (shared_ptr (new Image (frame)), av_frame_get_best_effort_timestamp (frame))); } else { @@ -68,6 +70,7 @@ VideoFilterGraph::process (AVFrame* frame) av_frame_unref (_frame); } } +DCPOMATIC_ENABLE_WARNINGS return images; } -- 2.30.2