@@ -116,14 +116,8 @@ class VideoSeekContext {
116116 /* Number of frames that were decoded during seek. */
117117 uint64_t num_frames_decoded_;
118118
119- /* DTS of frame found after seek.
120- * In case the requested frame is not seekable, the demuxer will seek
121- * to the nearest seekable frame and its DTS is stored in out_frame_dts_.
122- */
123- int64_t out_frame_dts_;
124-
125- /* DTS of frame to seek as set by the user in seek_frame_. */
126- int64_t requested_frame_dts_;
119+ /* PTS of frame to seek as set by the user in seek_frame_. */
120+ int64_t requested_frame_pts_;
127121};
128122
129123
@@ -161,7 +155,7 @@ class VideoDemuxer {
161155 av_free (data_with_header_);
162156 }
163157 }
164- bool Demux (uint8_t **video, int *video_size, int64_t *pts = nullptr , int64_t *dts = nullptr ) {
158+ bool Demux (uint8_t **video, int *video_size, int64_t *pts = nullptr ) {
165159 if (!av_fmt_input_ctx_) {
166160 return false ;
167161 }
@@ -199,7 +193,6 @@ class VideoDemuxer {
199193 *pts = (int64_t ) (packet_filtered_->pts * default_time_scale_ * time_base_);
200194 pkt_duration_ = packet_filtered_->duration ;
201195 }
202- if (dts) *dts = pkt_dts_;
203196 } else {
204197 if (is_mpeg4_ && (frame_count_ == 0 )) {
205198 int ext_data_size = av_fmt_input_ctx_->streams [av_stream_]->codecpar ->extradata_size ;
@@ -227,7 +220,6 @@ class VideoDemuxer {
227220 *pts = (int64_t )(packet_->pts * default_time_scale_ * time_base_);
228221 pkt_duration_ = packet_->duration ;
229222 }
230- if (dts) *dts = pkt_dts_;
231223 }
232224 frame_count_++;
233225 return true ;
@@ -249,7 +241,6 @@ class VideoDemuxer {
249241 std::cerr << " ERROR: Can't seek by frame number in VFR sequences. Seek by timestamp instead." << std::endl;
250242 return false ;
251243 }
252-
253244 int64_t timestamp = 0 ;
254245 // Seek for single frame;
255246 auto seek_frame = [&](VideoSeekContext const & seek_ctx, int flags) {
@@ -309,7 +300,7 @@ class VideoDemuxer {
309300
310301 int seek_done = 0 ;
311302 do {
312- if (!Demux (pp_video, video_size, &pkt_data.pts , &pkt_data. dts )) {
303+ if (!Demux (pp_video, video_size, &pkt_data.pts )) {
313304 throw std::runtime_error (" ERROR: Demux failed trying to seek for specified frame number/timestamp" );
314305 }
315306 seek_done = is_seek_done (pkt_data, seek_ctx);
@@ -327,20 +318,18 @@ class VideoDemuxer {
327318 } while (seek_done != 0 );
328319
329320 seek_ctx.out_frame_pts_ = pkt_data.pts ;
330- seek_ctx.out_frame_dts_ = pkt_data.dts ;
331- seek_ctx.requested_frame_dts_ = timestamp;
332321 seek_ctx.out_frame_duration_ = pkt_data.duration = pkt_duration_;
322+ seek_ctx.requested_frame_pts_ = (int64_t ) (timestamp * default_time_scale_ * time_base_);
333323 };
334324
335325 // Seek for closest key frame in the past;
336326 auto seek_for_prev_key_frame = [&](PacketData& pkt_data, VideoSeekContext& seek_ctx) {
337327 seek_frame (seek_ctx, AVSEEK_FLAG_BACKWARD );
338- Demux (pp_video, video_size, &pkt_data.pts , &pkt_data. dts );
328+ Demux (pp_video, video_size, &pkt_data.pts );
339329 seek_ctx.num_frames_decoded_ = static_cast <uint64_t >(pkt_data.pts / 1000 * frame_rate_);
340330 seek_ctx.out_frame_pts_ = pkt_data.pts ;
341- seek_ctx.out_frame_dts_ = pkt_data.dts ;
342- seek_ctx.requested_frame_dts_ = timestamp;
343331 seek_ctx.out_frame_duration_ = pkt_data.duration = pkt_duration_;
332+ seek_ctx.requested_frame_pts_ = (int64_t ) (timestamp * default_time_scale_ * time_base_);
344333 };
345334
346335 PacketData pktData;
0 commit comments