Здравствуйте еще раз, подскажите пожалуйста куда вставить этот код
subprocess.call(['ffmpeg', '-i', 'hobbit.mp4', '-vframes', '1', '-ss', '00:01:48', '-an', '-vcodec', 'png', '-f', 'rawvideo', '-s', '320x240', 'out.png',])
Я его добавил в функцию handle_uploaded_file вот полный код:
# -*- coding: utf-8 -*-
from django.shortcuts import render, render_to_response, redirect
from django.http import HttpResponse, HttpResponseRedirect
from love.models import FileToUpload
from love.forms import UploadFileForm
from django.http import HttpResponseBadRequest, Http404
from django.template import RequestContext
import os
from django.conf import settings
import subprocess
os.chdir('C://moi/media/')
def show_video (request) :
clips = FileToUpload.objects.all()
return render_to_response('love/uploads_list.html', {"clips": clips})
def upload_file(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid() and form.is_multipart():
handle_uploaded_file(request.FILES['file'])
form.save()
return HttpResponseRedirect('/uploads_list') # which renders `uploads_list.html` page
else:
form = UploadFileForm()
return render_to_response('love/uploads_form.html', {'form': form,'total_files':os.listdir(settings.MEDIA_ROOT),'path':settings.MEDIA_ROOT},context_instance=RequestContext(request))
def handle_uploaded_file(file,path=''):
filename = file._get_name()
destination_file = open('%s/%s' % (settings.MEDIA_ROOT, str(path) + str(filename)), 'wb+')
for chunk in file.chunks():
destination_file.write(chunk)
destination_file.close()
subprocess.call(['ffmpeg', '-i', 'hobbit.mp4', '-vframes', '1', '-ss', '00:01:48', '-an', '-vcodec', 'png', '-f', 'rawvideo', '-s', '320x240', 'out.png',])
Правильно ли я сделал?
Updated 10 Dec. 2014, 13:30 by adbastana2014.