解决ijklayer 多路码流时默认播放h265

1. 背景

1.1 ijkplayer 编译完成后是默认播放小码流的即h264 ,如下面的代码所示,但如果需求是播大码流即h265时,通过IJKFFOption好像不行。此时可以更改编译后的IJKMediaFramework源码实现

 // choose first h264

        if (type == AVMEDIA_TYPE_VIDEO) {
            enum AVCodecID codec_id = st->codecpar->codec_id;
            video_stream_count++;
            if (codec_id == AV_CODEC_ID_H264) {
                h264_stream_count++;
                if (first_h264_stream < 0)
                    first_h264_stream = i;
            }

2.源码更改

2.1 打开工程位置/ijkplayer-ios/ios/IJKMediaPlayer/IJKMediaPlayer.xcodeproj
2.2 修改ff_ffplay.c文件中read_thread方法,增加if判断

if (type == AVMEDIA_TYPE_VIDEO) {
        enum AVCodecID codec_id = st->codecpar->codec_id;
        video_stream_count++;
        if (codec_id == AV_CODEC_ID_H264) {
            h264_stream_count++;
            if (first_h264_stream < 0)
                first_h264_stream = i;
        }

 //修改当多路码流时默认选择大码流h265
        if(codec_id == AV_CODEC_ID_HEVC){  // edit
            if(first_h265_stream<0){
                first_h265_stream = i;
            }
            
        }
         }
     }
    
      if (video_stream_count > 1 && st_index[AVMEDIA_TYPE_VIDEO] < 0) { 
             if(first_h265_stream >=0){    //edit
            st_index[AVMEDIA_TYPE_VIDEO] = first_h265_stream;
            av_log(NULL, 16  , "multiple video stream found, prefer first h265 stream: %d\n", 
    first_h264_stream);
    }else{
            st_index[AVMEDIA_TYPE_VIDEO] = first_h264_stream;
            av_log(NULL, 16  , "multiple video stream found, prefer first h264 stream: %d\n", 
  first_h264_stream);
   
      }
}

你可能感兴趣的:(解决ijklayer 多路码流时默认播放h265)