Guest User

Untitled

a guest
Sep 14th, 2016
136
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     while (av_read_frame(formatContext, &packet)>=0)
  3.     {
  4.  
  5.         result = decodeVideo(videoCodecContext, frame, &frameFinished, &packet);
  6.  
  7.         if (result < 0 && result != AVERROR_EOF)
  8.         {
  9.             showLog("Error on decoding video");
  10.  
  11.             showErrorMessage(result);
  12.  
  13.             freeMemory();
  14.  
  15.             return -1;
  16.         }
  17.  
  18.         showLog("Decoding video successful");
  19.  
  20.         if (frameFinished && packet.stream_index==videoStream)
  21.         {
  22.             result = sws_scale(swsContext, (uint8_t const * const *)frame->data, frame->linesize, 0, frame->height, rgbFrame->data, rgbFrame->linesize);
  23.  
  24.             if (result < 0)
  25.             {
  26.                 showLog("Error on converting image");
  27.  
  28.                 showErrorMessage(result);
  29.  
  30.                 freeMemory();
  31.  
  32.                 return -1;
  33.             }
  34.  
  35.             showLog("Image scaling successful");
  36.         }
  37.  
  38.         av_packet_unref(&packet);
  39.        
  40.     }
  41.  
  42. int decodeVideo(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
  43. {
  44.     int ret = 0;
  45.  
  46.     *got_frame = 0;
  47.  
  48.     if (pkt)
  49.     {
  50.         ret = avcodec_send_packet(avctx, pkt);
  51.  
  52.         // In particular, we don't expect AVERROR(EAGAIN), because we read all
  53.         // decoded frames with avcodec_receive_frame() until done.
  54.         if (ret < 0)
  55.         {
  56.             return ret == AVERROR_EOF ? 0 : ret;
  57.         }
  58.     }
  59.  
  60.     ret = avcodec_receive_frame(avctx, frame);
  61.  
  62.     if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
  63.     {
  64.         return ret;
  65.     }
  66.  
  67.     if (ret >= 0)
  68.     {
  69.         *got_frame = 1;
  70.     }
  71.  
  72.     return ret;
  73. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×