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;
134 int64_t seeking_frame;
137 int64_t seek_audio_frame_found;
138 int64_t seek_video_frame_found;
141 int64_t largest_frame_processed;
142 int64_t current_video_frame;
147 double pts_offset_seconds;
148 double audio_pts_seconds;
149 double video_pts_seconds;
150 int64_t NO_PTS_OFFSET;
154 double video_stream_duration_seconds = 0.0;
155 double audio_stream_duration_seconds = 0.0;
156 double format_duration_seconds = 0.0;
157 double inferred_duration_seconds = 0.0;
160 SwsContext *img_convert_ctx =
nullptr;
162 AVFrame *pFrameRGB_cached =
nullptr;
164 int hw_de_supported = 0;
166 AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE;
167 AVHWDeviceType hw_de_av_device_type = AV_HWDEVICE_TYPE_NONE;
168 int IsHardwareDecodeSupported(
int codecid);
175 bool CheckSeek(
bool is_video);
178 void CheckWorkingFrames(int64_t requested_frame);
181 int64_t ConvertFrameToAudioPTS(int64_t frame_number);
184 int64_t ConvertFrameToVideoPTS(int64_t frame_number);
187 int64_t ConvertVideoPTStoFrame(int64_t pts);
190 std::shared_ptr<openshot::Frame> CreateFrame(int64_t requested_frame);
202 int64_t GetPacketPTS();
208 double PickDurationSeconds()
const;
211 void ApplyDurationStrategy();
214 bool IsPartialFrame(int64_t requested_frame);
217 void ProcessVideoPacket(int64_t requested_frame);
220 void ProcessAudioPacket(int64_t requested_frame);
223 std::shared_ptr<openshot::Frame> ReadStream(int64_t requested_frame);
226 void RemoveAVFrame(AVFrame *);
229 void RemoveAVPacket(AVPacket *);
232 void Seek(int64_t requested_frame);
237 void UpdatePTSOffset();
240 void UpdateAudioInfo();
243 void UpdateVideoInfo();
259 FFmpegReader(
const std::string& path,
bool inspect_reader=
true);
271 void Close()
override;
280 std::shared_ptr<openshot::Frame>
GetFrame(int64_t requested_frame)
override;
283 bool IsOpen()
override {
return is_open; };
286 std::string
Name()
override {
return "FFmpegReader"; };
289 std::string
Json()
const override;
290 void SetJson(
const std::string value)
override;
295 void Open()
override;