S
S
Sergey Eremin2018-02-21 13:43:41
Django
Sergey Eremin, 2018-02-21 13:43:41

How to trigger "generation" of other video formats in django-videokit?

Decided to use the django-videokit ( git ) battery for a small Python/Django project . And in general, it almost worked for me. But it is not clear why the creation (conversion) of the source video to other formats does not occur. Django-videokit should launch the ffmpeg utility through Celery and “cook” video files of the required formats ( .mp4 , .ogg and .webm ). Links to these files will appear in the corresponding fields VideoSpecField.
In models.py, everything is almost like in the documentation:

from videokit.models import VideoField, VideoSpecField
from my_project import settings

class tbVideoItems(models.Model):
    szVideoName = VideoField(
        upload_to = settings.PATH_FOR_VIDEO,
        null = True,
        blank = True,
        width_field = 'iVideoWidth',
        height_field = 'iVideoHeight',
        rotation_field = 'fVideoRotation',
        mimetype_field = 'szVideoMimetype',
        duration_field = 'iVideoDuration',
        thumbnail_field = 'imgVideoThumbnail'
    )
    iVideoWidth = models.IntegerField(null = True, blank = True)
    iVideoHeight = models.IntegerField(null = True, blank = True)
    fVideoRotation = models.FloatField(null = True, blank = True)
    szVideoMimetype = models.CharField(max_length = 32, null = True, blank = True)
    iVideoDuration = models.IntegerField(null = True, blank = True)
    imgVideoThumbnail = models.ImageField(null = True, blank = True)

    szVideoName_ogg = VideoSpecField(source = 'szVideoName', format = 'ogg')
    szVideoName_webm = VideoSpecField(source = 'szVideoName', format = 'webm')

    class Meta:
        verbose_name = u"Видео-ролик"
        verbose_name_plural = u"Видео-ролики"
        ordering = ['szVideoName']

The original video is "sucked in" and the iVideoWidth , iVideoHeight , fVideoRotation , szVideoMimetype and iVideoDuration fields are set to the correct values. The imgVideoThumbnail thumbnail is created . The fields VideoSpecField( szVideoName_mp4 , szVideoName_ogg and szVideoName_webm ) remain empty. We need to start generating. To do this, in views.py(for example) we write. something like:
# ...
qVideos = tbVideoItems.objects.all()
    for i in qVideos:
        if i.szVideoName_ogg == "":
            i.szVideoName_ogg.generate()
        # ...
# ...

Accordingly, the generation starts. On the second call views.py, you can see that szVideoName_ogg has a value. When viewing field values ​​(via the admin panel or via print i.szVideoName_ogg), the values ​​change. For example:
the videos / the Futurama-S7e01 \ fc54f1c9ace5c6403763ae772a59adc6.ogg
a couple of seconds:
the videos / the Futurama-S7e01 \ c57acb82ed465ed362f190495d9c4990.ogg
still a couple of seconds:
the videos / the Futurama-S7e01 \ ed046299f6622802ca36f76961b8aebf.ogg
and so on ...
In the target folder no .ogg there are no files. For control, I checked: in general, there is not a single .ogg anywhere on the disk (including temporary folders) .
What is also remarkable: when running under *nix, video files "sucked" through szVideoName , do not have read status and, accordingly, cannot be given to the client by the web server:
$ ls -l
-rw------- 1 web web   69537154 фев 27 17:05 Futurama-S7E07.mp4
-rw-r--r-- 1 web web      13053 фев 27 17:05 Futurama-S7E07.mp4.thumb.jpg

At the same time, the created preview ( .thumb.jpg ) has all right with the rights. Under Widows, there are no such problems and the video file remains via the web.
I have a hypothesis that somehow Celery picks up the file and does something with it (or tries). But what?!
In django-videokit itself, there is task.pya description of creating a process for converting and creating a file:
process = subprocess.Popen(
    ['ffmpeg', '-i', source_file, '-y'] + options + [temp_file])

But now this process is being created, and if it is being created, does it work?
django-videoki mentions that somehow you can check the status of creating alternative video files, but does not say how :(.
Everything is complicated by the fact that this is my first experience using Celery and how the initialization of queues, execution of tasks, etc. -- I don't understand. Neither RabbitMQ nor Cellery configured in any way (out of the box). I don't understand where to "dig". Help.
PS The instructions for installing django-videokit indicate that you must first install RabbitMQ. But in the requirements.txtexample it is indicated, among other things also redis==2.10.5 In code
celery.py<code> примера тоже сипользуют Redis... Мне не понятно как и кто тогда управляет очередями.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2018-03-11
@Sergei_Erjemin

when launched under *nix, video files “sucked in” via szVideoName do not have read status and, accordingly, cannot be given to the client by the web server

If the web server is running under the web user, then the rights -rw------- mean read and write access for this very user, which means that the return of the web server is possible. This is easy to check by trying to download this file with curl, for example.
Celery does exactly what is specified in the body of the corresponding tasks described in the django-videokit project. If it is curious, it is necessary to look for "batteries" in source codes.
First, it's worth reading the celery logs, there will probably be some startup errors (for example, the lack of ffmpeg on the machine :-) ). Secondly, ffmpeg swears at any error with a non-zero response code. If django-videokit doesn't check this response code, it's a bad battery.
This is a very broad question, to answer which you need to explain the basics of the AMQP protocol that implements RabbitMQ, half of the Celery documentation "and the like".
Briefly, the scheme is as follows:
Traditionally, celery uses RabbitMQ to submit tasks and Redis to store the results of their execution.
Queues (their settings) are managed by Celery, declaring them at the start of workers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question