Answers.Body: <p>Use</p>
  <pre><code>ffmpeg -i in.mp4 -vf yadif,format=yuv420p -force_key_frames &quot;expr:gte(t,n_forced/2)&quot; -c:v libx264 -crf 18 -bf 2 -c:a aac -q:a 1 -ac 2 -ar 48000 -use_editlist 0 -movflags +faststart out.mp4
  </code></pre>
  <p><code>-vf</code> specifies video filters</p>
  <p><code>yadif</code> will deinterlace videos if they're interlaced.</p>
  <p><code>format=yuv420p</code> will produce pixel format with 4:2:0 chroma subsampling.</p>
  <p><code>-force_key_frames &quot;expr:gte(t,n_forced/2)&quot;</code> will place keyframes every half-second, so that will be the GOP size.</p>
  <p><code>-c:v libx264</code> will use the x264 encoder to produce a H264 video stream.</p>
  <p><code>-crf 18</code> will produce a visually lossless file. Better than setting  a bitrate manually.</p>
  <p><code>-bf 2</code> will limit consecutive B-frames to 2</p>
  <p><code>-c:a aac</code> will use the native encoder to produce an AAC audio stream.</p>
  <p><code>-q:a 1</code> sets the highest quality for the audio. Better than setting  a bitrate manually.</p>
  <p><code>-ac 2</code> rematrixes audio to stereo.</p>
  <p><code>-ar 48000</code> resamples audio to 48000 Hz.</p>
  <p><code>-use_editlist 0</code> avoids writing edit lists.</p>
  <p><code>-movflags +faststart</code> places moov atom/box at front of the output file.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-05T15:16:36.480Z
Answers.Text: I believe you wrote this answer using this [Recommended Upload Settings](https://support.google.com/youtube/answer/1722171) as reference. Here's the command for [Content ID Partners](https://support.google.com/youtube/answer/6039860): `ffmpeg -i in.mp4 -vf yadif,format=yuv422p -force_key_frames expr:gte(t\,n_forced/2) -c:v libx264 -b:v <60M for 1080, 50M for 720, 15M for SD> -bf 2 -c:a flac -ac 2 -ar 44100 -use_editlist 0 -movflags +faststart out.mp4`.
Answers.UserDisplayName: MCCCS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-15T06:36:32.793Z
Answers.Text: Any idea how I can run this on fish shell where parentheses `(t\,n_forced/2)` are interpreted as a command?
Answers.UserDisplayName: andrewgazelka
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-15T06:55:17.833Z
Answers.Text: Enclose `expr:gte(t\,n_forced/2)` in single or double quotes, I guess
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-15T09:51:38.283Z
Answers.Text: -force_key_frames "expr:gte(t,n_forced/2)"
Answers.UserDisplayName: Polly
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-30T21:38:49.283Z
Answers.Text: @MCCCS could you give a rundown of the differences?
Answers.UserDisplayName: Zoom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-31T08:39:54.993Z
Answers.Text: @Zoom Content ID Partners can (and should) use 44.1kHZ and the lossless audio codec PCM-FLAC (note: I forgot to add 16 or 24 bits audio to my command). They should use higher bitrates for video. They should use 4:2:2 not 4:2:0. Note that my command is untested.
Answers.UserDisplayName: MCCCS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-06T14:43:34.080Z
Answers.Text: @Gyan Is there any difference between in your answer `-force_key_frames expr:gte(t\,n_forced/2)` and `-g <framerate/2>`?
Answers.UserDisplayName: MCCCS
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-16T08:51:36.707Z
Answers.LastActivityDate: 2022-10-29T09:46:43.550Z
Answers.LastEditDate: 2022-10-29T09:46:43.550Z
Answers.UserDisplayName: Gyan
Body: <p>I just read <a href="https://support.google.com/youtube/answer/1722171?hl=en" rel="noreferrer">Recommended upload encoding settings</a> article from official google support. I think this is the best settings for encoding my youtube videos.</p>
  
  <p>Can you help me find out how to encode that settings in ffmpeg for 720p or 1080p videos?</p>
  
  <p><strong>Here's the settings</strong></p>
  
  <p><a href="https://i.sstatic.net/vBZAT.png" rel="noreferrer"><img src="https://i.sstatic.net/vBZAT.png" alt="enter image description here"></a></p>
  
  <p>Thanks in advance.</p>
  
Tags: <video><ffmpeg><encoding><youtube>
Title: How to encode for YouTube with ffmpeg?
UserDisplayName: Engkus Kusnadi
ThreadText: # How to encode for YouTube with ffmpeg?
  
  (Asked by: username_0 on 2018-07-16)
  
  I just read [Recommended upload encoding settings](https://support.google.com/youtube/answer/1722171?hl=en) article from official google support. I think this is the best settings for encoding my youtube videos.
  
  Can you help me find out how to encode that settings in ffmpeg for 720p or 1080p videos?
  
  **Here's the settings**
  
  [![enter image description here](https://i.sstatic.net/vBZAT.png)](https://i.sstatic.net/vBZAT.png)
  
  Thanks in advance.
  
  **Tags:** video, ffmpeg, encoding, youtube
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-16. Score: 16 | Accepted answer
  
  Use
  
  ```
  ffmpeg -i in.mp4 -vf yadif,format=yuv420p -force_key_frames "expr:gte(t,n_forced/2)" -c:v libx264 -crf 18 -bf 2 -c:a aac -q:a 1 -ac 2 -ar 48000 -use_editlist 0 -movflags +faststart out.mp4
  
  ```
  
  `-vf` specifies video filters
  
  `yadif` will deinterlace videos if they're interlaced.
  
  `format=yuv420p` will produce pixel format with 4:2:0 chroma subsampling.
  
  `-force_key_frames "expr:gte(t,n_forced/2)"` will place keyframes every half-second, so that will be the GOP size.
  
  `-c:v libx264` will use the x264 encoder to produce a H264 video stream.
  
  `-crf 18` will produce a visually lossless file. Better than setting a bitrate manually.
  
  `-bf 2` will limit consecutive B-frames to 2
  
  `-c:a aac` will use the native encoder to produce an AAC audio stream.
  
  `-q:a 1` sets the highest quality for the audio. Better than setting a bitrate manually.
  
  `-ac 2` rematrixes audio to stereo.
  
  `-ar 48000` resamples audio to 48000 Hz.
  
  `-use_editlist 0` avoids writing edit lists.
  
  `-movflags +faststart` places moov atom/box at front of the output file.
  
  > **Comments:**
  > **username_2**: I believe you wrote this answer using this [Recommended Upload Settings](https://support.google.com/youtube/answer/1722171) as reference. Here's the command for [Content ID Partners](https://support.google.com/youtube/answer/6039860): `ffmpeg -i in.mp4 -vf yadif,format=yuv422p -force_key_frames expr:gte(t\,n_forced/2) -c:v libx264 -b:v <60M for 1080, 50M for 720, 15M for SD> -bf 2 -c:a flac -ac 2 -ar 44100 -use_editlist 0 -movflags +faststart out.mp4`.  
  > **username_3**: Any idea how I can run this on fish shell where parentheses `(t\,n_forced/2)` are interpreted as a command?  
  > **username_1**: Enclose `expr:gte(t\,n_forced/2)` in single or double quotes, I guess  
  > **username_4**: -force_key_frames "expr:gte(t,n_forced/2)"  
  > **username_5**: @username_2 could you give a rundown of the differences?  
  > **username_2**: @username_5 Content ID Partners can (and should) use 44.1kHZ and the lossless audio codec PCM-FLAC (note: I forgot to add 16 or 24 bits audio to my command). They should use higher bitrates for video. They should use 4:2:2 not 4:2:0. Note that my command is untested.  
  > **username_2**: @username_1 Is there any difference between in your answer `-force_key_frames expr:gte(t\,n_forced/2)` and `-g <framerate/2>`?  
  
  ---
  
  