Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while (av_read_frame(formatContext, &packet)>=0)
- {
- result = decodeVideo(videoCodecContext, frame, &frameFinished, &packet);
- if (result < 0 && result != AVERROR_EOF)
- {
- showLog("Error on decoding video");
- showErrorMessage(result);
- freeMemory();
- return -1;
- }
- showLog("Decoding video successful");
- if (frameFinished && packet.stream_index==videoStream)
- {
- result = sws_scale(swsContext, (uint8_t const * const *)frame->data, frame->linesize, 0, frame->height, rgbFrame->data, rgbFrame->linesize);
- if (result < 0)
- {
- showLog("Error on converting image");
- showErrorMessage(result);
- freeMemory();
- return -1;
- }
- showLog("Image scaling successful");
- }
- av_packet_unref(&packet);
- }
- int decodeVideo(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
- {
- int ret = 0;
- *got_frame = 0;
- if (pkt)
- {
- ret = avcodec_send_packet(avctx, pkt);
- // In particular, we don't expect AVERROR(EAGAIN), because we read all
- // decoded frames with avcodec_receive_frame() until done.
- if (ret < 0)
- {
- return ret == AVERROR_EOF ? 0 : ret;
- }
- }
- ret = avcodec_receive_frame(avctx, frame);
- if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
- {
- return ret;
- }
- if (ret >= 0)
- {
- *got_frame = 1;
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement