The task is just a function, you finished the tutorial, it's the same thing
@app.task
def trascode(video):
subprocess.call('ffmpeg -i path/.../original path/.../mp4_720') # Change the path to the one given by video.original
video.mp4_480 = # Something
video.mp4_720 = # Something else
video.save()
On Fri, Feb 20, 2015 at 11:18 AM, Robin Lery <robinlery@gmail.com> wrote:
Thank you.So mp4_480 and mp4_720 should be blank=True and null=True. And then pass the video instance object to the delay() ???And also, could you please show me how to write the tasks.py, so that I can use ffmpeg code (subprocess.call('ffmpeg -i path/.../original path/.../mp4_720') to transcode.--On Fri, Feb 20, 2015 at 6:49 PM, Vijay Khemlani <vkhemlan@gmail.com> wrote:To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei0fjxCurSdVufpqj5hpzCGadMq_tQky_POGoXm%2B6GtSfA%40mail.gmail.com.Then in your task function you can get the file from the video model instance, trascode it, and store it in the corresponding fields of the object (mp4_480, mp4_720)--On Fri, Feb 20, 2015 at 10:18 AM, Vijay Khemlani <vkhemlan@gmail.com> wrote:I would do something like thisvideo = Video()video.original = form.cleaned_data['video'] # Assuming the form field is "video"video.user = uservideo.title = form.cleaned_data['title'] # Assuming the form field is "title"video.save() # You might need to make the mp4_480 and mp4_720 fields "nullable" on the modelyourapp.tasks.transcode_video.delay(video) # Assuming the task is the "transcode_video" function.return HttpResponseRedirect('/')ThenOn Fri, Feb 20, 2015 at 10:04 AM, Robin Lery <robinlery@gmail.com> wrote:I would like to transcode user uploaded videos using celery. I think first I should upload the video, and spawn a celery task for transcoding.--
Maybe something like this in the tasks.py:subprocess.call('ffmpeg -i path/.../original path/.../output')
Just completed First steps with celery, so confused how to do so in the `views.py` and `tasks.py`. Also is it a good solution? I would really appreciate your help and advice. Thank you.
models.py:class Video(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=100)
original = models.FileField(upload_to=get_upload_file_name)
mp4_480 = models.FileField(upload_to=get_upload_file_name)
mp4_720 = models.FileField(upload_to=get_upload_file_name)
privacy = models.CharField(max_length=1,choices=PRIVACY, default='F')
pub_date = models.DateTimeField(auto_now_add=True, auto_now=False)
my incomplete views.py:@login_required
def upload_video(request):
if request.method == 'POST':
form = VideoForm(request.POST, request.FILES)
if form.is_valid():
if form.cleaned_data:
user = request.user
#
#
# No IDEA WHAT TO DO NEXT
#
#
return HttpResponseRedirect('/')
else:
form = VideoForm()
return render(request, 'upload_video.html', {
'form':form
})
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B4-nGoz%3D_qCx%2BbSnOfNFLYiufqUUES3S3T9y4GXoZiaBV9tyw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B4-nGrcbmeq4WxHr%2Bo59fqPTdzC5rLjq2DaQLHurgVE8NsSrQ%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei22HjyZJqdH%2B6SeFRPsGf2Zq83fAp1SeURCQLCyJ8VFNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment