I still get the nearest key frame...
Let's say i want to seek to the middle of the video. I'm using this code to
get the length of the video and divided by 2.

int64_t targetPos = (int64_t)(pFormatCtx->streams[videoStream]->duration / 2
* AV_TIME_BASE);


Next i do the seek stuff.

av_seek_frame(pFormatCtx, videoStream, targetPos, AVSEEK_FLAG_BACKWARD);

do {av_read_frame(pFormatCtx, &packet);

        avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,packet.data,
packet.size);

        if (packet.pts = targetPos)
        {
            if(frameFinished)
            {
                break;
            }
        }

        av_free_packet(&packet);

} while(1);


Am i missing something here?


Best regards





On Thu, Jan 20, 2011 at 7:06 PM, Thomas Rehaag <[email protected]>wrote:

>
>  Hi all,
>>
>> I'm totally new to ffmpeg-lib so bare with me.
>>
>> I'm working on a project to extract x frames from a video, from start to
>> end, and save them as an jpeg. I've been using
>> "pFormatCtx->streams[videoStream]->duration" to get the total length of
>> the
>> video.
>> Now to my question, what is the best way to seek in a video file?
>>
>> I've been using the "av_seek_frame" but it only seems to be seeking to the
>> nearest keyframe. I don't need the seek to be super accurate, but close.
>> Is it possible to seek by a timecode instead?
>>
>> Best regards
>>
>
> Hi,
>
>
> > I'm totally new to ffmpeg-lib so bare with me.
> so I'm about one step ahead ;)
>
> I do this:
>
> int64_t targetPos = (int64_t)(fSearch * AV_TIME_BASE);
> av_seek_frame(m_pFormatCtx, -1, targetPos, AVSEEK_FLAG_BACKWARD);
>
> with fSearch in seconds and it works fine.
>
> Regards,
>
> Thomas
> _______________________________________________
> libav-user mailing list
> [email protected]
> https://lists.mplayerhq.hu/mailman/listinfo/libav-user
>
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to