Home > Blockchain >  Video upload and view in different resolution in django
Video upload and view in different resolution in django

Time:02-04

I am building a video streaming app like youtube in django for learning purposes. I want to implement the functionality of uploading video by user and view it in different resolutions like 360p, 480p etc. I dont know how to achieve this..

Should I save all the versions of video?? Wouldn't that be redundant??

Also how to convert the video in different resolutions!

I want to use aws s3 for this.

CodePudding user response:

Yes, I think you have to save all the versions of your video. I don't think you can resize a video from Python. Maybe you should use a subprocess, like ffmpeg:

Example (this example change the size and delete the original video, assuming that the video is a models.FileField):

def do_video_resize(video):
 filename = video.file.path.split('/')[-1]
 if ffmpeg('-v', '-8', '-i', video.file.path, '-vf', 'scale=-2:480', '-preset', 'slow', '-c:v', 'libx264', '-strict', 'experimental', '-c:a', 'aac', '-crf', '20', '-maxrate', '500k', '-bufsize', '500k', '-r', '25', '-f', 'mp4', ('/tmp/'  filename ), '-y'):
    resized_video = open('/tmp/'   filename)
    video.file.save(filename ,File(resized_video))
    resized_video.close()
    os.remove('/tmp/'  filename)
    return video

def ffmpeg(*cmd):
  try:
    subprocess.check_output(['ffmpeg']   list(cmd))
  except subprocess.CalledProcessError:
    return False
  return True
  •  Tags:  
  • Related