[Libav-user] Loosing Video Frames
gaurav mishra
gauravmishra.itbhu at gmail.com
Mon Oct 12 11:43:06 CEST 2015
Hi,
I have written some code which opens up a mp4 file , decodes each frame ,
does some manipulation on it and encode it back to new container. Issue i
am seeing here is i am loosing last 3 sec (approx 65 frames) of video .
Below is a simplified version of code which i expected to create a
identical file.which does no manipulation on frame just decode a frame then
encode it back and finally mux it.
while(1) {
ret = av_read_frame(ifmt_ctx, &packet);
if(ret < 0) {
av_log( NULL , AV_LOG_ERROR , "error reading frame or end of
file");
break;
}
AVStream *in_stream = ifmt_ctx->streams[packet.stream_index];
AVStream *output_stream =
out_stream.format_ctx->streams[packet.stream_index];
stream_index = packet.stream_index;
frame_decoded = 0;
frame = av_frame_alloc();
ret = avcodec_decode_video2(in_stream->codec, frame,
&frame_decoded, &packet);
if(ret<0){
av_frame_free(&frame);
fprintf(stderr,"could not decode a packet....");
return ret;
}
if(frame_decoded){
ptsFactor = 2;
frame->pts = ptsFactor*frameEncodedCount ;
frameEncodedCount++;
av_init_packet(&encoded_packet);
encode_success = 0;
ret =
avcodec_encode_video2(this->out_stream.format_ctx->streams[0]->codec,
&encoded_packet,
frame,
&encode_success);
encoded_packet.stream_index = 0;
if(encode_success){
av_packet_rescale_ts(&encoded_packet,
this->out_stream.format_ctx->streams[0]->codec->time_base,
this->out_stream.format_ctx->streams[0]->time_base);
ret =
av_interleaved_write_frame(this->out_stream.format_ctx, &encoded_packet);
}
}
}
I also noticed that the first above code failed to encode first 60 frames
of video. ie
it successfully decoded frames but didnt enter the if(encode_success)
block. Any idea what might be going wrong here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20151012/58a9bc1f/attachment.html>
More information about the Libav-user
mailing list