Which Codec should be used on video to avoid Recompression in youtube & vimeo

Solution 1:

You cannot avoid YouTube or others recompressing your input video. They'll never take it as-is. This has been confirmed by YouTube researchers. A quote from a YouTube research paper:*

[We] normalize files before transcoding by creating a high-bitrate, constant-frame-rate mezzanine.

There are multiple reasons for that:

  1. Video codecs/formats can be weird (for the lack of a better word). Lots of different encoders exist, and they might produce bitstreams with special attributes that may not be supported by all components of the streaming architecture. For example, decoding might not properly work, there may be wrong timestamps, and, perhaps a user was trying to upload a malicious file, trying to exploit bugs in the software. You don't want to deal with that. You want to have a single kind of video format (an "intermediate format" or "mezzanine") where you know that it's not going to break your existing infrastructure. So you'll convert the incoming video to that format and any further processing is going to be easier.

  2. Optimization of quality: YouTube and others know best how they need to compress videos such that the output is of good quality and low bitrate. They spend massive amounts of CPU time and human efforts into optimizing that aspect. They wouldn't just take your video as-is.

  3. HTTP Adaptive Streaming as it's used these days requires generating different sets of videos for different client types (e.g., 4K streaming to a modern browser on the desktop is different from streaming low-res video to a legacy Android device). So even if you had a well-compressed input file, YouTube would have to generate dozens of alternative, scaled versions anyway.

* Covell et al. 2016, Optimizing Transcoder Quality Targets Using a Neural Network with an Embedded Bitrate Model

Solution 2:

There is a great answer on avp.stackexchange.com for YouTube-codecs and more

Some general info about the formats used: YouTube uses 4 container formats and 3 diffrent codecs. It depends on the popularity of the video what codecs are used for your video (see below why). Generally, every of your uploaded video will be encoded in h.264 and will be muxed into an .flv and .mp4 container. Thats the standard and this will hapen for every video. Though .flv will only be used for resolutions below 720p. Meaning only 360p and 480p will exist in an .flv container. Though every video below 720p will also have a mp4 version for the highest available resolution, either 360p or 480p. For 240p YouTube is using 3gp which is an rather old codec meant for mobile devices (long before the smartphone era), it also comes in the conatainer .3gp.

The other codec used is VP8 which is coming in the WebM container format. WebM is a format developed by Google and was meant as a standard video codec for HTML5, though the support for it is not very big. Even on YouTube only very few videos are encoded in WebM, WebM was introduced with the HTML5 version of YouTube. YouTube only encodes some videos in WebM after they got uploaded and mostly only popular videos (going by the videos I saw encoded in WebM) so its not certain your video will be present in WebM.

In regard of your linked question (maybe they should be merged?)

What codec/container should you use for uploading?

That depends, if you are limited/concerned by your upload speed then use h.264 Level 3.1/4.1 with Main Profile for SD or High Profile for HD and AAC audio. YouTube will accept this just fine and it will look nice after it got encoded by the YouTube servers. But be aware that YouTube will ALWAYS encode your video once its uploaded, doesn't matter what codec and settings you use. So if you want the theoretically best quality for your uploads choose a lossless codec for uploading or atleast visually lossless. See YouTube as the final output into a delivery/consumer format and the upload to YouTube is the last step in production and during production you want to stay lossless. But please note this is all just a theoretical thing, pracitically I'd say it really doesn't matter as we are talking about YouTube and not about TV broadcast or Cinema.

But if you really want to do it the "perfect" way, use a production codec and not a consumer codec like h.264. MJPEG would be a good codec for that, YouTube definitely supports that in an .avi or .mov container. MJPEG is a lossy codec but the visual quality will be the same as the source (if you chose a high enough quality setting, this is practically JPEG as video codec). Going with a real lossless codec would be a waste of hard-drive space and bandwidth in my opinion.

But if you want to upload your video truely lossless and don't care about the upload time, I recommend using a standard QuickTime codec as they should be nearly all supported by YouTube (note that not all of them are lossless, h264 is also a standard QuickTime codec). Though YouTube doesn't state which QuickTime codecs are supported unfortunately. Animation or JPEG2000 should work I guess. Both codecs can be 100% lossless.

For the audio use PCM if you want to stay lossless with the audio aswell but again this is really just a theoretical quality improvement. AAC will do the same job quality wise and will be smaller. I recommend a bitrate of atleast 192kbps for AAC. YouTube will convert that to ~24kbps(Mobile aka 3gp) ~64kbps(240p), ~128kbps(360p/480p) and ~192kbps(720p+).

When it comes to frame rates, if you can choose then use 25FPS during recording/animating, YouTube likes that the most (the frame rate used for every video) but if your footage comes already in another frame rate then stick with that and don't interpolate up or down to 25FPS. YouTube will handle the conversion for you and generally does that better then your encoder. They have to deal with all kind of framerates everyday and solved this (actually very complicated) issue really well.

For vimeo you should take a look at the vimeo-guidelines. You should use the H.264-codec. Because then they don't need to decompress it

Guidelines:

Codec: H.264

A codec is the format in which your video will be encoded. Vimeo accepts most major video codecs, but for best results we recommend using H.264. If you’re uploading High Definition (HD) video, choose the High Profile H.264 setting instead of Main Profile. Advanced H.264 settings: To make your uploads extra smooth, choose the following advanced settings whenever possible.

  • Closed GOP
  • CABAC (to reduce your file size)