[FFmpeg-devel] [PATCH] Codec lookup: do not use codec_id
Nicolas George
nicolas.george
Wed Jul 4 16:43:31 CEST 2007
Hi.
Here is an updated version of the patch, to take the remarks into account.
I added a comment about the hackish use of the AVCodecContext structure
(the hack was there before me; my patch just makes it a little more
visible).
I did the following tests:
a=~/fichiers/video/Cortex_Academy.mov (adpcm_ima_qt+svq3)
b=~/fichiers/video/TheChubChubs.avi (msmpeg4+mp3)
./ffmpeg -i $a /tmp/t1.avi -newvideo -i $b
-> works
(the result is not exactly identical as with an unpatched ffmpeg, but two
runs of an unpatched ffmpeg give similar differences (mostly, on the exact
size of frames, I assume this is normal behavior)
./ffmpeg -i $a /tmp/t1.avi -newaudio -i $b
-> works; this time, the result is absolutely identical to unpatched ffmpeg.
./ffmpeg -i $a -acodec mp2 -vcodec mpeg4 /tmp/t1a.avi \
-acodec ac3 -vcodec mpeg2video /tmp/t1b.avi
-> works, both output files are absolutely identical to unpatched ffmpeg.
./ffmpeg -i $b -acodec copy -vcodec copy /tmp/t1.avi
-> works, result absolutely identical to unpatched ffmpeg.
./ffmpeg -i $a -acodec copy -vcodec copy /tmp/t1.mov
-> works, result absolutely identical to unpatched ffmpeg.
Rebuilt with --disable-encoders --disable-decoders,
./ffmpeg -i $b -acodec copy -vcodec copy /tmp/t1.avi
./ffmpeg -i $a -acodec copy -vcodec copy /tmp/t1.mov
-> works, result absolutely identical to unpatched ffmpeg.
Rebuilt with --enable-gpl, make fulltest fails both with the patched and
unpatched version, and they fail both in exactly the same way
(tests/data/*.regression identical).
I think it shows that I did not break anything.
Regards,
--
Nicolas George
Suggest log message:
Use directly the codec instead of the codec_id whenever possible.
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 9470)
+++ ffmpeg.c (working copy)
@@ -130,7 +130,7 @@
static int me_method = ME_EPZS;
static int video_disable = 0;
static int video_discard = 0;
-static int video_codec_id = CODEC_ID_NONE;
+static AVCodec *video_codec = NULL;
static int video_codec_tag = 0;
static int same_quality = 0;
static int do_deinterlace = 0;
@@ -148,11 +148,11 @@
static float audio_qscale = QSCALE_NONE;
static int audio_disable = 0;
static int audio_channels = 1;
-static int audio_codec_id = CODEC_ID_NONE;
+static AVCodec *audio_codec = NULL;
static int audio_codec_tag = 0;
static char *audio_language = NULL;
-static int subtitle_codec_id = CODEC_ID_NONE;
+static AVCodec *subtitle_codec = NULL;
static char *subtitle_language = NULL;
static float mux_preload= 0.5;
@@ -1722,7 +1722,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);
@@ -1742,7 +1746,13 @@
ist = ist_table[i];
if (ist->decoding_needed) {
AVCodec *codec;
- codec = avcodec_find_decoder(ist->st->codec->codec_id);
+ codec = ist->st->codec->codec;
+ if(codec == NULL)
+ codec = avcodec_find_decoder(ist->st->codec->codec_id);
+ /* 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 */
+ ist->st->codec->codec = NULL;
if (!codec) {
fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n",
ist->st->codec->codec_id, ist->file_index, ist->index);
@@ -2350,7 +2360,7 @@
video_standard = av_strdup(arg);
}
-static void opt_codec(int *pstream_copy, int *pcodec_id,
+static void opt_codec(int *pstream_copy, AVCodec **pcodec,
int codec_type, const char *arg)
{
AVCodec *p;
@@ -2368,14 +2378,14 @@
fprintf(stderr, "Unknown codec '%s'\n", arg);
exit(1);
} else {
- *pcodec_id = p->id;
+ *pcodec = p;
}
}
}
static void opt_audio_codec(const char *arg)
{
- opt_codec(&audio_stream_copy, &audio_codec_id, CODEC_TYPE_AUDIO, arg);
+ opt_codec(&audio_stream_copy, &audio_codec, CODEC_TYPE_AUDIO, arg);
}
static void opt_audio_tag(const char *arg)
@@ -2448,12 +2458,12 @@
static void opt_video_codec(const char *arg)
{
- opt_codec(&video_stream_copy, &video_codec_id, CODEC_TYPE_VIDEO, arg);
+ opt_codec(&video_stream_copy, &video_codec, CODEC_TYPE_VIDEO, arg);
}
static void opt_subtitle_codec(const char *arg)
{
- opt_codec(&subtitle_stream_copy, &subtitle_codec_id, CODEC_TYPE_SUBTITLE, arg);
+ opt_codec(&subtitle_stream_copy, &subtitle_codec, CODEC_TYPE_SUBTITLE, arg);
}
static void opt_map(const char *arg)
@@ -2543,8 +2553,8 @@
ap->pix_fmt = frame_pix_fmt;
ap->channel = video_channel;
ap->standard = video_standard;
- ap->video_codec_id = video_codec_id;
- ap->audio_codec_id = audio_codec_id;
+ ap->video_codec_id = video_codec == NULL ? CODEC_ID_NONE : video_codec->id;
+ ap->audio_codec_id = audio_codec == NULL ? CODEC_ID_NONE : audio_codec->id;
if(pgmyuv_compatibility_hack)
ap->video_codec_id= CODEC_ID_PGMYUV;
@@ -2704,7 +2714,6 @@
{
AVStream *st;
AVCodecContext *video_enc;
- int codec_id;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
@@ -2741,13 +2750,16 @@
int i;
AVCodec *codec;
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
- if (video_codec_id != CODEC_ID_NONE)
- codec_id = video_codec_id;
+ if(video_codec == NULL) {
+ int codec_id;
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO);
+ codec = avcodec_find_encoder(codec_id);
+ } else {
+ codec = video_codec;
+ }
+ video_enc->codec = codec;
+ video_enc->codec_id = codec == NULL ? CODEC_ID_NONE : codec->id;
- video_enc->codec_id = codec_id;
- codec = avcodec_find_encoder(codec_id);
-
for(i=0; i<opt_name_count; i++){
const AVOption *opt;
double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt);
@@ -2853,7 +2865,7 @@
/* reset some key parameters */
video_disable = 0;
- video_codec_id = CODEC_ID_NONE;
+ video_codec = NULL;
video_stream_copy = 0;
}
@@ -2861,7 +2873,7 @@
{
AVStream *st;
AVCodecContext *audio_enc;
- int codec_id, i;
+ int i;
st = av_new_stream(oc, oc->nb_streams);
if (!st) {
@@ -2891,7 +2903,15 @@
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 == NULL) {
+ int codec_id;
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO);
+ audio_enc->codec = avcodec_find_encoder(codec_id);
+ audio_enc->codec_id = codec_id;
+ } else {
+ audio_enc->codec = audio_codec;
+ audio_enc->codec_id = audio_codec->id;
+ }
for(i=0; i<opt_name_count; i++){
const AVOption *opt;
@@ -2900,9 +2920,6 @@
av_set_double(audio_enc, opt_names[i], d);
}
- if (audio_codec_id != CODEC_ID_NONE)
- codec_id = audio_codec_id;
- audio_enc->codec_id = codec_id;
if (audio_qscale > QSCALE_NONE) {
audio_enc->flags |= CODEC_FLAG_QSCALE;
@@ -2921,7 +2938,7 @@
/* reset some key parameters */
audio_disable = 0;
- audio_codec_id = CODEC_ID_NONE;
+ audio_codec = NULL;
audio_stream_copy = 0;
}
@@ -2956,7 +2973,7 @@
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 = subtitle_codec_id;
+ subtitle_enc->codec = subtitle_codec;
}
if (subtitle_language) {
@@ -2965,7 +2982,7 @@
subtitle_language = NULL;
}
- subtitle_codec_id = CODEC_ID_NONE;
+ subtitle_codec = NULL;
subtitle_stream_copy = 0;
}
@@ -3023,8 +3040,8 @@
exit(1);
}
} else {
- use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_id != CODEC_ID_NONE;
- use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_id != CODEC_ID_NONE;
+ use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec != NULL;
+ use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec != NULL;
/* disable if no corresponding type found and at least one
input file */
-------------- 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/20070704/8c620c68/attachment.pgp>
More information about the ffmpeg-devel
mailing list