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, for performance (and storage) YouTube will compress your videos and can change quality. Even so, Vimeo stands out for having higher video quality, since it has less compression (and therefore usually the same 1080p takes 10 times more to load on Vimeo than YouTube).
Your question includes the "ffmpeg" tag, which can be used for this. :)
Compressing via CLI with ffmpeg:
I will use CMD but you can do this using PHP's exec ().
For example, I'm using this video: link
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 answer .
However through 1920x1080
already knows that it is 1080p.
Making 1080p in 720p:
ffmpeg.exe -i "Sunset - 5933.mp4" -vcodec libopenh264 -s 1280x720 -aspect 1280:720 "Sunset - 720.mp4"
You will now have two files, one for 1080p and one for 720p. -vcodec
is the video codec, you should use ffmpeg.exe -i
to see which libraries are compiled, search for libopenh264
or libx264
you own. The -s
is the size of the file and the -aspect
is the ratio.
You can also "render" the audio also so you can use -acodec
to define an audio codec, most common is libmp3lame
and you can then change the bitrates and the like. Otherwise, by default the audio will remain the same.
Attention:
The% most common% is vcodec
, however it is in the libx264
license which may not be very good for some situations, especially for proprietary (non-open) software. They offer a commercial license too, which I believe is not GPL. For this reason I use (as mentioned in the example) GPL
of vcodec
it is on license libopenh264
(see here) , being more free and still free. But it has fewer features and less use, and many standard ffmpeg distributions do not include BSD
. The ffmpeg in general is on LGPL, which is freer. In the case of the LGPL your software should link to ffmpeg, being software still distinct.