while (av_read_frame(pFormatCtx, packet) >= 0){
EnterCriticalSection(&cs) ;
if (packet->stream_index == videoindex){
ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
if (ret < 0){
printf("Decode Error.\n");
return -1;
}
if (got_picture){
pFrame->pts = av_frame_get_best_effort_timestamp(pFrame);
if (filter_change)
apply_filters(pFormatCtx);
filter_change = 0;
/* push the decoded frame into the filtergraph */
if (av_buffersrc_add_frame(buffersrc_ctx, pFrame) < 0) {
printf("Error while feeding the filtergraph\n");
break;
}
picref = av_frame_alloc();
while (1) {
ret = av_buffersink_get_frame_flags(buffersink_ctx, picref, 0);
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
break;
if (ret < 0)
return ret;
if (picref) {
img_convert_ctx = sws_getContext(picref->width, picref->height, (AVPixelFormat)picref->format, pCodecCtx->width, pCodecCtx->hei