mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-28 20:53:54 +02:00
fftools/ffmpeg: return errors from find_codec_or_die() instead of aborting
Rename the function to just find_codec().
This commit is contained in:
parent
2e6afa799e
commit
6c6f13baf3
@ -709,8 +709,8 @@ void assert_avoptions(AVDictionary *m);
|
|||||||
int assert_file_overwrite(const char *filename);
|
int assert_file_overwrite(const char *filename);
|
||||||
char *file_read(const char *filename);
|
char *file_read(const char *filename);
|
||||||
AVDictionary *strip_specifiers(const AVDictionary *dict);
|
AVDictionary *strip_specifiers(const AVDictionary *dict);
|
||||||
const AVCodec *find_codec_or_die(void *logctx, const char *name,
|
int find_codec(void *logctx, const char *name,
|
||||||
enum AVMediaType type, int encoder);
|
enum AVMediaType type, int encoder, const AVCodec **codec);
|
||||||
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
|
int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global);
|
||||||
|
|
||||||
int check_filter_outputs(void);
|
int check_filter_outputs(void);
|
||||||
|
@ -911,19 +911,22 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
|
static int choose_decoder(const OptionsContext *o, AVFormatContext *s, AVStream *st,
|
||||||
enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type)
|
enum HWAccelID hwaccel_id, enum AVHWDeviceType hwaccel_device_type,
|
||||||
|
const AVCodec **pcodec)
|
||||||
|
|
||||||
{
|
{
|
||||||
char *codec_name = NULL;
|
char *codec_name = NULL;
|
||||||
|
|
||||||
MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
|
MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
|
||||||
if (codec_name) {
|
if (codec_name) {
|
||||||
const AVCodec *codec = find_codec_or_die(NULL, codec_name, st->codecpar->codec_type, 0);
|
int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
|
||||||
st->codecpar->codec_id = codec->id;
|
if (ret < 0)
|
||||||
if (recast_media && st->codecpar->codec_type != codec->type)
|
return ret;
|
||||||
st->codecpar->codec_type = codec->type;
|
st->codecpar->codec_id = (*pcodec)->id;
|
||||||
return codec;
|
if (recast_media && st->codecpar->codec_type != (*pcodec)->type)
|
||||||
|
st->codecpar->codec_type = (*pcodec)->type;
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
|
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
|
||||||
hwaccel_id == HWACCEL_GENERIC &&
|
hwaccel_id == HWACCEL_GENERIC &&
|
||||||
@ -942,13 +945,15 @@ static const AVCodec *choose_decoder(const OptionsContext *o, AVFormatContext *s
|
|||||||
if (config->device_type == hwaccel_device_type) {
|
if (config->device_type == hwaccel_device_type) {
|
||||||
av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
|
av_log(NULL, AV_LOG_VERBOSE, "Selecting decoder '%s' because of requested hwaccel method %s\n",
|
||||||
c->name, av_hwdevice_get_type_name(hwaccel_device_type));
|
c->name, av_hwdevice_get_type_name(hwaccel_device_type));
|
||||||
return c;
|
*pcodec = c;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return avcodec_find_decoder(st->codecpar->codec_id);
|
*pcodec = avcodec_find_decoder(st->codecpar->codec_id);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1166,7 +1171,11 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ist->dec = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type);
|
ret = choose_decoder(o, ic, st, ist->hwaccel_id, ist->hwaccel_device_type,
|
||||||
|
&ist->dec);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
|
ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
|
||||||
|
|
||||||
ist->reinit_filters = -1;
|
ist->reinit_filters = -1;
|
||||||
@ -1357,7 +1366,7 @@ int ifile_open(const OptionsContext *o, const char *filename)
|
|||||||
InputFile *f;
|
InputFile *f;
|
||||||
AVFormatContext *ic;
|
AVFormatContext *ic;
|
||||||
const AVInputFormat *file_iformat = NULL;
|
const AVInputFormat *file_iformat = NULL;
|
||||||
int err, i, ret;
|
int err, i, ret = 0;
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
AVDictionary *unused_opts = NULL;
|
AVDictionary *unused_opts = NULL;
|
||||||
const AVDictionaryEntry *e = NULL;
|
const AVDictionaryEntry *e = NULL;
|
||||||
@ -1455,13 +1464,19 @@ int ifile_open(const OptionsContext *o, const char *filename)
|
|||||||
MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
|
MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
|
||||||
|
|
||||||
if (video_codec_name)
|
if (video_codec_name)
|
||||||
ic->video_codec = find_codec_or_die(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
|
ret = err_merge(ret, find_codec(NULL, video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
|
||||||
|
&ic->video_codec));
|
||||||
if (audio_codec_name)
|
if (audio_codec_name)
|
||||||
ic->audio_codec = find_codec_or_die(NULL, audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
|
ret = err_merge(ret, find_codec(NULL, audio_codec_name , AVMEDIA_TYPE_AUDIO , 0,
|
||||||
|
&ic->audio_codec));
|
||||||
if (subtitle_codec_name)
|
if (subtitle_codec_name)
|
||||||
ic->subtitle_codec = find_codec_or_die(NULL, subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
|
ret = err_merge(ret, find_codec(NULL, subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0,
|
||||||
|
&ic->subtitle_codec));
|
||||||
if (data_codec_name)
|
if (data_codec_name)
|
||||||
ic->data_codec = find_codec_or_die(NULL, data_codec_name , AVMEDIA_TYPE_DATA , 0);
|
ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
|
||||||
|
&ic->data_codec));
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
|
ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
|
||||||
ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
|
ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
|
||||||
@ -1496,8 +1511,13 @@ int ifile_open(const OptionsContext *o, const char *filename)
|
|||||||
assert_avoptions(o->g->format_opts);
|
assert_avoptions(o->g->format_opts);
|
||||||
|
|
||||||
/* apply forced codec ids */
|
/* apply forced codec ids */
|
||||||
for (i = 0; i < ic->nb_streams; i++)
|
for (i = 0; i < ic->nb_streams; i++) {
|
||||||
choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE);
|
const AVCodec *dummy;
|
||||||
|
ret = choose_decoder(o, ic, ic->streams[i], HWACCEL_NONE, AV_HWDEVICE_TYPE_NONE,
|
||||||
|
&dummy);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (o->find_stream_info) {
|
if (o->find_stream_info) {
|
||||||
AVDictionary **opts;
|
AVDictionary **opts;
|
||||||
|
@ -139,7 +139,9 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
|
|||||||
return AVERROR_ENCODER_NOT_FOUND;
|
return AVERROR_ENCODER_NOT_FOUND;
|
||||||
}
|
}
|
||||||
} else if (strcmp(codec_name, "copy")) {
|
} else if (strcmp(codec_name, "copy")) {
|
||||||
*enc = find_codec_or_die(ost, codec_name, ost->type, 1);
|
int ret = find_codec(ost, codec_name, ost->type, 1, enc);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
ost->par_in->codec_id = (*enc)->id;
|
ost->par_in->codec_id = (*enc)->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,8 +637,8 @@ static int opt_recording_timestamp(void *optctx, const char *opt, const char *ar
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AVCodec *find_codec_or_die(void *logctx, const char *name,
|
int find_codec(void *logctx, const char *name,
|
||||||
enum AVMediaType type, int encoder)
|
enum AVMediaType type, int encoder, const AVCodec **pcodec)
|
||||||
{
|
{
|
||||||
const AVCodecDescriptor *desc;
|
const AVCodecDescriptor *desc;
|
||||||
const char *codec_string = encoder ? "encoder" : "decoder";
|
const char *codec_string = encoder ? "encoder" : "decoder";
|
||||||
@ -658,13 +658,16 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name,
|
|||||||
|
|
||||||
if (!codec) {
|
if (!codec) {
|
||||||
av_log(logctx, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
|
av_log(logctx, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
|
||||||
exit_program(1);
|
return encoder ? AVERROR_ENCODER_NOT_FOUND :
|
||||||
|
AVERROR_DECODER_NOT_FOUND;
|
||||||
}
|
}
|
||||||
if (codec->type != type && !recast_media) {
|
if (codec->type != type && !recast_media) {
|
||||||
av_log(logctx, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
|
av_log(logctx, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
|
||||||
exit_program(1);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
return codec;
|
|
||||||
|
*pcodec = codec;
|
||||||
|
return 0;;
|
||||||
}
|
}
|
||||||
|
|
||||||
int assert_file_overwrite(const char *filename)
|
int assert_file_overwrite(const char *filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user