[FFmpeg-devel] ffmpeg -af, libavfilter

Clément Bœsch ubitux at gmail.com
Tue Mar 20 16:10:57 CET 2012


On Fri, Feb 24, 2012 at 07:13:33PM +0100, Stefano Sabatini wrote:
[...]
> > From 22e02b3b5be58f4e28395a2ff10bf65269da2d8a Mon Sep 17 00:00:00 2001
> > From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
> > Date: Tue, 14 Feb 2012 17:00:53 +0100
> > Subject: [PATCH 1/2] lavfi/WIP: add
> >  avfilter_fill_frame_from_audio_buffer_ref().
> > 
> > ---
> >  libavfilter/avcodec.c |   14 ++++++++++++++
> >  libavfilter/avcodec.h |   11 +++++++++++
> >  2 files changed, 25 insertions(+), 0 deletions(-)
> > 
> > diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c
> > index 2850c4d..5fea5b7 100644
> > --- a/libavfilter/avcodec.c
> > +++ b/libavfilter/avcodec.c
> > @@ -56,6 +56,20 @@ AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame
> >      return picref;
> >  }
> >  
> > +int avfilter_fill_frame_from_audio_buffer_ref(AVFrame *frame,
> > +                                              const AVFilterBufferRef *samplesref)
> > +{
> > +    if (!samplesref || !samplesref->audio || !frame)
> > +        return AVERROR(EINVAL);
> > +
> > +    memcpy(frame->data, samplesref->data, sizeof(frame->data));
> > +    frame->pkt_pos    = samplesref->pos;
> > +    frame->format     = samplesref->format;
> > +    frame->nb_samples = samplesref->audio->nb_samples;
> > +
> > +    return 0;
> > +}
> > +
> >  int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
> >                                                const AVFilterBufferRef *picref)
> >  {
> > diff --git a/libavfilter/avcodec.h b/libavfilter/avcodec.h
> > index 22dd1a2..36ab917 100644
> > --- a/libavfilter/avcodec.h
> > +++ b/libavfilter/avcodec.h
> > @@ -47,6 +47,17 @@ int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
> >  AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, int perms);
> >  
> >  /**
> > + * Fill an AVFrame with the information stored in samplesref.
> > + *
> > + * @param frame an already allocated AVFrame
> > + * @param samplesref an audio buffer reference
> > + * @return 0 in case of success, a negative AVERROR code in case of
> > + * failure
> > + */
> > +int avfilter_fill_frame_from_audio_buffer_ref(AVFrame *frame,
> > +                                              const AVFilterBufferRef *samplesref);
> > +
> > +/**
> >   * Fill an AVFrame with the information stored in picref.
> >   *
> >   * @param frame an already allocated AVFrame
> > -- 
> > 1.7.9
> 
> OK, but maybe we should unify the A/V API and have a single
> avfilter_fill_frame_from_buffer_ref().
> 

Let's get things started on this again, see the new attached patch. I had
a request today (or yesterday can't remember) about this one. It doesn't
help much for the -af but I guess it could be applied without much
trouble.

-- 
Clément B.
-------------- next part --------------
From 0c7e38b3a499c82e9b696e023ad4b07e263ba04d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <clement.boesch at smartjog.com>
Date: Tue, 14 Feb 2012 17:00:53 +0100
Subject: [PATCH] lavfi: add avfilter_fill_frame_from_{audio_,}buffer_ref().

FIXME: bump LIBAVFILTER_VERSION_MINOR + Changelog entry
---
 libavfilter/avcodec.c |   23 +++++++++++++++++++++++
 libavfilter/avcodec.h |   22 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c
index 2850c4d..455ef92 100644
--- a/libavfilter/avcodec.c
+++ b/libavfilter/avcodec.c
@@ -56,6 +56,20 @@ AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame
     return picref;
 }
 
+int avfilter_fill_frame_from_audio_buffer_ref(AVFrame *frame,
+                                              const AVFilterBufferRef *samplesref)
+{
+    if (!samplesref || !samplesref->audio || !frame)
+        return AVERROR(EINVAL);
+
+    memcpy(frame->data, samplesref->data, sizeof(frame->data));
+    frame->pkt_pos    = samplesref->pos;
+    frame->format     = samplesref->format;
+    frame->nb_samples = samplesref->audio->nb_samples;
+
+    return 0;
+}
+
 int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
                                               const AVFilterBufferRef *picref)
 {
@@ -73,3 +87,12 @@ int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
 
     return 0;
 }
+
+int avfilter_fill_frame_from_buffer_ref(AVFrame *frame,
+                                        const AVFilterBufferRef *ref)
+{
+    if (!ref)
+        return AVERROR(EINVAL);
+    return ref->video ? avfilter_fill_frame_from_video_buffer_ref(frame, ref)
+                      : avfilter_fill_frame_from_audio_buffer_ref(frame, ref);
+}
diff --git a/libavfilter/avcodec.h b/libavfilter/avcodec.h
index 22dd1a2..64773a6 100644
--- a/libavfilter/avcodec.h
+++ b/libavfilter/avcodec.h
@@ -47,6 +47,17 @@ int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
 AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, int perms);
 
 /**
+ * Fill an AVFrame with the information stored in samplesref.
+ *
+ * @param frame an already allocated AVFrame
+ * @param samplesref an audio buffer reference
+ * @return 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int avfilter_fill_frame_from_audio_buffer_ref(AVFrame *frame,
+                                              const AVFilterBufferRef *samplesref);
+
+/**
  * Fill an AVFrame with the information stored in picref.
  *
  * @param frame an already allocated AVFrame
@@ -58,6 +69,17 @@ int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
                                               const AVFilterBufferRef *picref);
 
 /**
+ * Fill an AVFrame with information stored in ref.
+ *
+ * @param frame an already allocated AVFrame
+ * @param ref a video or audio buffer reference
+ * @return 0 in case of success, a negative AVERROR code in case of
+ * failure
+ */
+int avfilter_fill_frame_from_buffer_ref(AVFrame *frame,
+                                        const AVFilterBufferRef *ref);
+
+/**
  * Add frame data to buffer_src.
  *
  * @param buffer_src pointer to a buffer source context
-- 
1.7.9.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120320/12c14a18/attachment.asc>


More information about the ffmpeg-devel mailing list