leocrawford / picasawebsync

Sync local directories with picasaweb
MIT License
59 stars 16 forks source link

Request option for resize video before upload #37

Closed andreasqueri closed 8 years ago

andreasqueri commented 8 years ago

Hi, I think a nice improvement would be to add an option to resize the videos before you upload, as well as going to the pictures. I made a change that allows you to do this using ffmpeg, but the solution is too dependent on the operating system and is hard-coded in the source. I think the best solution would be to add an option to commandline program as "--reszievideo" that let user to choose if resize or not videos, reading which command to use to resize from a config file. I think also , that this new feature is easy to make. These are the changes I made to implement the resize video:

added the resizeVideo function:

def resizeVideo(path):

   filename = os.path.basename(path)
   filename_new = "/tmp/" + filename
   res=0
   if not(os.path.exists(filename_new)):
     res=call(["ffmpeg","-loglevel","-8","-i",path,"-strict","-2","-s","176x144","-b:v","800000","-b:a","32k","-r","23",filename_new])

     if (res==0):
       return filename_new
     else:
       return None

And these are the change made in the upload_local_video function

def upload_local_video(self, subAlbum):
         name = urllib.quote(self.name, '')
        metadata = gdata.photos.VideoEntry()
         metadata.title = atom.Title(text=name)  # have to quote as certain charecters, e.g. / seem to break it
         self.addMetadata(metadata)
         shrinkFile = resizeVideo(self.path)
         currentFile = self.path
        if (shrinkFile is not None):
             currentFile = shrinkFile
        photo = gd_client.InsertVideo(subAlbum.albumUri, metadata, currentFile, self.type)

        if (shrinkFile is not None):
             os.remove(shrinkFile)
         subAlbum.numberFiles = subAlbum.numberFiles + 1
         return photo

How can you see, the only change i made is to add the resizeVideo function and i call him ever before upload video.

The best thing would be to add the option --resize video to the command line and change the function resizeVideo so that it reads the command to use to resize from a configuration file, and perhaps give the user the possibility of choose whether to resize the video only in certain circumstances (for example, files larger than a certain size etc ..)

leocrawford commented 8 years ago

Thanks for the suggestion. I'm a little sceptical about making the codebase more complex for one user. Perhaps if you keep your own fork for now, and if I get much interest we can look at merging back in?