Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /* find the video decoder */
  2. if (!(pCodec=avcodec_find_decoder_by_name("h264_mediacodec"))){ //first find the h264_mediacodec
  3. LOGD("h264_mediacodec not found, using h264");
  4. if (!(pCodec=avcodec_find_decoder(AV_CODEC_ID_H264))){ //AV_CODEC_ID_H264 AV_CODEC_ID_HEVC
  5. LOGD("codec not found!");
  6. goto ERROR;
  7. }
  8. }
  9. else
  10. LOGD("using h264_mediacodec");
  11.  
  12. pCodecCtx = avcodec_alloc_context3(pCodec);
  13. /*pCodecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
  14. pCodecCtx->codec_id = AV_CODEC_ID_H264;
  15. pCodecCtx->profile = FF_PROFILE_H264_MAIN;
  16. pCodecCtx->coded_width = 1280;
  17. pCodecCtx->coded_height = 720;
  18. pCodecCtx->pix_fmt = AV_PIX_FMT_YUV420P;
  19. pCodecCtx->extradata = NULL;
  20. pCodecCtx->extradata_size = 0;*/
  21. av_opt_set_int(pCodecCtx, "refcounted_frames", 1, 0);
  22. av_opt_set(pCodecCtx, "threads", "auto", 0);
  23. pCodecCtx->codec_id = AV_CODEC_ID_H264;
  24. pCodecCtx->get_format = mediacodec_hwaccel_get_format;
  25. pCodecCtx->thread_count = 1;
  26.  
  27. pFrame = av_frame_alloc();// Allocate video frame
  28. if((pCodecCtx == NULL)||(pFrame == NULL))
  29. {
  30. LOGD("pCodecCtx or pFrame alloc fail");
  31. goto ERROR;
  32. }
  33.  
  34. int ret = avcodec_open2(pCodecCtx, pCodec, NULL);
  35. if ( ret < 0) {
  36. LOGD("could not open codec %d", ret);
  37. goto ERROR;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement