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;
150 double pts_offset_seconds;
151 double audio_pts_seconds;
152 double video_pts_seconds;
153 int64_t NO_PTS_OFFSET;
157 double video_stream_duration_seconds = 0.0;
158 double audio_stream_duration_seconds = 0.0;
159 double format_duration_seconds = 0.0;
160 double inferred_duration_seconds = 0.0;
163 SwsContext *img_convert_ctx =
nullptr;
165 AVFrame *pFrameRGB_cached =
nullptr;
167 int hw_de_supported = 0;
169 AVPixelFormat hw_de_av_pix_fmt = AV_PIX_FMT_NONE;
170 AVHWDeviceType hw_de_av_device_type = AV_HWDEVICE_TYPE_NONE;
171 int IsHardwareDecodeSupported(
int codecid);
181 void CheckWorkingFrames(int64_t requested_frame);
184 int64_t ConvertFrameToAudioPTS(int64_t frame_number);
187 int64_t ConvertFrameToVideoPTS(int64_t frame_number);
190 int64_t ConvertVideoPTStoFrame(int64_t pts);
193 std::shared_ptr<openshot::Frame> CreateFrame(int64_t requested_frame);
205 int64_t GetPacketPTS();
211 double PickDurationSeconds()
const;
214 void ApplyDurationStrategy();
217 bool IsPartialFrame(int64_t requested_frame);
220 void ProcessVideoPacket(int64_t requested_frame);
223 void ProcessAudioPacket(int64_t requested_frame);
226 std::shared_ptr<openshot::Frame> ReadStream(int64_t requested_frame);
229 void RemoveAVFrame(AVFrame *);
232 void RemoveAVPacket(AVPacket *);
235 void Seek(int64_t requested_frame);
240 void UpdatePTSOffset();
243 void UpdateAudioInfo();
246 void UpdateVideoInfo();
262 FFmpegReader(
const std::string& path,
bool inspect_reader=
true);
274 void Close()
override;
283 std::shared_ptr<openshot::Frame>
GetFrame(int64_t requested_frame)
override;
286 bool IsOpen()
override {
return is_open; };
289 std::string
Name()
override {
return "FFmpegReader"; };
292 std::string
Json()
const override;
293 void SetJson(
const std::string value)
override;
298 void Open()
override;