5

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.

So let's go into detail

  1. moov atom at the front of the file (Fast Start)
  2. Channels: Stereo or Stereo + 5.1
  3. Sample rate 96khz or 48khz
  4. Progressive scan (no interlacing)
  5. High Profile
  6. 2 consecutive B frames
  7. Closed GOP. GOP of half the frame rate.
  8. CABAC
  9. Chroma subsampling: 4:2:0
  10. Frame rate
  11. YouTube uses 16:9 aspect ratio players.
  12. Audio codec: AAC-LC

In ffmpeg's command line these become the following.

  1. -movflags +faststart
  2. -ac 2
  3. -ar 48000
  4. Not sure what the command for this is. (FFMPEG By default encoding is progressive.)
  5. -profile:v high -level 4.0
  6. -bf 2 (FFMPEG's default is 16.)
  7. -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.)
  8. -coder 1 (By default CABAC is the entropy encoder used by x264.)
  9. -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.)
  10. -r 24000/1001 (Assume YouTube's default frame rate is 24.)
  11. -aspect 16:9
  12. -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.

7
  • 3
    1. Posting the PHP source here probably won't help a lot. Not everybody understands PHP, so even they know the answer they can't answer. 2. Encoding 4K in baseline is incredibly dumb. 3. Don't set -aspect. It will mess up your encoding.
    – Timothy Gu
    Jan 20, 2015 at 7:49
  • Thanks i edited my code above and put $fcmd into it so i can control the command line properties for each size/quality of video being generated 360p 480 etc under 4k and 2k should i set them both to use -profile:v high ?
    – C0nw0nk
    Jan 20, 2015 at 15:35
  • 1
    The YouTube link you have just shows how you should code your videos for uploading to YouTube. It's not necessarily what they are using internally (and I know this for a fact). If you want 24 FPS, why are you using 24000/1001?
    – slhck
    Jan 20, 2015 at 15:37
  • So nobody knows what command line they use internally ? I read thats how you set the rate to be 24 ?
    – C0nw0nk
    Jan 20, 2015 at 15:39
  • 3
    Well, YouTube people know, of course, and a few researchers with whom they work together (I've talked to one at a conference recently). You can also just download MP4s from YouTube in all kinds of formats (itags), e.g. using 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...)
    – slhck
    Jan 20, 2015 at 15:41

0

You must log in to answer this question.

Browse other questions tagged .