Commit d6cb1346 authored by digulla's avatar digulla Committed by John Stebbins

Better error message when avcodec_find_encoder_by_name() fails (#2252)

* Better error message when avcodec_find_encoder_by_name() fails

* Gracefully fail when the code in the job setup and the switch here get out of sync.
parent 78399ddc
......@@ -102,6 +102,7 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
{
int ret = 0;
char reason[80];
char * codec_name = NULL;
AVCodec * codec = NULL;
AVCodecContext * context;
AVRational fps;
......@@ -121,37 +122,37 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
case AV_CODEC_ID_MPEG4:
{
hb_log("encavcodecInit: MPEG-4 ASP encoder");
codec = avcodec_find_encoder_by_name("mpeg4");
codec_name = "mpeg4";
} break;
case AV_CODEC_ID_MPEG2VIDEO:
{
hb_log("encavcodecInit: MPEG-2 encoder");
codec = avcodec_find_encoder_by_name("mpeg2video");
codec_name = "mpeg2video";
} break;
case AV_CODEC_ID_VP8:
{
hb_log("encavcodecInit: VP8 encoder");
codec = avcodec_find_encoder_by_name("libvpx");
codec_name = "libvpx";
} break;
case AV_CODEC_ID_VP9:
{
hb_log("encavcodecInit: VP9 encoder");
codec = avcodec_find_encoder_by_name("libvpx-vp9");
codec_name = "libvpx-vp9";
} break;
case AV_CODEC_ID_H264:
{
switch (job->vcodec) {
case HB_VCODEC_FFMPEG_NVENC_H264:
hb_log("encavcodecInit: H.264 (Nvidia NVENC)");
codec = avcodec_find_encoder_by_name("h264_nvenc");
codec_name = "h264_nvenc";
break;
case HB_VCODEC_FFMPEG_VCE_H264:
hb_log("encavcodecInit: H.264 (AMD VCE)");
codec = avcodec_find_encoder_by_name("h264_amf");
codec_name = "h264_amf";
break;
case HB_VCODEC_FFMPEG_VT_H264:
hb_log("encavcodecInit: H.264 (VideoToolbox)");
codec = avcodec_find_encoder_by_name("h264_videotoolbox");
codec_name = "h264_videotoolbox";
break;
}
}break;
......@@ -160,30 +161,36 @@ int encavcodecInit( hb_work_object_t * w, hb_job_t * job )
switch (job->vcodec) {
case HB_VCODEC_FFMPEG_NVENC_H265:
hb_log("encavcodecInit: H.265 (Nvidia NVENC)");
codec = avcodec_find_encoder_by_name("hevc_nvenc");
codec_name = "hevc_nvenc";
break;
case HB_VCODEC_FFMPEG_VCE_H265:
hb_log("encavcodecInit: H.265 (AMD VCE)");
codec = avcodec_find_encoder_by_name("hevc_amf");
codec_name = "hevc_amf";
break;
case HB_VCODEC_FFMPEG_VT_H265:
hb_log("encavcodecInit: H.265 (VideoToolbox)");
codec = avcodec_find_encoder_by_name("hevc_videotoolbox");
codec_name = "hevc_videotoolbox";
break;
}
}break;
default:
{
hb_error("encavcodecInit: unsupported encoder!");
ret = 1;
goto done;
}
}
if (codec_name == NULL)
{
// Catch all when the switch above fails
hb_log( "encavcodecInit: Unable to determine codec_name "
"from hb_work_object_t.codec_param=%d and "
"hb_job_t.vcodec=%x", w->codec_param,
job->vcodec );
ret = 1;
goto done;
}
codec = avcodec_find_encoder_by_name(codec_name);
if( !codec )
{
hb_log( "encavcodecInit: avcodec_find_encoder "
"failed" );
hb_log( "encavcodecInit: avcodec_find_encoder_by_name(%s) "
"failed", codec_name );
ret = 1;
goto done;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment