Change the quality of online video?

Asked

Viewed 833 times

4

How do websites such as Youtube and Facebook offer different qualities for uploaded videos? Is there any specific tool/code to change the quality of the videos, or do they encode and save the video files in different formats? 360p, 480p, 720p, 1020p ... How this question works?

2 answers

6


When you upload a video to Youtube it detects the quality of the uploaded version, the uploaded video will be the highest quality available, the lower qualities will be rendered by Youtube.

By default, because of performance (and storage) Youtube will compress the videos and can change the quality. That’s why Vimeo is highlighted for having higher video quality, since it has less compression (and so usually the same 1080p takes 10 times more to load on Vimeo compared to Youtube).

Your question includes the "ffmpeg" tag, which can be used for this. :)

Compacting via CLI with ffmpeg:

I will use CMD but you can run it using PHP exec().

For example I’m using this video: https://pixabay.com/pt/videos/p%C3%B4r-do-sol-campo-paisagem-5933/

Taking the current "resolution":

ffmpeg.exe -i "Sunset - 5933.mp4"

This will return:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Sunset - 5933.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.4.101
  Duration: 00:00:13.44, start: 0.021016, bitrate: 5006 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 5003 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler

A better alternative is to use ffprobe, see this response.

Meanwhile through the 1920x1080 you already know it’s 1080p.

Making 1080p in 720p:

ffmpeg.exe -i "Sunset - 5933.mp4" -vcodec libopenh264 -s 1280x720 -aspect 1280:720 "Sunset - 720.mp4"

Now you will have two files, one for 1080p and the other for 720p. The -vcodec is the video codec, you must use the ffmpeg.exe -i to see which libraries are compiled, look for libopenh264 or by libx264 you own. The -s is the size of the archive and the -aspect is the proportion.

You can also "render" the audio too so you can use the -acodec to set an audio codec, the most common is the libmp3lame and you can then change the bitrates and the like. Otherwise, by default the audio will remain identical.

Heed:

The vcodec most common is the libx264, but he’s on leave from GPL which may not be very good for some situations, especially for proprietary (unopened) software. They offer a commercial license as well, which I believe is not GPL. For this reason I use (as mentioned in the example) the vcodec of libopenh264 he’s on leave BSD (see here), being more free and still free. But it has less resources and less used, including many standard ffmpeg distributions do not include the libopenh264. ffmpeg in general is about LGPL, which is more free. In the case of LGPL your software must make a "link" with ffmpeg, being still distinct software.

  • Wow Thanks man, I will study a little more about ffmpeg and ffprobe because I will need them soon, vlw by the full answer

-4

When you watch a video on Youtube, you are downloading a file, so the quality identifies the file you are downloading, so for each quality, there is a different file. That’s why sometimes when the video has bad quality it has only one resolution.

  • Your "answer" does not answer the question, in my view. The question is precisely how Youtube does to create "every file". Who "Upa" the video only sends a quality (e.g. 1080p), Youtube generates the 360p. The question, as I understand it, is precisely how Youtube generates 360p from 1080p.

  • "Is there any specific tool/code to change the quality of the videos, or do they encode and save the video files in different formats?" That was the question, and it was answered.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.