AVFilterBufferRef *picref;
/* audio-only fields */
- void *samples_buf;
- int samples_buf_size;
int bps; ///< bytes per sample
AVPacket pkt, pkt0;
AVFilterBufferRef *samplesref;
movie->seek_point, movie->format_name, movie->file_name,
movie->stream_index);
+ if (!(movie->frame = avcodec_alloc_frame()) ) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to alloc frame\n");
+ return AVERROR(ENOMEM);
+ }
+
return 0;
}
if (movie->codec_ctx)
avcodec_close(movie->codec_ctx);
if (movie->format_ctx)
- av_close_input_file(movie->format_ctx);
+ avformat_close_input(&movie->format_ctx);
avfilter_unref_buffer(movie->picref);
av_freep(&movie->frame);
avfilter_unref_buffer(movie->samplesref);
- av_freep(&movie->samples_buf);
}
#if CONFIG_MOVIE_FILTER
if ((ret = movie_common_init(ctx, args, opaque, AVMEDIA_TYPE_VIDEO)) < 0)
return ret;
- if (!(movie->frame = avcodec_alloc_frame()) ) {
- av_log(ctx, AV_LOG_ERROR, "Failed to alloc frame\n");
- return AVERROR(ENOMEM);
- }
-
movie->w = movie->codec_ctx->width;
movie->h = movie->codec_ctx->height;
/* use pkt_dts if pkt_pts is not available */
movie->picref->pts = movie->frame->pkt_pts == AV_NOPTS_VALUE ?
movie->frame->pkt_dts : movie->frame->pkt_pts;
+
if (!movie->frame->sample_aspect_ratio.num)
movie->picref->video->sample_aspect_ratio = st->sample_aspect_ratio;
av_dlog(outlink->src,
{
MovieContext *movie = outlink->src->priv;
AVPacket pkt;
- int ret, samples_size, decoded_data_size;
+ int ret, got_frame = 0;
if (!movie->pkt.size && movie->is_done == 1)
return AVERROR_EOF;
}
}
- /* reallocate the buffer for the decoded samples, if necessary */
- samples_size =
- FFMAX(movie->pkt.size*sizeof(movie->bps), AVCODEC_MAX_AUDIO_FRAME_SIZE);
- if (samples_size > movie->samples_buf_size) {
- movie->samples_buf = av_fast_realloc(movie->samples_buf,
- &movie->samples_buf_size, samples_size);
- if (!movie->samples_buf)
- return AVERROR(ENOMEM);
- }
- decoded_data_size = movie->samples_buf_size;
-
/* decode and update the movie pkt */
- ret = avcodec_decode_audio3(movie->codec_ctx, movie->samples_buf,
- &decoded_data_size, &movie->pkt);
- if (ret < 0)
+ avcodec_get_frame_defaults(movie->frame);
+ ret = avcodec_decode_audio4(movie->codec_ctx, movie->frame, &got_frame, &movie->pkt);
+ if (ret < 0) {
+ movie->pkt.size = 0;
return ret;
+ }
movie->pkt.data += ret;
movie->pkt.size -= ret;
/* wrap the decoded data in a samplesref */
- if (decoded_data_size > 0) {
- int nb_samples = decoded_data_size / movie->bps / movie->codec_ctx->channels;
+ if (got_frame) {
+ int nb_samples = movie->frame->nb_samples;
+ int data_size =
+ av_samples_get_buffer_size(NULL, movie->codec_ctx->channels,
+ nb_samples, movie->codec_ctx->sample_fmt, 1);
+ if (data_size < 0)
+ return data_size;
movie->samplesref =
avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
- memcpy(movie->samplesref->data[0], movie->samples_buf, decoded_data_size);
+ memcpy(movie->samplesref->data[0], movie->frame->data[0], data_size);
movie->samplesref->pts = movie->pkt.pts;
movie->samplesref->pos = movie->pkt.pos;
movie->samplesref->audio->sample_rate = movie->codec_ctx->sample_rate;