You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
lavf/ffmenc: do not fail on missing codec
ffm encoder fails when codec is not found. It may happen when stream is being copied. This commit allows to store such stream and provides backward compatibility with version prior 2.5 release. fixes #4266 Signed-off-by: Lukasz Marek <lukasz.m.luki2@gmail.com>
This commit is contained in:
@@ -94,15 +94,18 @@ static void write_header_chunk(AVIOContext *pb, AVIOContext *dpb, unsigned id)
|
|||||||
av_free(dyn_buf);
|
av_free(dyn_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ffm_write_header_codec_private_ctx(AVIOContext *pb, AVCodecContext *ctx, int type)
|
static int ffm_write_header_codec_private_ctx(AVFormatContext *s, AVCodecContext *ctx, int type)
|
||||||
{
|
{
|
||||||
|
AVIOContext *pb = s->pb;
|
||||||
AVIOContext *tmp;
|
AVIOContext *tmp;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
const AVCodec *enc = ctx->codec ? ctx->codec : avcodec_find_encoder(ctx->codec_id);
|
const AVCodec *enc = ctx->codec ? ctx->codec : avcodec_find_encoder(ctx->codec_id);
|
||||||
|
|
||||||
if (!enc)
|
if (!enc) {
|
||||||
return AVERROR(EINVAL);
|
av_log(s, AV_LOG_WARNING, "Stream codec is not found. Codec private options are not stored.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (ctx->priv_data && enc->priv_class && enc->priv_data_size) {
|
if (ctx->priv_data && enc->priv_class && enc->priv_data_size) {
|
||||||
if ((ret = av_opt_serialize(ctx->priv_data, AV_OPT_FLAG_ENCODING_PARAM | type,
|
if ((ret = av_opt_serialize(ctx->priv_data, AV_OPT_FLAG_ENCODING_PARAM | type,
|
||||||
AV_OPT_SERIALIZE_SKIP_DEFAULTS, &buf, '=', ',')) < 0)
|
AV_OPT_SERIALIZE_SKIP_DEFAULTS, &buf, '=', ',')) < 0)
|
||||||
@@ -281,7 +284,7 @@ static int ffm_write_header(AVFormatContext *s)
|
|||||||
st->recommended_encoder_configuration)) < 0)
|
st->recommended_encoder_configuration)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else if ((ret = ffm_write_header_codec_ctx(s->pb, codec, MKBETAG('S', '2', 'V', 'I'), AV_OPT_FLAG_VIDEO_PARAM)) < 0 ||
|
} else if ((ret = ffm_write_header_codec_ctx(s->pb, codec, MKBETAG('S', '2', 'V', 'I'), AV_OPT_FLAG_VIDEO_PARAM)) < 0 ||
|
||||||
(ret = ffm_write_header_codec_private_ctx(s->pb, codec, AV_OPT_FLAG_VIDEO_PARAM)) < 0)
|
(ret = ffm_write_header_codec_private_ctx(s, codec, AV_OPT_FLAG_VIDEO_PARAM)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_AUDIO:
|
case AVMEDIA_TYPE_AUDIO:
|
||||||
@@ -292,7 +295,7 @@ static int ffm_write_header(AVFormatContext *s)
|
|||||||
st->recommended_encoder_configuration)) < 0)
|
st->recommended_encoder_configuration)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
} else if ((ret = ffm_write_header_codec_ctx(s->pb, codec, MKBETAG('S', '2', 'A', 'U'), AV_OPT_FLAG_AUDIO_PARAM)) < 0 ||
|
} else if ((ret = ffm_write_header_codec_ctx(s->pb, codec, MKBETAG('S', '2', 'A', 'U'), AV_OPT_FLAG_AUDIO_PARAM)) < 0 ||
|
||||||
(ret = ffm_write_header_codec_private_ctx(s->pb, codec, AV_OPT_FLAG_AUDIO_PARAM)) < 0)
|
(ret = ffm_write_header_codec_private_ctx(s, codec, AV_OPT_FLAG_AUDIO_PARAM)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user