[Libav-user] Having problem to seek MPEGTS video using av_seek_frame

zuraq heziyuz at gmail.com
Fri Mar 12 09:41:53 EET 2021

I'm trying to use ffmpeg function to capture some thumbnail of video. I'm use
the example of the ffmpeg and write code like this:

    int timeStamp = ((double)ms / (double)1000) *
pFormatCtx->streams[videoStream]->time_base.den /

    int ret = av_seek_frame(pFormatCtx, videoStream, timeStamp,

    while (av_read_frame(pFormatCtx, &packet) >= 0) {

        if (packet.stream_index == videoStream) {
            avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished,

            if (frameFinished) {
                sws_scale(sws_ctx, (uint8_t const * const *) pFrame->data,
pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data,

                if (++i <= 1) {
                    SaveFrame(pFrameRGB, pCodecCtx->width,
pCodecCtx->height, i);


actually,it works well in .mp4 video. but for .ts video, it can only capture
the first frame of the video, I think the problem is av_seek_frame doesnt
work,but I dont know how to fix the problem. can anyone give me some help?

Sent from: http://libav-users.943685.n4.nabble.com/

More information about the Libav-user mailing list