16#ifndef OPENSHOT_FFMPEG_READER_H
17#define OPENSHOT_FFMPEG_READER_H
107 AVFormatContext *pFormatCtx;
108 int videoStream, audioStream;
109 AVCodecContext *pCodecCtx, *aCodecCtx;
111 AVBufferRef *hw_device_ctx = NULL;
113 AVStream *pStream, *aStream;
117 bool is_duration_known;
118 bool check_interlace;
130 std::shared_ptr<openshot::Frame> last_video_frame;
131 std::shared_ptr<openshot::Frame> last_final_video_frame;
135 int64_t seeking_frame;
138 int64_t seek_audio_frame_found;
139 int64_t seek_video_frame_found;
140 int64_t last_seek_max_frame;
141 int seek_stagnant_count;
144 int64_t largest_frame_processed;
145 int64_t current_video_frame;
147 int64_t first_video_frame = 0;
152 double pts_offset_seconds;
153 double audio_pts_seconds;
154 double video_pts_seconds;
155 int64_t NO_PTS_OFFSET;
159 double video_stream_duration_seconds = 0.0;
160 double audio_stream_duration_seconds = 0.0;
161 double format_duration_seconds = 0.0;
162 double inferred_duration_seconds = 0.0;
163 int source_width = 0;
164 int source_height = 0;
165 double source_rotation = 0.0;
168 SwsContext *img_convert_ctx =
nullptr;
170 AVFrame *pFrameRGB_cached =
nullptr;
172 int hw_de_supported = 0;
173 bool force_sw_decode =
false;
174 bool hw_decode_failed =
false;
175 int hw_decode_error_count = 0;
176 bool hw_decode_succeeded =
false;
178 AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE;
179 AVHWDeviceType hw_de_av_device_type = AV_HWDEVICE_TYPE_NONE;
180 int IsHardwareDecodeSupported(
int codecid);
190 void CheckWorkingFrames(int64_t requested_frame);
193 int64_t ConvertFrameToAudioPTS(int64_t frame_number);
196 int64_t ConvertFrameToVideoPTS(int64_t frame_number);
199 int64_t ConvertVideoPTStoFrame(int64_t pts);
202 std::shared_ptr<openshot::Frame> CreateFrame(int64_t requested_frame);
211 bool ReopenWithoutHardwareDecode(int64_t requested_frame);
217 int64_t GetPacketPTS();
223 double PickDurationSeconds()
const;
226 void ApplyDurationStrategy();
229 bool IsPartialFrame(int64_t requested_frame);
232 void ProcessVideoPacket(int64_t requested_frame);
235 void ProcessAudioPacket(int64_t requested_frame);
238 std::shared_ptr<openshot::Frame> ReadStream(int64_t requested_frame);
241 void RemoveAVFrame(AVFrame *);
244 void RemoveAVPacket(AVPacket *);
247 void Seek(int64_t requested_frame);
252 void UpdatePTSOffset();
255 void UpdateAudioInfo();
258 void UpdateVideoInfo();
261 void UpdateOrientedVideoInfo();
264 void ApplyFrameOrientation(std::shared_ptr<openshot::Frame> frame);
280 FFmpegReader(
const std::string& path,
bool inspect_reader=
true);
292 void Close()
override;
301 std::shared_ptr<openshot::Frame>
GetFrame(int64_t requested_frame)
override;
304 bool IsOpen()
override {
return is_open; };
310 std::string
Name()
override {
return "FFmpegReader"; };
313 std::string
Json()
const override;
314 void SetJson(
const std::string value)
override;
319 void Open()
override;
Header file for AudioLocation class.
Header file for CacheMemory class.
Header file for Clip class.
Header file for TextReader class.
Header file for FFmpegUtilities.
Header file for OpenMPUtilities (set some common macros)
Header file for ReaderBase class.
Header file for global Settings class.
This class is a memory-based cache manager for Frame objects.
This class uses the FFmpeg libraries, to open video files and audio files, and return openshot::Frame...
void Open() override
Open File - which is called by the constructor automatically.
CacheMemory * GetCache() override
Get the cache object used by this reader.
bool HardwareDecodeSuccessful() const override
Return true if hardware decode was requested and successfully produced at least one frame.
FFmpegReader(const std::string &path, bool inspect_reader=true)
Constructor for FFmpegReader.
Json::Value JsonValue() const override
Generate Json::Value for this object.
bool GetIsDurationKnown()
Return true if frame can be read with GetFrame()
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
CacheMemory final_cache
Final cache object used to hold final frames.
std::string Name() override
Return the type name of the class.
virtual ~FFmpegReader()
Destructor.
std::string Json() const override
Generate JSON string of this object.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
void Close() override
Close File.
void SetJson(const std::string value) override
Load JSON string into this object.
bool IsOpen() override
Determine if reader is open or closed.
This abstract class is the base class, used by all readers in libopenshot.
This namespace is the default namespace for all code in the openshot library.
DurationStrategy
This enumeration determines which duration source to favor.
This struct holds the associated video frame and starting sample # for an audio packet.
This struct holds the packet counts and end-of-file detection for an openshot::FFmpegReader.
int64_t packets_decoded()