本文整理汇总了Python中models.Video.dataset方法的典型用法代码示例。如果您正苦于以下问题:Python Video.dataset方法的具体用法?Python Video.dataset怎么用?Python Video.dataset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Video
的用法示例。
在下文中一共展示了Video.dataset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_uploaded_file
# 需要导入模块: from models import Video [as 别名]
# 或者: from models.Video import dataset [as 别名]
def handle_uploaded_file(f, name, extract=True, user=None, rate=30, rescale=0):
video = Video()
if user:
video.uploader = user
video.name = name
video.save()
primary_key = video.pk
filename = f.name
filename = filename.lower()
if filename.endswith('.dva_export.zip'):
create_video_folders(video, create_subdirs=False)
with open('{}/{}/{}.{}'.format(settings.MEDIA_ROOT, video.pk, video.pk, filename.split('.')[-1]),
'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
video.uploaded = True
video.save()
task_name = 'import_video_by_id'
import_video_task = TEvent()
import_video_task.video = video
import_video_task.save()
app.send_task(name=task_name, args=[import_video_task.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
elif filename.endswith('.mp4') or filename.endswith('.flv') or filename.endswith('.zip'):
create_video_folders(video, create_subdirs=True)
with open('{}/{}/video/{}.{}'.format(settings.MEDIA_ROOT, video.pk, video.pk, filename.split('.')[-1]),
'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
video.uploaded = True
if filename.endswith('.zip'):
video.dataset = True
video.save()
if extract:
extract_frames_task = TEvent()
extract_frames_task.arguments_json = json.dumps({'rate': rate,'rescale': rescale})
extract_frames_task.video = video
task_name = 'extract_frames' if video.dataset else 'segment_video'
extract_frames_task.operation = task_name
extract_frames_task.save()
app.send_task(name=task_name, args=[extract_frames_task.pk, ],
queue=settings.TASK_NAMES_TO_QUEUE[task_name])
else:
raise ValueError, "Extension {} not allowed".format(filename.split('.')[-1])
return video