diff options
author | digulla <[email protected]> | 2019-08-21 17:57:31 +0200 |
---|---|---|
committer | John Stebbins <[email protected]> | 2019-08-21 08:57:31 -0700 |
commit | d6cb1346460fb016df525637ffcc10ff65530d44 (patch) | |
tree | 6cd58dcc459b5ecf09b84af458e1a21526854391 /libhb | |
parent | 78399ddc40b4938f201036bee48bef7c64b715f2 (diff) |
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.
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/encavcodec.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/libhb/encavcodec.c b/libhb/encavcodec.c index 0dcafcadb..c1b5fe07e 100644 --- a/libhb/encavcodec.c +++ b/libhb/encavcodec.c @@ -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; } |