[FFmpeg-devel] [PATCH 3/3] Implement a common get_filtered_video_frame(), shared between ffplay.c and ffmpeg.c.

Stefano Sabatini stefano.sabatini-lala
Fri Oct 15 12:53:13 CEST 2010


---
 cmdutils.c |   22 ++++++++++++++++++++++
 cmdutils.h |    9 +++++++++
 ffmpeg.c   |   28 ++++------------------------
 ffplay.c   |   29 +++++++----------------------
 4 files changed, 42 insertions(+), 46 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index fca783c..49c6ad5 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -787,4 +787,26 @@ AVFilter ffsink = {
     .outputs   = (AVFilterPad[]) {{ .name = NULL }},
 };
 
+int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
+                             AVFilterBufferRef **picref_ptr, AVRational *tb)
+{
+    int ret;
+    AVFilterBufferRef *picref;
+
+    if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0)
+        return ret;
+    if (!(picref = ctx->inputs[0]->cur_buf))
+        return AVERROR(ENOENT);
+    *picref_ptr = picref;
+    ctx->inputs[0]->cur_buf = NULL;
+    *tb = ctx->inputs[0]->time_base;
+
+    memcpy(frame->data,     picref->data,     sizeof(frame->data));
+    memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
+    frame->interlaced_frame = picref->video->interlaced;
+    frame->top_field_first  = picref->video->top_field_first;
+
+    return 1;
+}
+
 #endif /* CONFIG_AVFILTER */
diff --git a/cmdutils.h b/cmdutils.h
index 00f914c..b431b2e 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -270,6 +270,15 @@ typedef struct {
 
 extern AVFilter ffsink;
 
+/**
+ * Extract a frame from sink.
+ *
+ * @return a negative error in case of failure, 1 if one frame has
+ * been extracted successfully.
+ */
+int get_filtered_video_frame(AVFilterContext *sink, AVFrame *frame,
+                             AVFilterBufferRef **picref, AVRational *pts_tb);
+
 #endif /* CONFIG_AVFILTER */
 
 #endif /* FFMPEG_CMDUTILS_H */
diff --git a/ffmpeg.c b/ffmpeg.c
index bb4563d..eeaed96 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -340,29 +340,6 @@ static struct termios oldtty;
 
 #if CONFIG_AVFILTER
 
-static int get_filtered_video_pic(AVFilterContext *ctx,
-                                  AVFilterBufferRef **picref, AVFrame *pic2,
-                                  uint64_t *pts)
-{
-    AVFilterBufferRef *pic;
-
-    if(avfilter_request_frame(ctx->inputs[0]))
-        return -1;
-    if(!(pic = ctx->inputs[0]->cur_buf))
-        return -1;
-    *picref = pic;
-    ctx->inputs[0]->cur_buf = NULL;
-
-    *pts          = pic->pts;
-
-    memcpy(pic2->data,     pic->data,     sizeof(pic->data));
-    memcpy(pic2->linesize, pic->linesize, sizeof(pic->linesize));
-    pic2->interlaced_frame = pic->video->interlaced;
-    pic2->top_field_first  = pic->video->top_field_first;
-
-    return 1;
-}
-
 static int configure_filters(AVInputStream *ist, AVOutputStream *ost)
 {
     AVFilterContext *last_filter, *filter;
@@ -1676,8 +1653,11 @@ static int output_packet(AVInputStream *ist, int ist_index,
         if (start_time == 0 || ist->pts >= start_time)
 #if CONFIG_AVFILTER
         while (frame_available) {
+            AVRational tb;
             if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ist->output_video_filter)
-                get_filtered_video_pic(ist->output_video_filter, &ist->picref, &picture, &ist->pts);
+                get_filtered_video_frame(ist->output_video_filter, &picture, &ist->picref, &tb);
+            if (ist->picref)
+                ist->pts = ist->picref->pts;
 #endif
             for(i=0;i<nb_ostreams;i++) {
                 int frame_size;
diff --git a/ffplay.c b/ffplay.c
index 93208e2..f2ae657 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -1779,27 +1779,6 @@ static AVFilter input_filter =
                                   { .name = NULL }},
 };
 
-static int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame,
-                                    int64_t *pts, AVRational *tb, int64_t *pos)
-{
-    AVFilterBufferRef *pic;
-
-    if(avfilter_request_frame(ctx->inputs[0]))
-        return -1;
-    if(!(pic = ctx->inputs[0]->cur_buf))
-        return -1;
-    ctx->inputs[0]->cur_buf = NULL;
-
-    frame->opaque = pic;
-    *pts          = pic->pts;
-    *pos          = pic->pos;
-    *tb           = ctx->inputs[0]->time_base;
-
-    memcpy(frame->data,     pic->data,     sizeof(frame->data));
-    memcpy(frame->linesize, pic->linesize, sizeof(frame->linesize));
-
-    return 1;
-}
 #endif  /* CONFIG_AVFILTER */
 
 static int video_thread(void *arg)
@@ -1860,12 +1839,18 @@ static int video_thread(void *arg)
 #if !CONFIG_AVFILTER
         AVPacket pkt;
 #else
+        AVFilterBufferRef *picref;
         AVRational tb;
 #endif
         while (is->paused && !is->videoq.abort_request)
             SDL_Delay(10);
 #if CONFIG_AVFILTER
-        ret = get_filtered_video_frame(filt_out, frame, &pts_int, &tb, &pos);
+        ret = get_filtered_video_frame(filt_out, frame, &picref, &tb);
+        if (picref) {
+            pts_int = picref->pts;
+            pos     = picref->pos;
+            frame->opaque = picref;
+        }
 
         if (av_cmp_q(tb, is->video_st->time_base)) {
             int64_t pts1 = pts_int;
-- 
1.7.1




More information about the ffmpeg-devel mailing list