I am trying to use the same command line YouTube uses for quality etc. in H.264/MP4 containers. I have been working on converting videos into multiple formats, scales, sizes and adjusting the bit rates and audio rates to match what YouTube said they use.
In a nut shell here is what I use:
-pix_fmt yuv420p -profile:v baseline -level 3.0 -acodec libfaac -ar 44100 -ac 2 -ab 192k -aspect 16:9 -r 24000/1001 -movflags +faststart
Now if I am to elaborate on why these values are what they are You should first see what YouTube tell us themselves what they use here.
- https://support.google.com/youtube/answer/1722171?hl=en
- https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
So let's go into detail
- moov atom at the front of the file (Fast Start)
- Channels: Stereo or Stereo + 5.1
- Sample rate 96khz or 48khz
- Progressive scan (no interlacing)
- High Profile
- 2 consecutive B frames
- Closed GOP. GOP of half the frame rate.
- CABAC
- Chroma subsampling: 4:2:0
- Frame rate
- YouTube uses 16:9 aspect ratio players.
- Audio codec: AAC-LC
In ffmpeg's command line these become the following.
-movflags +faststart
-ac 2
-ar 48000
- Not sure what the command for this is. (FFMPEG By default encoding is progressive.)
-profile:v high -level 4.0
-bf 2
(FFMPEG's default is 16.)-g 12
or-g 15
varies on YouTube's FPS. (The default, 12, works for 24-25 fps. For NTSC and 30 fps, select 15.* FFMPEG option:-g
, Not sure what youtube's default FPS is if it is 24 or 30. I assume 24 since the default 12 would be half the frame rate and 15 if their frame rate is 30.)-coder 1
(By default CABAC is the entropy encoder used by x264.)-pix_fmt yuv420p
(My opinion everyone needs to add this mandatory, or perhaps all non-FFmpeg based players do not support proper decoding of YUV 4:2:2 or YUV 4:4:4. So yuv 4:2:0 is required.)-r 24000/1001
(Assume YouTube's default frame rate is 24.)-aspect 16:9
-acodec libfaac
But I know there are probably some commands I am missing or need changing if anyone would be so kind to help. And correct / tell me what I need to change / add.
Because I want to use a baseline profile I do not use CABAC, GOP or B-Frames in my command line, since they all become disabled and irrelevant.
-aspect
. It will mess up your encoding.youtube-dl
and then analyze the bitstream yourself regarding GOPs, B-frame types, et cetera. The real question is: why do you want to match these settings so closely? What's the use case? (If you want 24 fps, just set-r 24
...)