Try all decoders not just the first one that was compiled in

This commit is contained in:
Cameron Gutman 2023-08-29 20:47:09 -05:00
parent ab53f149f2
commit c158833258

View File

@ -60,37 +60,42 @@ int ffmpeg_init(int videoFormat, int width, int height, int perf_lvl, int buffer
} }
ffmpeg_decoder = perf_lvl & VAAPI_ACCELERATION ? VAAPI : SOFTWARE; ffmpeg_decoder = perf_lvl & VAAPI_ACCELERATION ? VAAPI : SOFTWARE;
for (int try = 0; try < 6; try++) {
if (videoFormat & VIDEO_FORMAT_MASK_H264) { if (videoFormat & VIDEO_FORMAT_MASK_H264) {
if (ffmpeg_decoder == SOFTWARE) { if (ffmpeg_decoder == SOFTWARE) {
if (!decoder) decoder = avcodec_find_decoder_by_name("h264_nvv4l2"); // Tegra if (try == 0) decoder = avcodec_find_decoder_by_name("h264_nvv4l2"); // Tegra
if (!decoder) decoder = avcodec_find_decoder_by_name("h264_nvmpi"); // Tegra if (try == 1) decoder = avcodec_find_decoder_by_name("h264_nvmpi"); // Tegra
if (!decoder) decoder = avcodec_find_decoder_by_name("h264_omx"); // VisionFive if (try == 2) decoder = avcodec_find_decoder_by_name("h264_omx"); // VisionFive
if (!decoder) decoder = avcodec_find_decoder_by_name("h264_v4l2m2m"); // Stateful V4L2 if (try == 3) decoder = avcodec_find_decoder_by_name("h264_v4l2m2m"); // Stateful V4L2
} }
if (!decoder) decoder = avcodec_find_decoder_by_name("h264"); // Software and hwaccel if (try == 4) decoder = avcodec_find_decoder_by_name("h264"); // Software and hwaccel
} else if (videoFormat & VIDEO_FORMAT_MASK_H265) { } else if (videoFormat & VIDEO_FORMAT_MASK_H265) {
if (ffmpeg_decoder == SOFTWARE) { if (ffmpeg_decoder == SOFTWARE) {
if (!decoder) decoder = avcodec_find_decoder_by_name("hevc_nvv4l2"); // Tegra if (try == 0) decoder = avcodec_find_decoder_by_name("hevc_nvv4l2"); // Tegra
if (!decoder) decoder = avcodec_find_decoder_by_name("hevc_nvmpi"); // Tegra if (try == 1) decoder = avcodec_find_decoder_by_name("hevc_nvmpi"); // Tegra
if (!decoder) decoder = avcodec_find_decoder_by_name("hevc_omx"); // VisionFive if (try == 2) decoder = avcodec_find_decoder_by_name("hevc_omx"); // VisionFive
if (!decoder) decoder = avcodec_find_decoder_by_name("hevc_v4l2m2m"); // Stateful V4L2 if (try == 3) decoder = avcodec_find_decoder_by_name("hevc_v4l2m2m"); // Stateful V4L2
} }
if (!decoder) decoder = avcodec_find_decoder_by_name("hevc"); // Software and hwaccel if (try == 4) decoder = avcodec_find_decoder_by_name("hevc"); // Software and hwaccel
} else if (videoFormat & VIDEO_FORMAT_MASK_AV1) {
if (ffmpeg_decoder == SOFTWARE) {
if (try == 0) decoder = avcodec_find_decoder_by_name("libdav1d");
}
if (try == 1) decoder = avcodec_find_decoder_by_name("av1"); // Hwaccel
} else { } else {
printf("Video format not supported\n"); printf("Video format not supported\n");
return -1; return -1;
} }
if (decoder == NULL) { // Skip this decoder if it isn't compiled into FFmpeg
printf("Couldn't find decoder\n"); if (!decoder) {
return -1; continue;
} }
printf("Using FFmpeg decoder: %s\n", decoder->name);
decoder_ctx = avcodec_alloc_context3(decoder); decoder_ctx = avcodec_alloc_context3(decoder);
if (decoder_ctx == NULL) { if (decoder_ctx == NULL) {
printf("Couldn't allocate context"); printf("Couldn't allocate context\n");
return -1; return -1;
} }
@ -117,9 +122,17 @@ int ffmpeg_init(int videoFormat, int width, int height, int perf_lvl, int buffer
int err = avcodec_open2(decoder_ctx, decoder, NULL); int err = avcodec_open2(decoder_ctx, decoder, NULL);
if (err < 0) { if (err < 0) {
printf("Couldn't open codec"); printf("Couldn't open codec: %s\n", decoder->name);
return err; continue;
} }
}
if (decoder == NULL) {
printf("Couldn't find decoder\n");
return -1;
}
printf("Using FFmpeg decoder: %s\n", decoder->name);
dec_frames_cnt = buffer_count; dec_frames_cnt = buffer_count;
dec_frames = malloc(buffer_count * sizeof(AVFrame*)); dec_frames = malloc(buffer_count * sizeof(AVFrame*));