2 Copyright (C) 2013-2016 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/>.
21 #ifndef DCPOMATIC_FFMPEG_H
22 #define DCPOMATIC_FFMPEG_H
24 #include "file_group.h"
25 #include "ffmpeg_subtitle_period.h"
27 #include <libavcodec/avcodec.h>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/thread/mutex.hpp>
32 struct AVFormatContext;
37 class FFmpegAudioStream;
43 FFmpeg (boost::shared_ptr<const FFmpegContent>);
46 boost::shared_ptr<const FFmpegContent> ffmpeg_content () const {
47 return _ffmpeg_content;
50 int avio_read (uint8_t *, int);
51 int64_t avio_seek (int64_t, int);
54 AVCodecContext* video_codec_context () const;
55 AVCodecContext* subtitle_codec_context () const;
56 ContentTime pts_offset (
57 std::vector<boost::shared_ptr<FFmpegAudioStream> > audio_streams, boost::optional<ContentTime> first_video, double video_frame_rate
60 static FFmpegSubtitlePeriod subtitle_period (AVSubtitle const & sub);
61 static std::string subtitle_id (AVSubtitle const & sub);
62 static bool subtitle_starts_image (AVSubtitle const & sub);
64 boost::shared_ptr<const FFmpegContent> _ffmpeg_content;
66 uint8_t* _avio_buffer;
67 int _avio_buffer_size;
68 AVIOContext* _avio_context;
69 FileGroup _file_group;
71 AVFormatContext* _format_context;
75 /** Index of video stream within AVFormatContext */
76 boost::optional<int> _video_stream;
78 /* It would appear (though not completely verified) that one must have
79 a mutex around calls to avcodec_open* and avcodec_close... and here
82 static boost::mutex _mutex;
85 void setup_general ();
86 void setup_decoders ();
88 static void ffmpeg_log_callback (void* ptr, int level, const char* fmt, va_list vl);
89 static boost::weak_ptr<Log> _ffmpeg_log;