SHARE
TWEET

Untitled

a guest Jul 24th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int size = avpicture_get_size(AV_PIX_FMT_YUV420P,
  2.   ccontext>width,ccontext->height);
  3.   uint8_t* picture_buf = (uint8_t*)(av_malloc(size));
  4.   AVFrame* pic = avcodec_alloc_frame();
  5.   AVFrame* picrgb = avcodec_alloc_frame();
  6.   int size2 = avpicture_get_size(AV_PIX_FMT_RGB24, ccontext->width,
  7.   ccontext->height);
  8.   uint8_t* picture_buf2 = (uint8_t*)(av_malloc(size2));
  9.   avpicture_fill((AVPicture *)pic, picture_buf, AV_PIX_FMT_YUV420P,
  10.   ccontext->width, ccontext->height);
  11.   avpicture_fill((AVPicture *)picrgb, picture_buf2,AV_PIX_FMT_RGB24,
  12.   ccontext->width, ccontext->height);
  13.  
  14.   while (av_read_frame(context, &packet) >= 0 && cnt < 1000)
  15.  {//read 100 frames
  16.  
  17.     std::cout << "1 Frame: " << cnt << std::endl;
  18.     if (packet.stream_index == video_stream_index)
  19.     {//packet is video
  20.         std::cout << "2 Is Video" << std::endl;
  21.         if (stream == NULL)
  22.         {//create stream in file
  23.             std::cout << "3 create stream" << std::endl;
  24.             stream = avformat_new_stream(oc, context-
  25.             >streams[video_stream_index]->codec->codec);
  26.             avcodec_copy_context(stream->codec, context-
  27.             >streams[video_stream_index]->codec);
  28.             stream->sample_aspect_ratio = context-
  29.             >streams[video_stream_index]->codec->sample_aspect_ratio;
  30.         }
  31.         int check = 0;
  32.         packet.stream_index = stream->id;
  33.         std::cout << "4 decoding" << std::endl;
  34.         int result = avcodec_decode_video2(ccontext, pic,          
  35.         &check,&packet);
  36.         std::cout << "Bytes decoded " << result << " check " << check <<
  37.         std::endl;
  38.         if (cnt > 100)//cnt < 0)
  39.         {
  40.             sws_scale(img_convert_ctx, pic->data, pic->linesize, 0,
  41.             ccontext->height, picrgb->data, picrgb->linesize);
  42.             std::stringstream name;
  43.             name << "test" << cnt << ".ppm";
  44.             myfile.open(name.str());
  45.             myfile << "P3 " << ccontext->width << " " << ccontext->height
  46.                   << " 255n";
  47.             for (int y = 0; y < ccontext->height; y++)
  48.             {
  49.                 for (int x = 0; x < ccontext->width * 3; x++)
  50.                     myfile << (int)(picrgb->
  51.                 data[0] + y * picrgb->linesize[0])[x] << " ";
  52.             }
  53.             myfile.close();
  54.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top