[FFmpeg-devel] [PATCH] Codec lookup: do not use codec_id
Nicolas George
nicolas.george
Wed Aug 8 20:41:41 CEST 2007
Le primidi 21 thermidor, an CCXV, Benoit Fouet a ?crit?:
> Applied
Thanks.
> after changing the freeing of subtitles...
Oops, sorry.
Now, for the next step: use a pointer to the AVCodec instead of the CodecID
for the encoders.
I decided to do the encoders and decoders in separate patches, because that
was reasonably independent.
Regards,
--
Nicolas George
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 9983)
+++ ffmpeg.c (working copy)
@@ -1736,7 +1736,11 @@
ost = ost_table[i];
if (ost->encoding_needed) {
AVCodec *codec;
- codec = avcodec_find_encoder(ost->st->codec->codec_id);
+ codec = ost->st->codec->codec;
+ /* until here, ost->st->codec was used to store future codec
+ * parameters; now, it will be properly used as an
+ * AVCodecContext; it must therefore be reset */
+ ost->st->codec->codec = NULL;
if (!codec) {
fprintf(stderr, "Unsupported codec for output stream #%d.%d\n",
ost->file_index, ost->index);
@@ -2495,12 +2499,10 @@
input_ts_offset = parse_date(arg, 1);
}
-static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
+static AVCodec *find_codec_or_die(const char *name, int type, int encoder)
{
AVCodec *codec;
- if(!name)
- return CODEC_ID_NONE;
codec = encoder ?
avcodec_find_encoder_by_name(name) :
avcodec_find_decoder_by_name(name);
@@ -2512,7 +2514,7 @@
av_log(NULL, AV_LOG_ERROR, "Invalid codec type '%s'\n", name);
exit(1);
}
- return codec->id;
+ return codec;
}
static void opt_input_file(const char *filename)
@@ -2542,8 +2544,8 @@
ap->pix_fmt = frame_pix_fmt;
ap->channel = video_channel;
ap->standard = video_standard;
- ap->video_codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 0);
- ap->audio_codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 0);
+ ap->video_codec_id = video_codec_name ? find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 0)->id : CODEC_ID_NONE;
+ ap->audio_codec_id = audio_codec_name ? find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 0)->id : CODEC_ID_NONE;
if(pgmyuv_compatibility_hack)
ap->video_codec_id= CODEC_ID_PGMYUV;
@@ -2747,12 +2749,15 @@
int i;
AVCodec *codec;
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
- if (video_codec_name)
- codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);
-
+ if(video_codec_name) {
+ codec = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1);
+ codec_id = codec->id;
+ } else {
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
+ codec = avcodec_find_encoder(codec_id);
+ }
video_enc->codec_id = codec_id;
- codec = avcodec_find_encoder(codec_id);
+ video_enc->codec = codec;
for(i=0; i<opt_name_count; i++){
const AVOption *opt;
@@ -2865,7 +2870,7 @@
{
AVStream *st;
AVCodecContext *audio_enc;
- int codec_id, i;
+ int i;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
@@ -2895,7 +2900,13 @@
st->stream_copy = 1;
audio_enc->channels = audio_channels;
} else {
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
+ if(audio_codec_name) {
+ audio_enc->codec = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);
+ audio_enc->codec_id = audio_enc->codec->id;
+ } else {
+ audio_enc->codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
+ audio_enc->codec = avcodec_find_encoder(audio_enc->codec_id);
+ }
for(i=0; i<opt_name_count; i++){
const AVOption *opt;
@@ -2904,10 +2915,6 @@
av_set_double(audio_enc, opt_names[i], d);
}
- if (audio_codec_name)
- codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1);
- audio_enc->codec_id = codec_id;
-
if (audio_qscale > QSCALE_NONE) {
audio_enc->flags |= CODEC_FLAG_QSCALE;
audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale;
@@ -2953,7 +2960,13 @@
if(d==d && (opt->flags&AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM))
av_set_double(subtitle_enc, opt_names[i], d);
}
- subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1);
+ if(subtitle_codec_name) {
+ subtitle_enc->codec = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1);
+ subtitle_enc->codec_id = subtitle_enc->codec->id;
+ } else {
+ subtitle_enc->codec_id = CODEC_ID_NONE;
+ subtitle_enc->codec = NULL;
+ }
}
if (subtitle_language) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070808/8a05d261/attachment.pgp>
More information about the ffmpeg-devel
mailing list