[FFmpeg-cvslog] buffersrc: add av_buffersrc_write_frame().

Anton Khirnov git at videolan.org
Wed May 16 02:30:36 CEST 2012


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sat Dec 31 16:40:43 2011 +0100| [720c6b78d1e8323d2df070e3da2f0ed305156c65] | committer: Anton Khirnov

buffersrc: add av_buffersrc_write_frame().

It's the same as av_vsrc_buffer_add_frame(), except it doesn't take pts
or pixel_aspect parameters. Those are read from AVFrame.

Deprecate av_vsrc_buffer_add_frame().

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=720c6b78d1e8323d2df070e3da2f0ed305156c65
---

 avconv.c                  |    3 +--
 libavfilter/buffersrc.c   |   20 ++++++++++++++++++--
 libavfilter/buffersrc.h   |   11 +++++++++++
 libavfilter/version.h     |    3 +++
 libavfilter/vsrc_buffer.h |    2 ++
 5 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/avconv.c b/avconv.c
index c157778..fbe3827 100644
--- a/avconv.c
+++ b/avconv.c
@@ -2357,8 +2357,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int
             buf->refcount++;
             av_buffersrc_buffer(ist->filters[i]->filter, fb);
         } else
-            av_vsrc_buffer_add_frame(ist->filters[i]->filter, decoded_frame,
-                                     decoded_frame->pts, decoded_frame->sample_aspect_ratio);
+            av_buffersrc_write_frame(ist->filters[i]->filter, decoded_frame);
     }
 
     av_free(buffer_to_free);
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index c7284c1..58fc642 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -44,9 +44,27 @@ typedef struct {
         return AVERROR(EINVAL);\
     }
 
+#if FF_API_VSRC_BUFFER_ADD_FRAME
 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
                              int64_t pts, AVRational pixel_aspect)
 {
+    int64_t orig_pts = frame->pts;
+    AVRational orig_sar = frame->sample_aspect_ratio;
+    int ret;
+
+    frame->pts = pts;
+    frame->sample_aspect_ratio = pixel_aspect;
+    if ((ret = av_buffersrc_write_frame(buffer_filter, frame)) < 0)
+        return ret;
+    frame->pts = orig_pts;
+    frame->sample_aspect_ratio = orig_sar;
+
+    return 0;
+}
+#endif
+
+int av_buffersrc_write_frame(AVFilterContext *buffer_filter, AVFrame *frame)
+{
     BufferSourceContext *c = buffer_filter->priv;
     AVFilterBufferRef *buf;
     int ret;
@@ -70,8 +88,6 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
                   c->pix_fmt, c->w, c->h);
 
     avfilter_copy_frame_props(buf, frame);
-    buf->pts                    = pts;
-    buf->video->pixel_aspect    = pixel_aspect;
 
     if ((ret = av_fifo_generic_write(c->fifo, &buf, sizeof(buf), NULL)) < 0) {
         avfilter_unref_buffer(buf);
diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h
index 918a54f..ca82a75 100644
--- a/libavfilter/buffersrc.h
+++ b/libavfilter/buffersrc.h
@@ -36,4 +36,15 @@
  */
 int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);
 
+/**
+ * Add a frame to the buffer source.
+ *
+ * @param s an instance of the buffersrc filter.
+ * @param frame frame to be added.
+ *
+ * @warning frame data will be memcpy()ed, which may be a big performance
+ *          hit. Use av_buffersrc_buffer() to avoid copying the data.
+ */
+int av_buffersrc_write_frame(AVFilterContext *s, AVFrame *frame);
+
 #endif /* AVFILTER_BUFFERSRC_H */
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 71928f3..967d40d 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -50,5 +50,8 @@
 #ifndef FF_API_SAMPLERATE64
 #define FF_API_SAMPLERATE64             (LIBAVFILTER_VERSION_MAJOR < 3)
 #endif
+#ifndef FF_API_VSRC_BUFFER_ADD_FRAME
+#define FF_API_VSRC_BUFFER_ADD_FRAME        (LIBAVFILTER_VERSION_MAJOR < 3)
+#endif
 
 #endif // AVFILTER_VERSION_H
diff --git a/libavfilter/vsrc_buffer.h b/libavfilter/vsrc_buffer.h
index 13a209c..cbcc630 100644
--- a/libavfilter/vsrc_buffer.h
+++ b/libavfilter/vsrc_buffer.h
@@ -29,7 +29,9 @@
 #include "libavcodec/avcodec.h" /* AVFrame */
 #include "avfilter.h"
 
+#if FF_API_VSRC_BUFFER_ADD_FRAME
 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame,
                              int64_t pts, AVRational pixel_aspect);
+#endif
 
 #endif /* AVFILTER_VSRC_BUFFER_H */



More information about the ffmpeg-cvslog mailing list