2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef DCPOMATIC_FFMPEG_H
23 #define DCPOMATIC_FFMPEG_H
26 #include "file_group.h"
27 #include "ffmpeg_subtitle_period.h"
29 DCPOMATIC_DISABLE_WARNINGS
31 #include <libavcodec/avcodec.h>
33 DCPOMATIC_ENABLE_WARNINGS
34 #include <boost/thread/mutex.hpp>
37 struct AVFormatContext;
42 class FFmpegAudioStream;
49 explicit FFmpeg (std::shared_ptr<const FFmpegContent>);
52 std::shared_ptr<const FFmpegContent> ffmpeg_content () const {
53 return _ffmpeg_content;
56 int avio_read (uint8_t *, int);
57 int64_t avio_seek (int64_t, int);
60 AVCodecContext* video_codec_context () const;
61 AVCodecContext* subtitle_codec_context () const;
62 dcpomatic::ContentTime pts_offset (
63 std::vector<std::shared_ptr<FFmpegAudioStream>> audio_streams, boost::optional<dcpomatic::ContentTime> first_video, double video_frame_rate
66 static FFmpegSubtitlePeriod subtitle_period (AVSubtitle const & sub);
68 std::shared_ptr<const FFmpegContent> _ffmpeg_content;
70 uint8_t* _avio_buffer = nullptr;
71 int _avio_buffer_size = 4096;
72 AVIOContext* _avio_context = nullptr;
73 FileGroup _file_group;
75 AVFormatContext* _format_context = nullptr;
76 std::vector<AVCodecContext*> _codec_context;
77 AVFrame* _frame = nullptr;
79 /** Index of video stream within AVFormatContext */
80 boost::optional<int> _video_stream;
82 /* It would appear (though not completely verified) that one must have
83 a mutex around calls to avcodec_open* and avcodec_close... and here
86 static boost::mutex _mutex;
89 void setup_general ();
90 void setup_decoders ();
92 static void ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl);
93 static std::weak_ptr<Log> _ffmpeg_log;