I have a model for Video:

class Video(models.Model):
    title = models.CharField(max_length=75)
    pubdate = models.DateTimeField(default=timezone.now)
    original_video = models.FileField(upload_to=get_upload_file_name)
    mp4_720 = models.FileField(upload_to=get_upload_file_name,blank=True,
null=True)
    converted = models.BooleanField(default=False)

And this is the view:

def upload_video(request):
    if request.POST:
        form = VideoForm(request.POST, request.FILES)
        if form.is_valid():
            video = form.save(commit=False)
            video.save()
            convert_video.delay(video.id)
            return HttpResponseRedirect('/')

Lastly the tasks.py:

def get_upload_file_name(video):
    name = video.title
    name = name+'.mp4'
    return name

from pyvid.settings import MEDIA_ROOT

@app.task
def convert_video(video_id):
    video = Video.objects.get(id=video_id)
    video_path = str(MEDIA_ROOT)+'/'+str(video.original_video)
    convert_video_name = get_upload_file_name(video)
    cmd = 'ffmpeg -i %s -codec:v libx264 -profile:v baseline -preset slow
-b:v 250k -maxrate 250k -bufsize 500k -vf scale=-1:360 -threads 0 -codec:a
libfdk_aac -movflags +faststart %s.mp4' % (video_path, convert_video_name)
    subprocess.call(
        cmd,
        shell=True
    )

    video.mp4_720 = convert_video_name
    video.converted = True
    video.save()

The problem is, even though video.mp4_720 is directed to
upload_to=get_upload_file_name,
its just taking the value of convert_video_name file path (which is in the
base directory of the project) but not to the path applied.

How do I upload the new converted file it to the uploaded path?

Thank you

-- 
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 [email protected].
To post to this group, send email to [email protected].
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-nGp8_TW6JdW4D7iKOgAYE9zOFzc1bE-1kUjPj-p9e1somA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to