Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp (revision 9857)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp (revision 9860)
@@ -2,4 +2,5 @@
 
 #include <osg/Notify>
+#include <osg/Timer>
 
 #include <stdexcept>
@@ -17,4 +18,5 @@
     m_bytes_remaining(0),
     m_packet_pts(AV_NOPTS_VALUE),
+    m_writeBuffer(0),
     m_user_data(0),
     m_publish_func(0),
@@ -84,9 +86,9 @@
     // Allocate converted RGB frame
     m_frame_rgba.reset(avcodec_alloc_frame());
-    m_buffer_rgba.resize(avpicture_get_size(PIX_FMT_RGB32, width(), height()));
-    m_buffer_rgba_public.resize(m_buffer_rgba.size());
+    m_buffer_rgba[0].resize(avpicture_get_size(PIX_FMT_RGB32, width(), height()));
+    m_buffer_rgba[1].resize(m_buffer_rgba[0].size());
 
     // Assign appropriate parts of the buffer to image planes in m_frame_rgba
-    avpicture_fill((AVPicture *) m_frame_rgba.get(), &m_buffer_rgba[0], PIX_FMT_RGB32, width(), height());
+    avpicture_fill((AVPicture *) (m_frame_rgba).get(), &(m_buffer_rgba[0])[0], PIX_FMT_RGB32, width(), height());
 
     // Override get_buffer()/release_buffer() from codec context in order to retrieve the PTS of each frame.
@@ -216,4 +218,5 @@
             int src_pix_fmt, int src_width, int src_height)
 {
+    osg::Timer_t startTick = osg::Timer::instance()->tick();
 #ifdef USE_SWSCALE
     if (m_swscale_ctx==0)
@@ -221,18 +224,25 @@
         m_swscale_ctx = sws_getContext(src_width, src_height, src_pix_fmt,
                                       src_width, src_height, dst_pix_fmt,                                    
-                                      SWS_BILINEAR, NULL, NULL, NULL);
+                                      /*SWS_BILINEAR*/ SWS_BICUBIC, NULL, NULL, NULL);
     }
     
-    osg::notify(osg::NOTICE)<<"Using sws_scale"<<std::endl;
-
-    return sws_scale(m_swscale_ctx,
-           src->data, src->linesize, 0, src_height,
-           dst->data, dst->linesize);
+
+    osg::notify(osg::NOTICE)<<"Using sws_scale ";
+
+    int result =  sws_scale(m_swscale_ctx,
+                            src->data, src->linesize, 0, src_height,
+                            dst->data, dst->linesize);
 #else
-    osg::notify(osg::NOTICE)<<"Using img_convert"<<std::endl;
-
-    return img_convert(dst, dst_pix_fmt, src,
-                      src_pix_fmt, src_width, src_height);
+
+    osg::notify(osg::NOTICE)<<"Using img_convert ";
+
+    int result = img_convert(dst, dst_pix_fmt, src,
+                             src_pix_fmt, src_width, src_height);
+
 #endif
+    osg::Timer_t endTick = osg::Timer::instance()->tick();
+    osg::notify(osg::NOTICE)<<" time = "<<osg::Timer::instance()->delta_m(startTick,endTick)<<"ms"<<std::endl;
+
+    return result;
 }
 
@@ -247,7 +257,12 @@
     if (delay < -0.010)
         return;
-
+        
     const AVPicture * const src = (const AVPicture *) m_frame.get();
     AVPicture * const dst = (AVPicture *) m_frame_rgba.get();
+
+    osg::Timer_t startTick = osg::Timer::instance()->tick();
+
+    // Assign appropriate parts of the buffer to image planes in m_frame_rgba
+    avpicture_fill((AVPicture *) (m_frame_rgba).get(), &(m_buffer_rgba[m_writeBuffer])[0], PIX_FMT_RGB32, width(), height());
 
     // Convert YUVA420p (i.e. YUV420p plus alpha channel) using our own routine
@@ -258,6 +273,11 @@
         convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width(), height());
 
+
     // Flip and swap buffer
-    swapBuffers();
+    // swapBuffers();
+
+
+    osg::Timer_t endTick = osg::Timer::instance()->tick();
+    osg::notify(osg::NOTICE)<<" time of swapBuffers = "<<osg::Timer::instance()->delta_m(startTick,endTick)<<"ms"<<std::endl;
 
     // Wait 'delay' seconds before publishing the picture.
@@ -277,4 +297,6 @@
     }
 
+    m_writeBuffer = 1-m_writeBuffer;
+
     m_publish_func(* this, m_user_data);
 }
@@ -285,5 +307,5 @@
 {
     for (int h = 0; h < height(); ++h)
-        memcpy(&m_buffer_rgba_public[(height() - h - 1) * width() * 4], &m_buffer_rgba[h * width() * 4], width() * 4);
+        memcpy(&(m_buffer_rgba[1-m_writeBuffer])[(height() - h - 1) * width() * 4], &(m_buffer_rgba[m_writeBuffer])[h * width() * 4], width() * 4);
 }
 
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp (revision 9847)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegImageStream.cpp (revision 9860)
@@ -58,4 +58,6 @@
         const_cast<unsigned char *>(m_decoder->video_decoder().image()), NO_DELETE
     );
+    
+    setOrigin(osg::Image::TOP_LEFT);
 
     m_decoder->video_decoder().setUserData(this);
@@ -265,6 +267,13 @@
     FFmpegImageStream * const this_ = reinterpret_cast<FFmpegImageStream*>(user_data);
 
+#if 1
+    this_->setImage(
+        this_->m_decoder->video_decoder().width(), this_->m_decoder->video_decoder().height(), 1, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE,
+        const_cast<unsigned char *>(this_->m_decoder->video_decoder().image()), NO_DELETE
+    );
+#else
     /** \bug If viewer.realize() hasn't been already called, this doesn't work? */
     this_->dirty();
+#endif
 
     OpenThreads::ScopedLock<Mutex> lock(this_->m_mutex);
Index: /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp
===================================================================
--- /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp (revision 9856)
+++ /OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/FFmpegDecoderVideo.hpp (revision 9860)
@@ -108,6 +108,6 @@
     FramePtr                m_frame;
     FramePtr                m_frame_rgba;
-    Buffer                  m_buffer_rgba;
-    Buffer                  m_buffer_rgba_public;
+    Buffer                  m_buffer_rgba[2];
+    int                     m_writeBuffer;
 
     void *                  m_user_data;
@@ -176,5 +176,5 @@
 inline const uint8_t * FFmpegDecoderVideo::image() const
 {
-    return &m_buffer_rgba_public[0];
+    return &((m_buffer_rgba[1-m_writeBuffer])[0]);
 }
 
