Elan Ruusamäe - 2011-01-05

from code debugging it seems that avcodec_open in _php_get_decoder_context overwrites the avcodecontext

ffmpeg_movie.c :
static AVCodecContext* _php_get_decoder_context(ff_movie_context *ffmovie_ctx, int stream_type)
....
/* open the decoder */
if (avcodec_open(ffmovie_ctx->codec_ctx[stream_index], decoder) < 0) {
zend_error(E_WARNING, "Could not open codec for %s", _php_get_filename(ffmovie_ctx));
return NULL;
}

to use temp buffer there would solve the problem, but then calling whole method becames pointless, isn't it?

i.e such patch:
--- ffmpeg-php-0.6.0/ffmpeg_movie.c~ 2011-01-05 18:58:27.000000000 +0200
+++ ffmpeg-php-0.6.0/ffmpeg_movie.c 2011-01-05 18:58:34.572647878 +0200
@@ -510,10 +510,12 @@
GET_CODEC_PTR(ffmovie_ctx->fmt_ctx->streams[stream_index]->codec);

/* open the decoder */
- if (avcodec_open(ffmovie_ctx->codec_ctx[stream_index], decoder) < 0) {
+ AVCodecContext *ctx = avcodec_alloc_context();
+ if (avcodec_open(ctx, decoder) < 0) {
zend_error(E_WARNING, "Could not open codec for %s", _php_get_filename(ffmovie_ctx));
return NULL;
}
+ av_freep(&ctx);
}
return ffmovie_ctx->codec_ctx[stream_index];
}