解決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);
   
      }
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容