[FFmpeg-devel] [PATCH] video stabilization plugins using vid.stab library

Clément Bœsch ubitux at gmail.com
Thu Apr 25 10:13:30 CEST 2013


On Thu, Apr 25, 2013 at 01:26:03AM +0200, Georg Martius wrote:
[...]
> > Also, I fixed and simplified the direct path for vidstabdetect.
> Okay, I see. Well if the show option is disabled, then the filter does not 
> write something, so we don't need to make 'in' writeable. 

> Should this simplification also be done for the transform plugin?

AFAICT, in the case of the transform plugin, if in==out, vid.stab will dup in
anyway to be able to write to out; the inplace is an illusion. So in the filter
you could just unconditionally get a video buffer for out and use it.
Basically, just remove the direct path:

diff --git a/libavfilter/vf_vidstabtransform.c b/libavfilter/vf_vidstabtransform.c
index eee3da7..34b0ac5 100644
--- a/libavfilter/vf_vidstabtransform.c
+++ b/libavfilter/vf_vidstabtransform.c
@@ -216,43 +216,31 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     VSTransformData* td = &(tc->td);
 
     AVFilterLink *outlink = inlink->dst->outputs[0];
-    int direct = 0;
     AVFrame *out;
-    VSFrame inframe;
+    VSFrame inframe, outframe;
     int plane;
 
-    if (av_frame_is_writable(in)) {
-        direct = 1;
-        out = in;
-    } else {
         out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
         if (!out) {
             av_frame_free(&in);
             return AVERROR(ENOMEM);
         }
         av_frame_copy_props(out, in);
-    }
 
     for (plane = 0; plane < vsTransformGetSrcFrameInfo(td)->planes; plane++) {
         inframe.data[plane] = in->data[plane];
         inframe.linesize[plane] = in->linesize[plane];
     }
-    if (direct) {
-        vsTransformPrepare(td, &inframe, &inframe);
-    } else { // separate frames
-        VSFrame outframe;
         for (plane = 0; plane < vsTransformGetDestFrameInfo(td)->planes; plane++) {
             outframe.data[plane] = out->data[plane];
             outframe.linesize[plane] = out->linesize[plane];
         }
         vsTransformPrepare(td, &inframe, &outframe);
-    }
 
     vsDoTransform(td, vsGetNextTransform(td, &tc->trans));
 
     vsTransformFinish(td);
 
-    if (!direct)
         av_frame_free(&in);
 
     return ff_filter_frame(outlink, out);

I had this change locally yesterday, but since I wasn't able to test it
reliably I didn't apply.

> > 
> > BTW, this may be unrelated to this patch, but there is possibly a ref
> > counting issue somewhere; I have an undefined behaviour reproducible with
> > vidstabtransform and ffplay (sometimes it has no effect). Input frame
> > being read-only or no doesn't seem to change anything (output being
> > changed is still somehow random whatever the input frame state). There is
> > possibly a problem in the library (I'm using Git version), or maybe in
> > FFmpeg codebase.
> Can you give me a cmd-line to reproduce?
> 

ffplay ... -vf vidstabtransform

Sometimes it has some effect. Sometimes not (more often).

-- 
Clément B.
-------------- 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/20130425/bea97de8/attachment.asc>


More information about the ffmpeg-devel mailing list