[FFmpeg-user] about flushing decoder at the end of file
YIRAN LI
mrfun.china at gmail.com
Wed Feb 19 04:03:46 CET 2014
Hi friends,
I know when av_read_frame(ctx, pkt) returns < 0 we can set pkt.data = NULL
and pkt.size = 0 to flush any frames in decoder if the decoder has the
CODEC_CAP_DELAY set.
The example in src/doc/examples/demuxing.c does these
while (av_read_frame(ctx, &pkt) >=0 ) {
decode_packet(&got_frame, 0);
av_free_packet()
}
pkt.data = NULL;
pkt.size = 0;
do {
decode_packet(&got_frame, 1);
} while (got_frame);
so my question is how if both Audio and Video has something to flush?
Because decode_packet() depends on pkt.stream_index to call audio or video
decoder,
but pkt.stream_index is set in the last call to av_read_frame, so it never
changes in whole
do {} while.
My second question is how to flush all video frame quickly. Can I do this:
while (av_read_frame(ctx, &pkt) >=0 ) {
decode_packet(&got_frame, 0);
av_free_packet()
}
// will it have problem if there're only audio frames wait to flush but no
video frame
// can I explicitly set pkt index to video and call decode_video? (I only
want video frames)
pkt.stream_index = video_index;
pkt.data = NULL;
pkt.size = 0;
do {
avcodec_decode_video2(,&got_frame,..);
} while(got_frame)
I set steam_index to video index because I'm afraid that pkt.stream_index
may be the index of audio after return from av_read_frame().
Just imagine this case: when av_read_frame() returns < 0, there're audio
frames wait to flush but no video frames left. Will my call to
avcodec_decode_video2(,&got_frame,..) cause any crash? or it's guaranteed
to return got_frame == false so that I know there's no video frame left?
Great thanks!
More information about the ffmpeg-user
mailing list