lavfi: add libavfilter/avcodec.h and avfilter_copy_frame_props()

avfilter_copy_frame_props() avoids code duplication and increases
robustness.

The added files libavfilter/avcodec.[ch] are used for containing
utilities useful for gluing togheter libavfilter and libavcodec.
This commit is contained in:
Stefano Sabatini 2011-05-01 14:47:05 +02:00
parent 18ded93ab3
commit 566666caf3
9 changed files with 99 additions and 16 deletions

View File

@ -13,6 +13,10 @@ libavutil: 2011-04-18
API changes, most recent first:
2011-05-07 - xxxxxxx - lavfi 2.5.0 - avcodec.h
Add libavfilter/avcodec.h header and avfilter_copy_frame_props()
function.
2011-05-07 - xxxxxxx - lavc 53.5.0 - AVFrame
Add format field to AVFrame.

View File

@ -50,6 +50,7 @@
#include "libavformat/ffm.h" // not public API
#if CONFIG_AVFILTER
# include "libavfilter/avcodec.h"
# include "libavfilter/avfilter.h"
# include "libavfilter/avfiltergraph.h"
# include "libavfilter/vsrc_buffer.h"

View File

@ -40,6 +40,7 @@
#include "libavcodec/avfft.h"
#if CONFIG_AVFILTER
# include "libavfilter/avcodec.h"
# include "libavfilter/avfilter.h"
# include "libavfilter/avfiltergraph.h"
#endif
@ -1686,9 +1687,9 @@ static int input_request_frame(AVFilterLink *link)
}
av_free_packet(&pkt);
avfilter_copy_frame_props(picref, priv->frame);
picref->pts = pts;
picref->pos = priv->frame->pkt_pos;
picref->video->sample_aspect_ratio = priv->frame->sample_aspect_ratio;
avfilter_start_frame(link, picref);
avfilter_draw_slice(link, 0, link->h, 1);
avfilter_end_frame(link);

View File

@ -6,7 +6,7 @@ FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec
FFLIBS-$(CONFIG_SCALE_FILTER) += swscale
FFLIBS-$(CONFIG_MP_FILTER) += avcodec
HEADERS = avfilter.h avfiltergraph.h
HEADERS = avcodec.h avfilter.h avfiltergraph.h
OBJS = allfilters.o \
avfilter.o \
@ -16,6 +16,8 @@ OBJS = allfilters.o \
formats.o \
graphparser.o \
OBJS-$(CONFIG_AVCODEC) += avcodec.o
OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o
OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o

42
libavfilter/avcodec.c Normal file
View File

@ -0,0 +1,42 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* libavcodec/libavfilter gluing utilities
*/
#include "avcodec.h"
void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
{
dst->pts = src->pts;
dst->pos = src->pkt_pos;
dst->format = src->format;
switch (dst->type) {
case AVMEDIA_TYPE_VIDEO:
dst->video->w = src->width;
dst->video->h = src->height;
dst->video->sample_aspect_ratio = src->sample_aspect_ratio;
dst->video->interlaced = src->interlaced_frame;
dst->video->top_field_first = src->top_field_first;
dst->video->key_frame = src->key_frame;
dst->video->pict_type = src->pict_type;
}
}

40
libavfilter/avcodec.h Normal file
View File

@ -0,0 +1,40 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVFILTER_AVCODEC_H
#define AVFILTER_AVCODEC_H
/**
* @file
* libavcodec/libavfilter gluing utilities
*
* This should be included in an application ONLY if the installed
* libavfilter has been compiled with libavcodec support, otherwise
* symbols defined below will not be available.
*/
#include "libavcodec/avcodec.h" // AVFrame
#include "avfilter.h"
/**
* Copy the frame properties of src to dst, without copying the actual
* image data.
*/
void avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
#endif /* AVFILTER_AVCODEC_H */

View File

@ -26,7 +26,7 @@
#include "libavutil/samplefmt.h"
#define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 4
#define LIBAVFILTER_VERSION_MINOR 5
#define LIBAVFILTER_VERSION_MICRO 0
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \

View File

@ -24,6 +24,7 @@
*/
#include "avfilter.h"
#include "avcodec.h"
#include "vsrc_buffer.h"
#include "libavutil/imgutils.h"
@ -193,13 +194,9 @@ static int request_frame(AVFilterLink *link)
av_image_copy(picref->data, picref->linesize,
c->frame.data, c->frame.linesize,
picref->format, link->w, link->h);
avfilter_copy_frame_props(picref, &c->frame);
picref->pts = c->pts;
picref->pts = c->pts;
picref->video->sample_aspect_ratio = c->frame.sample_aspect_ratio;
picref->video->interlaced = c->frame.interlaced_frame;
picref->video->top_field_first = c->frame.top_field_first;
picref->video->key_frame = c->frame.key_frame;
picref->video->pict_type = c->frame.pict_type;
avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0));
avfilter_draw_slice(link, 0, link->h, 1);
avfilter_end_frame(link);

View File

@ -35,6 +35,7 @@
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
#include "libavformat/avformat.h"
#include "avcodec.h"
#include "avfilter.h"
typedef struct {
@ -239,20 +240,15 @@ static int movie_get_frame(AVFilterLink *outlink)
av_image_copy(movie->picref->data, movie->picref->linesize,
movie->frame->data, movie->frame->linesize,
movie->picref->format, outlink->w, outlink->h);
avfilter_copy_frame_props(movie->picref, movie->frame);
/* FIXME: use a PTS correction mechanism as that in
* ffplay.c when some API will be available for that */
/* 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;
movie->picref->pos = movie->frame->pkt_pos;
if (!movie->frame->sample_aspect_ratio.num)
movie->picref->video->sample_aspect_ratio = st->sample_aspect_ratio;
movie->picref->video->interlaced = movie->frame->interlaced_frame;
movie->picref->video->top_field_first = movie->frame->top_field_first;
movie->picref->video->key_frame = movie->frame->key_frame;
movie->picref->video->pict_type = movie->frame->pict_type;
av_dlog(outlink->src,
"movie_get_frame(): file:'%s' pts:%"PRId64" time:%lf pos:%"PRId64" aspect:%d/%d\n",
movie->file_name, movie->picref->pts,