def convert(self, sourcefile, targetfile): """Convert a video to h264 format using the magic script""" if convert_video(sourcefile, targetfile): return True else: errormsg = "Video conversion failed" raise ValidationError(errormsg)
def convert_video_collection(sourcedir, destdir): """Convert all video files in this collection""" for dirpath, dirnames, filenames in os.walk(sourcedir): destpath = os.path.join(destdir, '/'.join(dirpath.split(os.sep)[1:])) if not os.path.exists(destpath): os.makedirs(destpath) for f in filenames: (name, ext) = os.path.splitext(os.path.basename(f)) if ext in ['.mp4', '.flv', '.mov']: sourcefile = os.path.join(dirpath, f) destfile = os.path.join(destpath, name + ".mp4") if not os.path.exists(destfile): print sourcefile, destfile convert_video(sourcefile, destfile, force=True)
def ensure_mp4(self): """Ensure that the video file is an h264 format video, convert it if necessary""" # convert video to use the right size and iphone/net friendly bitrate # create a temporary copy in the new format # then move it into place # print "ENSURE: ", self.videofile.path (basename, ext) = os.path.splitext(self.videofile.path) tmploc = basename + "-conv.mp4" err = convert_video(self.videofile.path, tmploc, force=True) # print tmploc shutil.move(tmploc, self.videofile.path)
def ensure_mp4(self): """Ensure that the video file is an h264 format video, convert it if necessary""" # convert video to use the right size and iphone/net friendly bitrate # create a temporary copy in the new format # then move it into place (basename, ext) = os.path.splitext(self.videofile.path) if ext == '.mov': oldloc = self.videofile.path newloc = basename + ".mp4" err = convert_video(oldloc, newloc, force=True) self.videofile.name = get_video_file_path(self, os.path.basename(newloc)) os.remove(oldloc)