[FFmpeg-devel] [PATCH] Codec lookup: do not use codec_id

Nicolas George nicolas.george
Wed Aug 22 15:54:08 CEST 2007


Hi.

Le primidi 21 thermidor, an CCXV, Nicolas George a ?crit?:
> 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.

This patch does no longer apply cleanly after Reimar D?ffinger's patch
(r10142). Here is an updated version.

I hope someone will have time to review it: there seemed to be consensus
that the current codec lookup had to be corrected, and there are more steps
ahead.


By the way, the regression tests are broken in current (r10184) version:

-82ba2aa56763242ccfc6cd95a79673e3 *./tests/data/out.yuv
+b19cb7f9134f922326028c6bb44e96de *./tests/data/out.yuv


Regards,

-- 
  Nicolas George
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revision 10184)
+++ ffmpeg.c	(working copy)
@@ -1744,7 +1744,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);
@@ -2511,13 +2515,11 @@
     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)
 {
     char *codec_string = encoder ? "encoder" : "decoder";
     AVCodec *codec;
 
-    if(!name)
-        return CODEC_ID_NONE;
     codec = encoder ?
         avcodec_find_encoder_by_name(name) :
         avcodec_find_decoder_by_name(name);
@@ -2529,7 +2531,7 @@
         av_log(NULL, AV_LOG_ERROR, "Invalid %s type '%s'\n", codec_string, name);
         exit(1);
     }
-    return codec->id;
+    return codec;
 }
 
 static void opt_input_file(const char *filename)
@@ -2559,8 +2561,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;
 
@@ -2764,12 +2766,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;
@@ -2882,7 +2887,7 @@
 {
     AVStream *st;
     AVCodecContext *audio_enc;
-    int codec_id, i;
+    int i;
 
     st = av_new_stream(oc, oc->nb_streams);
     if (!st) {
@@ -2912,7 +2917,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;
@@ -2921,10 +2932,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;
@@ -2970,7 +2977,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/20070822/9b5a9733/attachment.pgp>



More information about the ffmpeg-devel mailing list