extract date and time for movies

zelo

Joined: 2004-06-22
Posts: 8
Posted: Thu, 2005-03-24 03:35

I made a quick patch to extract proper date and time for movies.
The idea is to get the date from the modification time of the movie files.
So it won't work with uploading. (maybe it works only for "add items from local server") Anyway, it does no harm in any case.

First, I tried to keep the modification time by 'copy' (modules/core/classes)

--- GalleryPlatform.class.org   2005-02-24 11:31:28.000000000 +0900
+++ GalleryPlatform.class       2005-03-24 11:39:15.725040000 +0900
@@ -56,6 +56,7 @@
            $results = move_uploaded_file($source, $dest);
        } else {
            $results = copy($source, $dest);
+           touch($dest, filemtime($source)); 
        }
        umask($umask);

Then I made 'originationTimestamp' property handled by the ffmpeg toolkit.

--- modules/ffmpeg/classes/FfmpegToolkitHelper.class.org        2005-01-29 08:43:04.000000000 +0900
+++ modules/ffmpeg/classes/FfmpegToolkitHelper.class    2005-03-24 11:54:18.282854400 +0900
@@ -95,6 +95,10 @@
            $gallery->i18n('Get the width, height and duration of the movie');
        $properties['dimensions-and-duration']['mimeTypes'] = $mimeTypes;
 
+       $properties['originationTimestamp']['type'] = 'int';
+       $properties['originationTimestamp']['description'] = $gallery->i18n('Get the origination timestamp');
+       $properties['originationTimestamp']['mimeTypes'] = $mimeTypes;
+
        return array(GalleryStatus::success(), array('operations' => $operations,
                                                     'properties' => $properties));
     }
--- modules/ffmpeg/classes/FfmpegToolkit.class.org      2005-01-29 08:43:04.000000000 +0900
+++ modules/ffmpeg/classes/FfmpegToolkit.class  2005-03-24 11:12:24.197777600 +0900
@@ -69,6 +69,11 @@
            $results = array($width, $height, $duration);
            break;
 
+       case 'originationTimestamp':
+           $timestamp = $this->_getMovieTimestamp($mimeType, $sourceFilename);
+           $results = array($timestamp);
+           break;
+
        default:
            return array(GalleryStatus::error(ERROR_UNIMPLEMENTED,
                                              __FILE__, __LINE__),
@@ -181,6 +186,13 @@
        }
     }
 
+    function _getMovieTimestamp($mimeType, $sourceFilename) {
+       if (file_exists($sourceFilename)) {
+           return filemtime($sourceFilename); 
+       } else {
+           return null; 
+       }
+    }
     /**
      * Run a given ffmpeg command on the source file name and return the
      * command line results.

I believe this can be extended to support image files without exif data.

This is my first experience with gallery code, so this must be premature.
I welcome any advice and I hope this can be of any help to somebody.

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Wed, 2005-03-30 04:01

Hrm. This is an interesting idea. Maybe we would be better off updating GalleryItemHelper_medium::fetchOriginationTimestamp() to use this behaviour as the default, instead? Then it would apply to any file type as a default if the originationTimestamp property isn't available...