Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int size = avpicture_get_size(AV_PIX_FMT_YUV420P,
- ccontext>width,ccontext->height);
- uint8_t* picture_buf = (uint8_t*)(av_malloc(size));
- AVFrame* pic = avcodec_alloc_frame();
- AVFrame* picrgb = avcodec_alloc_frame();
- int size2 = avpicture_get_size(AV_PIX_FMT_RGB24, ccontext->width,
- ccontext->height);
- uint8_t* picture_buf2 = (uint8_t*)(av_malloc(size2));
- avpicture_fill((AVPicture *)pic, picture_buf, AV_PIX_FMT_YUV420P,
- ccontext->width, ccontext->height);
- avpicture_fill((AVPicture *)picrgb, picture_buf2,AV_PIX_FMT_RGB24,
- ccontext->width, ccontext->height);
- while (av_read_frame(context, &packet) >= 0 && cnt < 1000)
- {//read 100 frames
- std::cout << "1 Frame: " << cnt << std::endl;
- if (packet.stream_index == video_stream_index)
- {//packet is video
- std::cout << "2 Is Video" << std::endl;
- if (stream == NULL)
- {//create stream in file
- std::cout << "3 create stream" << std::endl;
- stream = avformat_new_stream(oc, context-
- >streams[video_stream_index]->codec->codec);
- avcodec_copy_context(stream->codec, context-
- >streams[video_stream_index]->codec);
- stream->sample_aspect_ratio = context-
- >streams[video_stream_index]->codec->sample_aspect_ratio;
- }
- int check = 0;
- packet.stream_index = stream->id;
- std::cout << "4 decoding" << std::endl;
- int result = avcodec_decode_video2(ccontext, pic,
- &check,&packet);
- std::cout << "Bytes decoded " << result << " check " << check <<
- std::endl;
- if (cnt > 100)//cnt < 0)
- {
- sws_scale(img_convert_ctx, pic->data, pic->linesize, 0,
- ccontext->height, picrgb->data, picrgb->linesize);
- std::stringstream name;
- name << "test" << cnt << ".ppm";
- myfile.open(name.str());
- myfile << "P3 " << ccontext->width << " " << ccontext->height
- << " 255n";
- for (int y = 0; y < ccontext->height; y++)
- {
- for (int x = 0; x < ccontext->width * 3; x++)
- myfile << (int)(picrgb->
- data[0] + y * picrgb->linesize[0])[x] << " ";
- }
- myfile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement