def video_create_poster(videopath, poster, video_data): ''' Grab a JPEG snapshot of the video ''' output = "" thumbnailfile = NamedTemporaryFile(suffix='.jpg') try: request = datetime.strptime(PHOTOLOGUE_POSTER_TIME, '%H:%M:%S.%f') except: request = datetime.strptime(PHOTOLOGUE_POSTER_TIME, '%H:%M:%S') requested_time = (datetime.combine(datetime.min, request.time()) - datetime.min).total_seconds() # Is requested time after video end? # There is some rounding in process, we need to make shure we are safe if video_data['duration'] - 1 < requested_time: poster_time = str(timedelta(seconds=video_data['duration']/2.0)) else: poster_time = PHOTOLOGUE_POSTER_TIME grabimage = ( '%(ffmpeg)s -y -i "%(infile)s" ' '-vframes 1 -ss %(postertime)s -an ' '-vcodec mjpeg -f rawvideo ' '%(filt)s -s %(size)s %(outfile)s' ) % dict( ffmpeg=FFMPEG, infile=videopath, postertime=poster_time, outfile=thumbnailfile.name, filt=construct_filter(video_data['deinterlace']), size="%dx%d" % (video_data['orig_w'], video_data['orig_h']) ) (message, retval) = execute(grabimage, "-------------------- GRAB IMAGE ------------------") output += message if retval: raise Exception('Creating poster have failed\n\n' + output) s = os.stat(thumbnailfile.name) fsize = s.st_size if (fsize == 0): output += "Target file is 0 bytes conversion failed?\n" raise Exception('Poster creation have failed(file zero size)\n\n' + output) # Replace part after last dot by 'png' name = os.path.basename(videopath) dot = name.rfind('.') if dot != -1: name = name[:dot] name = os.path.join("poster", name+'.jpg') # Import poster_unconverted here from photologue.models.video import poster_unconverted if poster_unconverted(poster): poster.remove_deleted = False # Store file and save poster.file.save(name, File(thumbnailfile)) return output
def update_files(): """ Set name and mtime of all files associated to media items to title_slug and date_taken. """ for item in GalleryItemBase.objects.all(): update_item(item, item.title_slug) if hasattr(item, 'poster'): if not poster_unconverted(item.poster): update_item(item.poster, item.title_slug)