def search(dirname): try: filenames = os.listdir(dirname) for filename in filenames: if dirname[-1] == "/": pass else: dirname = dirname + "/" full_path = os.path.join(dirname, filename) if os.path.isdir(full_path): search(full_path) else: ext = os.path.splitext(full_path)[-1] thum = "%s_" % (datetime.today().strftime('%Y%m%d')) + str( uuid.uuid4())[:8] + ".jpg" small_thum_path = "/DATA/reference_library/thumnail/small_thum/%s" % thum if ext.lower() == ".mp4" or ext.lower() == ".mov" or ext.lower( ) == ".mkv" or ext.lower() == ".avi" or ext.lower() == ".webm": try: duration = int(VideoStream(full_path).duration / 2) thumbnail = VideoStream(full_path).get_frame_at_sec( duration).image() thumbnail.save(small_thum_path) except Exception, e: print e select_query = 'select * from img where full_path = "%s"' % full_path cur.execute("set names utf8") cur.execute(select_query) if cur.rowcount == 0: try: codec = VideoStream(full_path).codec_name if codec == "h264" or codec == "aac": full_path = full_path[5:] query_o = 'insert into img(img_path,img_name,full_path,thumnail,type) values("%s","%s","%s","%s","%s")' % ( dirname, filename, full_path, thum, 'video') cur.execute("set names utf8") cur.execute(query_o) db.commit() else: full_path = full_path[5:] query = 'insert into img(img_path,img_name,full_path,thumnail,type) values("%s","%s","%s","%s","%s")' % ( dirname, filename, full_path, 'codec.png', 'video') cur.execute("set names utf8") cur.execute(query) db.commit() except Exception, e: pass else: pass else:
def create(file): video_name = file.filename ext = video_name.rsplit('.', 1)[1].lower() if '.' in video_name and ext in VIDEO_EXTS: gene_name = str(uuid.uuid4()) new_video_name = gene_name + '.' + ext address = os.path.join('video', new_video_name) file.save(os.path.join(app.config['UPLOAD_FOLDER'], address)) screenshot_name = gene_name + '.jpeg' screenshot_address = os.path.join('video', 'screenshot', screenshot_name) screenshot = VideoStream( os.path.join(app.config['UPLOAD_FOLDER'], address)).get_frame_at_sec(2).image() screenshot.save( os.path.join(app.config['UPLOAD_FOLDER'], screenshot_address)) db = mysql.get_db() cursor = db.cursor() cursor.execute( "insert into video (name, address, screenshot) " "values (%s, %s, %s)", (video_name, address, screenshot_address)) db.commit() if cursor.rowcount != 1: return False, 'insert into db failed' return True, cursor.lastrowid else: return False, 'invalid extension'
def thumbnail(self): filename = STATIC_DIR + self.hash + '.png' try: open(filename) except: logger.debug("Generating new thumbnail.") pil_image = VideoStream(self.full_path)\ .get_frame_at_sec(60).image() pil_image.save(filename) return filename
def video_upload(): path = '/usr/local/nginx/Videos/vod' category = request.forms.get('category') upload = request.files.get('upload') upload.save(path) # appends upload.filename automatically #create thumbnail thumbnail = VideoStream(path + '/' + str(upload.filename)).get_frame_at_sec(3).image() thumbnail.save('./index/static/images/thumbnails/' + str(upload.filename).replace('.flv', '') + '.jpeg') #run transcode module subprocess.call('cd ' + path + ' && ' + './transcode.sh ' + str(upload.filename) + ' ' + str(upload.filename).replace('.flv', ''), shell=True) redirect("/home")
def search(dirname): try: filenames = os.listdir(dirname) for filename in filenames: if dirname[-1] == "/": pass else: dirname = dirname + "/" full_path = os.path.join(dirname, filename) if os.path.isdir(full_path): search(full_path) else: ext = os.path.splitext(full_path)[-1] thum = "%s_" % (datetime.today().strftime('%Y%m%d')) + str( uuid.uuid4())[:8] + ".jpg" small_thum_path = "/DATA/reference_library/thumnail/small_thum/%s" % thum if ext.lower() == ".mp4" or ext.lower() == ".mov" or ext.lower( ) == ".mkv" or ext.lower() == ".avi": try: thumbnail = VideoStream(full_path).get_frame_at_sec( 1).image() thumbnail.save(small_thum_path) full_path = full_path[5:] select_query = "select * from img where full_path = '%s'" % full_path cur.execute("set names utf8") cur.execute(select_query) if cur.rowcount == 0: query = "insert into img(img_path,img_name,full_path,thumnail,type) values('%s','%s','%s','%s','%s')" % ( dirname, filename, full_path, thum, 'video') cur.execute("set names utf8") cur.execute(query) db.commit() else: pass except Exception, e: print e else: pass
def get_video_link_with_thumbnail(item): outfile = item.thumbnail_local try: if not os.path.exists(outfile): # make video thumbnail try: pil_image = VideoStream(item.fullpath).get_frame_at_sec(5).image() except: try: pil_image = VideoStream(item.fullpath).get_frame_at_sec(0.5).image() except: pil_image = VideoStream(item.fullpath).get_frame_at_sec(0).image() size = 250,250 pil_image.thumbnail(size) pil_image.save(outfile) fileOk=True except: fileOk=False out = "" imgPath = item.thumbnail_web if fileOk else ERROR_THUMBNAIL out += "<br/>"+GetLink(item.web_original, "<img style=\"max-width:95%;border:3px solid black;\" src=\""+\ imgPath+"\"><br/>"+("" if fileOk else "ERROR: ")+item.basename_short+"</img>"+"\n", newTab=True) return out
def insert(dirname): select_query = 'select * from img where img_path="%s"'%path cur.execute("set names utf8") cur.execute(select_query) results = cur.fetchall() db_path_arr = [] for i in results: db_path_arr.append(i[3]) diff_arr = [] for a in path_arr: if a not in db_path_arr: diff_arr.append(a) for full_path in diff_arr: ext = os.path.splitext(full_path)[-1] thum = "%s_" % (datetime.today().strftime('%Y%m%d')) + str(uuid.uuid4())[:8] + ".jpg" small_thum_path = "/DATA/reference_library/thumnail/small_thum/%s"%thum filename = os.path.split(full_path)[-1] if ext.lower() == ".mp4" or ext.lower() == ".mov" or ext.lower() == ".mkv" or ext.lower() == ".avi" or ext.lower() == ".webm": try: duration = int(VideoStream(full_path).duration/2) thumbnail = VideoStream(full_path).get_frame_at_sec(duration).image() thumbnail.save(small_thum_path) except Exception, e: print e select_query = 'select * from img where full_path = "%s"' % full_path[5:] cur.execute("set names utf8") cur.execute(select_query) if cur.rowcount == 0: try: codec = VideoStream(full_path).codec_name print codec if codec == "h264" or codec =="aac": full_path = full_path[5:] query_o = 'insert into img(img_path,img_name,full_path,thumnail,type) values("%s","%s","%s","%s","%s")' % (path,filename,full_path,thum,'video') # print query_o cur.execute("set names utf8") cur.execute(query_o) db.commit() else: full_path = full_path[5:] query = 'insert into img(img_path,img_name,full_path,thumnail,type) values("%s","%s","%s","%s","%s")'%(path,filename,full_path,'codec.png','video') # print query cur.execute("set names utf8") cur.execute(query) db.commit() except Exception,e: pass else: pass
def createVideoThumbnail(fileId, fullPath, thumbnailSize, thumbnailsRoot): videoImage = VideoStream(fullPath).get_frame_at_sec(int(getVideoDuration(fullPath) / 2)).image() videoImage.save('videoPreviewTemp.jpg') createImageThumbnail(fileId, 'videoPreviewTemp.jpg', thumbnailSize, thumbnailsRoot)