[Ffmpeg-devel] Seeking into MPEG TS video files

Stefan Paulsen paulsen.stefan
Mon Apr 2 14:19:32 CEST 2007


Thanks for your answer.
The problem is, that I'm only able to jump to the beginning of the file.
Reading older threads reagarding this problem I found this code:

av_seek_frame( fmtCtx, -1, TARGET_PTS, AVSEEK_FLAG_BACKWARD );
CodecCtx->hurry_up = 1;
do {
    av_read_frame( fmtCtx, &Packet );
    // should really be checking that this is a video packet
    MyPts = Packet.pts / Packet.duration *
	AV_TIME_BASE / av_q2d( Stream->r_frame_rate);
    if( MyPts > TARGET_PTS )
        break;
    avcodec_decode_video( CodecCtx, pFrame, &gotFrame, Packet.data,
        Packet.size );
    av_free_packet( &Packet );
} while(1);
CodecCtx->hurry_up = 0;
// Now near TARGET_PTS with Packet ready for decode (and free)

But after I have seek into my video file and call av_read_frame(), I always
get the first frame of the video. av_seek_frame() just seems to ignore the
timestamp argument. Only if the timestamp is bigger than the duration of the
stream, I get a packet with a negative PTS.

Regards
Stefan


2007/4/2, M?ns Rullg?rd <mans at mansr.com>:
>
>
> Stefan Paulsen said:
> > Hi,
> >
> > is there a way to seek into MPEG TS video files? Using av_seek_frame()
> > doesn't seem to work, because there are no information on where to find
> the
> > keyframes. I'm only able to jump to the beginning.
>
> MPEG TS doesn't have an index, so seeking will always be problematic.  You
> should still be able to seek to an approximate location if you don't care
> about landing at a keyframe.
>
> --
> M?ns Rullg?rd
> mans at mansr.com
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>




More information about the ffmpeg-devel mailing list