[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdemultimedia/xine_artsplugin/tools/thumbnail
From:       Ewald Snel <ewald () rambo ! its ! tudelft ! nl>
Date:       2003-02-24 20:51:29
[Download RAW message or body]

CVS commit by snel: 

Fix YUY2 video format, efficient processing of small video files


  M +12 -7     videocreator.cpp   1.8


--- kdemultimedia/xine_artsplugin/tools/thumbnail/videocreator.cpp  #1.7:1.8
@@ -181,5 +181,6 @@ static QImage createThumbnail( xine_vide
 
 // Return the variance of the brightness of the pixels
-static double imageVariance( unsigned char *pixels, int pitch, int width, int height )
+static double imageVariance( unsigned char *pixels, int pitch,
+                             int width, int height, int step )
 {
     double sigmaX = 0;
@@ -191,5 +192,5 @@ static double imageVariance( unsigned ch
         unsigned int uSigmaXSquared = 0;
 
-        for (int x=0; x < width ; x++)
+        for (int x=0, n=(width * step); x < n ; x+=step)
         {
             int gray = pixels[x];
@@ -213,10 +214,9 @@ static bool findBestFrame( xine_video_po
 {
     xine_video_frame_t frames[2], *bestFrame = NULL;
-    xine_video_frame_t *cFrame = NULL;
     double variance, bestVariance = 0;
 
     for (int i=0, n=0; i < MAX_ATTEMPTS; i++)
     {
-        cFrame = &frames[n];
+        xine_video_frame_t *cFrame = &frames[n];
 
         // Try to read next frame
@@ -227,5 +227,6 @@ static bool findBestFrame( xine_video_po
 
         variance = imageVariance( cFrame->data, ((cFrame->width + 7) & ~0x7),
-                                  cFrame->width, cFrame->height );
+                                  cFrame->width, cFrame->height,
+                                 (cFrame->colorspace == XINE_IMGFMT_YV12) ? 1 : 2 );
 
         // Compare current frame to best frame
@@ -308,9 +309,13 @@ bool VideoCreator::create(const QString 
     {
         xine_video_frame_t frame;
+        int length;
 
         // Find 'best' (or at least any) frame
+        if (!xine_get_pos_length( stream, NULL, NULL, &length ) || length > 5000)
+        {
         if (xine_play( stream, 0, 4000 ))
         {
             success = findBestFrame( vo_port, &frame );
+            }
         }
         if (!success)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic