diff --git a/ffmpeg/ffmpeg_errors.go b/ffmpeg/ffmpeg_errors.go index f592a65035..c0a3645d52 100644 --- a/ffmpeg/ffmpeg_errors.go +++ b/ffmpeg/ffmpeg_errors.go @@ -37,6 +37,7 @@ func error_map() map[int]error { {code: C.lpms_ERR_FILTERS, desc: "Error initializing filtergraph"}, {code: C.lpms_ERR_OUTPUTS, desc: "Too many outputs"}, {code: C.lpms_ERR_DTS, desc: "Segment out of order"}, + {code: C.lpms_ERR_INPUT_CODEC, desc: "Unsupported input codec"}, } for _, v := range lpmsErrors { m[int(v.code)] = errors.New(v.desc) diff --git a/ffmpeg/lpms_ffmpeg.c b/ffmpeg/lpms_ffmpeg.c index 16324f08bb..060c6e4755 100644 --- a/ffmpeg/lpms_ffmpeg.c +++ b/ffmpeg/lpms_ffmpeg.c @@ -11,6 +11,7 @@ // Not great to appropriate internal API like this... const int lpms_ERR_INPUT_PIXFMT = FFERRTAG('I','N','P','X'); +const int lpms_ERR_INPUT_CODEC = FFERRTAG('I','N','P','C'); const int lpms_ERR_FILTERS = FFERRTAG('F','L','T','R'); const int lpms_ERR_PACKET_ONLY = FFERRTAG('P','K','O','N'); const int lpms_ERR_OUTPUTS = FFERRTAG('O','U','T','P'); @@ -833,8 +834,11 @@ static int open_video_decoder(input_params *params, struct input_ctx *ctx) else if (ctx->vi < 0) { fprintf(stderr, "No video stream found in input\n"); } else { - if (AV_CODEC_ID_H264 == codec->id && - AV_HWDEVICE_TYPE_CUDA == params->hw_type) { + if (AV_HWDEVICE_TYPE_CUDA == params->hw_type) { + if (AV_CODEC_ID_H264 != codec->id) { + ret = lpms_ERR_INPUT_CODEC; + dd_err("Non H264 codec detected in input\n"); + } AVCodec *c = avcodec_find_decoder_by_name("h264_cuvid"); if (c) codec = c; else fprintf(stderr, "Cuvid decoder not found; defaulting to software\n"); diff --git a/ffmpeg/lpms_ffmpeg.h b/ffmpeg/lpms_ffmpeg.h index fc0bd069d7..4e74ccae62 100644 --- a/ffmpeg/lpms_ffmpeg.h +++ b/ffmpeg/lpms_ffmpeg.h @@ -6,6 +6,7 @@ // LPMS specific errors extern const int lpms_ERR_INPUT_PIXFMT; +extern const int lpms_ERR_INPUT_CODEC; extern const int lpms_ERR_FILTERS; extern const int lpms_ERR_OUTPUTS; extern const int lpms_ERR_DTS; diff --git a/ffmpeg/nvidia_test.go b/ffmpeg/nvidia_test.go index 0cf946d981..593599e29f 100644 --- a/ffmpeg/nvidia_test.go +++ b/ffmpeg/nvidia_test.go @@ -96,6 +96,43 @@ func TestNvidia_Transcoding(t *testing.T) { } +func TestNvidia_BadCodecs(t *testing.T) { + // Following test case validates that the transcoder throws correct errors for unsupported codecs + // Currently only H264 is supported + + run, dir := setupTest(t) + defer os.RemoveAll(dir) + + fname := dir + "/mpeg2.ts" + oname := dir + "/out.ts" + prof := P240p30fps16x9 + + cmd := ` + cp "$1/../transcoder/test.ts" test.ts + # Generate an input file that is not H264 (mpeg2) and sanity check + ffmpeg -loglevel warning -i test.ts -an -c:v mpeg2video -t 1 mpeg2.ts + ffprobe -loglevel warning mpeg2.ts -show_streams | grep codec_name=mpeg2video + ` + run(cmd) + + // sanity check + err := Transcode2(&TranscodeOptionsIn{ + Fname: fname, + Accel: Nvidia, + }, []TranscodeOptions{ + { + Oname: oname, + Profile: prof, + Accel: Nvidia, + }, + }) + + if err == nil || err.Error() != "Unsupported input codec" { + t.Error(err) + } + +} + func TestNvidia_Pixfmts(t *testing.T) { // Following test case validates pixel format at the decoding end