1

I am creating a streaming app like youtube while I am creating it I am facing many challenges related to different quality video converting.

My question is

Should I convert orginal video file into multiple video file (like 240p, 480p and 720p) and storage them? Or there is anyway where I can create a single video file which can be play in multiple qualities like youtube.

laxec61532
  • 29
  • 2
  • 1
    If there is such a video format it does not make sense to use it. Your server should only send the video of one quality to the client. It does not make sense to have a file with 4k and 140p in it and if I want to watch 140p to download the 140p+4k video file which will take a couple of hours vs a couple of seconds for what I actually want. Youtube does not dynamically downscale either, they precompute the different resolutions, anything else is far too slow. – luk2302 Apr 22 '21 at 17:40
  • Generally wether or not you want multiple different resolutions depends on what you actually want to offer. Nobody is stoping you from just offering the video file as originally uploaded. If you want multiple resolutions, you need to convert / downscale the original one. – luk2302 Apr 22 '21 at 17:41
  • If you've ever uploaded on youtube you know that it can take forever before your video is available in all resolutions. This is because they first convert it and store the different versions. – Emanuel P Apr 22 '21 at 18:04

1 Answers1

1

Multiple video files is the way to go. Currently, the most common approach to adaptive streaming is MPEG-DASH. The different video sizes and a MPD manifest, which is like a playlist for the different video sizes, can be generated using ffmpeg and mp4box. Many videoplayers, e.g. Video.js or Dash.js support adaptive streaming with MPEG-DASH.

Generate video files:

ffmpeg -y -i movie.avi -an -c:v libx264 -x264opts 'keyint=24:min-keyint=24:no-scenecut' -b:v 1500k -maxrate 1500k -bufsize 3000k -vf "scale=-1:720" movie-720.mp4
ffmpeg -y -i movie.avi -an -c:v libx264 -x264opts 'keyint=24:min-keyint=24:no-scenecut' -b:v 800k -maxrate 800k -bufsize 1600k -vf "scale=-1:540" movie-540.mp4
ffmpeg -y -i movie.avi -an -c:v libx264 -x264opts 'keyint=24:min-keyint=24:no-scenecut' -b:v 400k -maxrate 400k -bufsize 800k -vf "scale=-1:360" movie-360.mp4
ffmpeg -y -i movie.avi -vn -c:a aac -b:a 128k movie.m4a

Generate the manifest:

mp4box -dash-strict 2000 -rap -frag-rap -bs-switching no -profile "dashavc264:live" -out movie-dash.mpd movie-720.mp4 movie-540.mp4 movie-360.mp4 movie.m4a

Original source: https://gist.github.com/andriika/8da427632cf6027a3e0036415cce5f54

malat
  • 12,152
  • 13
  • 89
  • 158
stekhn
  • 1,969
  • 2
  • 25
  • 38