How to Convert and Save Uploaded Video File to M3U8 Format Using Django?

181 Views Asked by At

I'm working on a Django project where users can upload video files, and I need to convert these uploaded videos into the M3U8 format for streaming purposes. Could anyone provide guidance or a code example on how to achieve this conversion and save the resulting M3U8 file using Django? I'm open to using any libraries or tools that could simplify this process. Thanks in advance for any help or suggestions!

# models.py

class Video(AdvertisementModelMixin):
    text = models.CharField(max_length=255)
    description = models.TextField()
    image = WEBPField(
        verbose_name='Image',
        upload_to=video_folder,
    )
    video = models.FileField(
        upload_to='video/',
        validators=[FileExtensionValidator(
            allowed_extensions=[
                'MOV',
                'avi',
                'mp4',
                'webm',
                'mkv',
                'm'
            ])
        ]
    )
    skip_duration = models.PositiveSmallIntegerField(
        null=True,
        blank=True,
        validators=[
            MinValueValidator(3),
            MaxValueValidator(20)
        ]
    )

    def __str__(self):
        return f"{self.id}. {self.text}"

    class Meta:
        verbose_name = "video"


# views.py

class VideoViewSet(ModelViewSet):
    queryset = (Video.objects.all()
                .prefetch_related("devices")
                .prefetch_related("provinces"))
    serializer_class = VideoSerializer
    pagination_class = AdsPagination
    ads_type = "video"
0

There are 0 best solutions below