Hello All,
I am a ffmpeg newbie and what I am trying to do is open a video and
based on the user input step through the frames of the video. I looked
and several examples online and was able to come up with an
implementation. This works fine for uncompressed and cinepak codecs.
But for some reason for other AVI files, I get the keyframe and for
subsequent frames after that I seem to be getting ghosting, which my
guess is a difference frame. My implementation for the seek is as
follows. Here number is the frame number. I would be extremely glad
for any help.
Thanks a lot
Avinash
int64_t seek_target = int64_t
(pFormatCtx->streams[videoStream]->time_base.den)* number *
pFormatCtx->streams[videoStream]->r_frame_rate.den;
seek_target = seek_target
/pFormatCtx->streams[videoStream]->time_base.num/pFormatCtx->streams[videoStream]->r_frame_rate.num
+ pFormatCtx->streams[videoStream]>start_time;
int err = av_seek_frame(pFormatCtx,videoStream,seek_target,AVSEEK_FLAG_ANY);
numBytes = avpicture_get_size(PIX_FMT_RGB24, dst_w, dst_h);
buffer = new uint8_t[numBytes + 64];
//put a PPM header on the buffer
int headerlen = sprintf((char *) buffer, "P6 %d %d 255\n", dst_w, dst_h);
avpicture_fill(
(AVPicture *)pFrameRGB,
buffer + headerlen,
PIX_FMT_RGB24,
dst_w,
dst_h);
SwsContext *img_convert_ctx;
img_convert_ctx = sws_getContext(pCodecCtx->width,
pCodecCtx->height, pCodecCtx->pix_fmt,dst_w,
dst_h,PIX_FMT_RGB24,SWS_BICUBIC, NULL, NULL, NULL);
i=0;
int len = avpicture_get_size(PIX_FMT_RGB24,dst_w,dst_h)+headerlen;
pCodecCtx->debug = 0;
avcodec_get_frame_defaults(pFrame);
while(av_read_frame(pFormatCtx, &packet)>=0 && i<1)
{
// Is this a packet from the video stream?
if(packet.stream_index==videoStream)
{
// Decode video frame
int const bytesDecoded = avcodec_decode_video2(pCodecCtx,
pFrame, &frameFinished,&packet);
// Did we get a video frame?
if(frameFinished) {
// Convert the image from its native format to RGB
sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0,
pCodecCtx->height, pFrameRGB->data,
pFrameRGB->linesize);
// Update Image in GUI
i=i+1;
}
}
}
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user