<p>I have encoded my videos using ffmpeg and H264, and this is my ffmpeg command (2 pass encoding):</p>

<pre><code>ffmpeg -y -i Edited\ Clips/arsenalVScristalPalas.mp4 -movflags faststart -c:v libx264 -x264opts 'keyint=300:min-keyint=25:8x8dct:sliced-threads=0:subq=6' -deblock 0:0 -flags +loop -preset slow -tune zerolatency -b:v 2048k -maxrate 2048k -bufsize 3000k -vf "scale=-1280:720" -pass 1 -acodec libmp3lame -b:a 128k -coder 1 -me_range 16 -sc_threshold 42 -bf 10 -qmin 0 -qmax 51 -trellis 2 -rc_lookahead 60 -ss 00:01:00 -t 00:01:00 -f mp4 /dev/null


ffmpeg -i Edited\ Clips/arsenalVScristalPalas.mp4 -movflags faststart -c:v libx264 -x264opts 'keyint=300:min-keyint=25:8x8dct:sliced-threads=0:subq=6' -deblock 0:0 -flags +loop -preset slow -tune zerolatency -b:v 2048k -maxrate 2048k -bufsize 3000k -vf "scale=-1280:720" -pass 2 -acodec libmp3lame -b:a 128k -coder 1 -me_range 16 -sc_threshold 42 -bf 10 -qmin 0 -qmax 51 -trellis 2 -rc_lookahead 60 -ss 00:01:00 -t 00:01:00  2pass15.mp4
</code></pre>

<p>I need the video to be in the highest quality (at the 2000kbps bitrate). I have another video with the same bitrate (from another source), but It has a better quality than my video. I need to reach that quality.</p>

<p>I used mediainfo to get the encoding options for that video, and here is the information:</p>

<blockquote>
  <p>General Complete name                            :
  arsenalVScristalPalas_hd.mp4 Format<br>
  : MPEG-4 Format profile                           : Base Media Codec
  ID                                 : isom (isom/iso2/avc1/mp41) File
  size                                : 171 MiB Duration<br>
  : 11mn 1s Overall bit rate                         : 2 164 Kbps
  Encoded date                             : UTC 1904-01-01 00:00:00
  Tagged date                              : UTC 1904-01-01 00:00:00
  Writing application                      : Lavf57.63.100</p>
  
  <p>Video ID                                       : 1 Format<br>
  : AVC Format/Info                              : Advanced Video Codec
  Format profile                           : Main@L3.1 Format settings,
  CABAC                   : Yes Format settings, ReFrames<br>
  : 6 frames Codec ID                                 : avc1 Codec
  ID/Info                            : Advanced Video Coding Duration<br>
  : 11mn 1s Bit rate                                 : 2 048 Kbps Width 
  : 1 280 pixels Height                                   : 720 pixels
  Display aspect ratio                     : 16:9 Frame rate mode<br>
  : Constant Frame rate                               : 50.000 fps Color
  space                              : YUV Chroma subsampling<br>
  : 4:2:0 Bit depth                                : 8 bits Scan type<br>
  : Progressive Bits/(Pixel*Frame)                       : 0.044 Stream
  size                              : 160 MiB (94%) Writing library<br>
  : x264 core 148 r2643 5c65704 Encoding settings<br>
  : cabac=1 / ref=6 / deblock=1:1:1 / analyse=0x1:0x131 / me=umh /
  subme=9 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=1 / me_range=16 /
  chroma_me=1 / trellis=2 / 8x8dct=0 / cqm=0 / deadzone=21,11 /
  fast_pskip=1 / chroma_qp_offset=-2 / threads=22 / lookahead_threads=5
  / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 /
  bluray_compat=0 / constrained_intra=0 / bframes=10 / b_pyramid=2 /
  b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 /
  keyint=300 / keyint_min=25 / scenecut=40 / intra_refresh=0 /
  rc_lookahead=60 / rc=2pass / mbtree=1 / bitrate=2048 / ratetol=1.0 /
  qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5
  / vbv_maxrate=2048 / vbv_bufsize=5000 / nal_hrd=none / filler=0 /
  ip_ratio=1.41 / aq=1:0.60 Language                                 :
  English Encoded date                             : UTC 1904-01-01
  00:00:00 Tagged date                              : UTC 1904-01-01
  00:00:00</p>
  
  <p>Audio ID                                       : 2 Format<br>
  : AAC Format/Info                              : Advanced Audio Codec
  Format profile                           : HE-AAC / LC Codec ID<br>
  : 40 Duration                                 : 11mn 1s
  Duration_LastFrame                       : -23ms Bit rate mode<br>
  : Constant Bit rate                                 : 128 Kbps
  Channel(s)                               : 2 channels Channel
  positions                        : Front: L R Sampling rate<br>
  : 48.0 KHz / 24.0 KHz Frame rate                               :
  23.438 fps (1024 spf) Compression mode                         : Lossy Stream size                              : 10.1 MiB (6%) Language<br>
  : English Default                                  : Yes Alternate
  group                          : 1 Encoded date<br>
  : UTC 1904-01-01 00:00:00 Tagged date                              :
  UTC 1904-01-01 00:00:00</p>
</blockquote>

<p>and this is the information of my video:</p>

<blockquote>
  <p>General Complete name                            : 2pass14.mp4 Format 
  : MPEG-4 Format profile                           : Base Media Codec
  ID                                 : isom (isom/iso2/avc1/mp41) File
  size                                : 15.4 MiB Duration<br>
  : 1mn 0s Overall bit rate                         : 2 150 Kbps Encoded
  date                             : UTC 1904-01-01 00:00:00 Tagged date
  : UTC 1904-01-01 00:00:00 Writing application                      :
  Lavf56.40.101</p>
  
  <p>Video ID                                       : 1 Format<br>
  : AVC Format/Info                              : Advanced Video Codec
  Format profile                           : High@L3.2 Format settings,
  CABAC                   : Yes Format settings, ReFrames<br>
  : 5 frames Codec ID                                 : avc1 Codec
  ID/Info                            : Advanced Video Coding Duration<br>
  : 1mn 0s Bit rate                                 : 2 048 Kbps Width<br>
  : 1 280 pixels Height                                   : 720 pixels
  Display aspect ratio                     : 16:9 Frame rate mode<br>
  : Constant Frame rate                               : 50.000 fps Color
  space                              : YUV Chroma subsampling<br>
  : 4:2:0 Bit depth                                : 8 bits Scan type<br>
  : Progressive Bits/(Pixel*Frame)                       : 0.044 Stream
  size                              : 14.4 MiB (94%) Writing library<br>
  : x264 core 148 r2643 5c65704 Encoding settings<br>
  : cabac=1 / ref=5 / deblock=1:3:3 / analyse=0x3:0x113 / me=umh /
  subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 /
  chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 /
  fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=3 /
  sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0
  / constrained_intra=0 / bframes=10 / b_pyramid=2 / b_adapt=2 /
  b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=300
  / keyint_min=25 / scenecut=42 / intra_refresh=0 / rc_lookahead=0 /
  rc=2pass / mbtree=0 / bitrate=2048 / ratetol=1.0 / qcomp=0.60 /
  qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 /
  vbv_maxrate=2048 / vbv_bufsize=3000 / nal_hrd=none / filler=0 /
  ip_ratio=1.40 / pb_ratio=1.30 / aq=1:1.00 Language<br>
  : English Encoded date                             : UTC 1904-01-01
  00:00:00 Tagged date                              : UTC 1904-01-01
  00:00:00</p>
  
  <p>Audio ID                                       : 2 Format<br>
  : MPEG Audio Format version                           : Version 1
  Format profile                           : Layer 3 Mode<br>
  : Joint stereo Mode extension                           : MS Stereo
  Codec ID                                 : 6B Duration<br>
  : 1mn 0s Duration_LastFrame                       : -1ms Bit rate mode
  : Constant Bit rate                                 : 128 Kbps Maximum
  bit rate                         : 2 048 Kbps Channel(s)<br>
  : 2 channels Sampling rate                            : 48.0 KHz
  Compression mode                         : Lossy Stream size<br>
  : 938 KiB (6%) Language                                 : English
  Default                                  : Yes Alternate group<br>
  : 1 Encoded date                             : UTC 1904-01-01 00:00:00
  Tagged date                              : UTC 1904-01-01 00:00:00</p>
</blockquote>

<p>is there anything that I am doing wrong?? any suggestions on how to improve my output quality??</p>

<p>and here is a demo of videos,</p>

<p>the video that has a better quality:</p>

<p><a href="https://ufile.io/b7a1b" rel="nofollow noreferrer">https://ufile.io/b7a1b</a></p>

<p>my video, that I need to improve quality:</p>

<p><a href="https://ufile.io/363f11" rel="nofollow noreferrer">https://ufile.io/363f11</a></p>

CC BY-SA 3.0
2017-03-13T17:54:14.833Z
Quite a few parameters are different, but for starters, set `-rc-lookahead` to 60. Try to set as many parameters as you can within x264opts and they will get more reliably flagged if there's a typo.
Gyan
CC BY-SA 3.0
2017-03-13T18:48:00.363Z
What are you using for source material?  Has it already been encoded in the past?  The quality of lossy compression is HIGHLY dependent on the quality of the source material.   If it has been lossy compressed previously, the quality you will get will be significantly lower per bit as loss compounds, generally pretty close to exponentially.
AJ Henderson
CC BY-SA 3.0
2017-03-14T06:22:45.710Z
`-tune zerolatency` is going to kill quality. It disables b-frames and cabac.
SlimSCSI
CC BY-SA 3.0
2017-03-16T10:23:35.083Z
@AJHenderson yes, the source has been encoded before and I expected to have some quality loss, but the other video is also using the same video, but  it has a better quality. It has been encoded before with h264 codec, and its lossy.
evan
CC BY-SA 3.0
2017-03-16T10:26:59.113Z
@SlimSCSI realy? So I should remove it?? I have enabled cabac with coder 1, and when I get video information with mediainfo, it says cabac is set to 1.
evan
<ffmpeg><encoding><h.264>
gain the highest quality with H264 at a certain bit rate
evan
# gain the highest quality with H264 at a certain bit rate

(Asked by: username_0 on 2017-03-13)

I have encoded my videos using ffmpeg and H264, and this is my ffmpeg command (2 pass encoding):
ffmpeg -y -i Edited\ Clips/arsenalVScristalPalas.mp4 -movflags faststart -c:v libx264 -x264opts 'keyint=300:min-keyint=25:8x8dct:sliced-threads=0:subq=6' -deblock 0:0 -flags +loop -preset slow -tune zerolatency -b:v 2048k -maxrate 2048k -bufsize 3000k -vf "scale=-1280:720" -pass 1 -acodec libmp3lame -b:a 128k -coder 1 -me_range 16 -sc_threshold 42 -bf 10 -qmin 0 -qmax 51 -trellis 2 -rc_lookahead 60 -ss 00:01:00 -t 00:01:00 -f mp4 /dev/null


ffmpeg -i Edited\ Clips/arsenalVScristalPalas.mp4 -movflags faststart -c:v libx264 -x264opts 'keyint=300:min-keyint=25:8x8dct:sliced-threads=0:subq=6' -deblock 0:0 -flags +loop -preset slow -tune zerolatency -b:v 2048k -maxrate 2048k -bufsize 3000k -vf "scale=-1280:720" -pass 2 -acodec libmp3lame -b:a 128k -coder 1 -me_range 16 -sc_threshold 42 -bf 10 -qmin 0 -qmax 51 -trellis 2 -rc_lookahead 60 -ss 00:01:00 -t 00:01:00  2pass15.mp4

I need the video to be in the highest quality (at the 2000kbps bitrate). I have another video with the same bitrate (from another source), but It has a better quality than my video. I need to reach that quality.
I used mediainfo to get the encoding options for that video, and here is the information:

General Complete name                            :
  arsenalVScristalPalas_hd.mp4 Format
  : MPEG-4 Format profile                           : Base Media Codec
  ID                                 : isom (isom/iso2/avc1/mp41) File
  size                                : 171 MiB Duration
  : 11mn 1s Overall bit rate                         : 2 164 Kbps
  Encoded date                             : UTC 1904-01-01 00:00:00
  Tagged date                              : UTC 1904-01-01 00:00:00
  Writing application                      : Lavf57.63.100
Video ID                                       : 1 Format
  : AVC Format/Info                              : Advanced Video Codec
  Format profile                           : Main@L3.1 Format settings,
  CABAC                   : Yes Format settings, ReFrames
  : 6 frames Codec ID                                 : avc1 Codec
  ID/Info                            : Advanced Video Coding Duration
  : 11mn 1s Bit rate                                 : 2 048 Kbps Width 
  : 1 280 pixels Height                                   : 720 pixels
  Display aspect ratio                     : 16:9 Frame rate mode
  : Constant Frame rate                               : 50.000 fps Color
  space                              : YUV Chroma subsampling
  : 4:2:0 Bit depth                                : 8 bits Scan type
  : Progressive Bits/(Pixel*Frame)                       : 0.044 Stream
  size                              : 160 MiB (94%) Writing library
  : x264 core 148 r2643 5c65704 Encoding settings
  : cabac=1 / ref=6 / deblock=1:1:1 / analyse=0x1:0x131 / me=umh /
  subme=9 / psy=1 / psy_rd=0.40:0.00 / mixed_ref=1 / me_range=16 /
  chroma_me=1 / trellis=2 / 8x8dct=0 / cqm=0 / deadzone=21,11 /
  fast_pskip=1 / chroma_qp_offset=-2 / threads=22 / lookahead_threads=5
  / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 /
  bluray_compat=0 / constrained_intra=0 / bframes=10 / b_pyramid=2 /
  b_adapt=2 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 /
  keyint=300 / keyint_min=25 / scenecut=40 / intra_refresh=0 /
  rc_lookahead=60 / rc=2pass / mbtree=1 / bitrate=2048 / ratetol=1.0 /
  qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / cplxblur=20.0 / qblur=0.5
  / vbv_maxrate=2048 / vbv_bufsize=5000 / nal_hrd=none / filler=0 /
  ip_ratio=1.41 / aq=1:0.60 Language                                 :
  English Encoded date                             : UTC 1904-01-01
  00:00:00 Tagged date                              : UTC 1904-01-01
  00:00:00
Audio ID                                       : 2 Format
  : AAC Format/Info                              : Advanced Audio Codec
  Format profile                           : HE-AAC / LC Codec ID
  : 40 Duration                                 : 11mn 1s
  Duration_LastFrame                       : -23ms Bit rate mode
  : Constant Bit rate                                 : 128 Kbps
  Channel(s)                               : 2 channels Channel
  positions                        : Front: L R Sampling rate
  : 48.0 KHz / 24.0 KHz Frame rate                               :
  23.438 fps (1024 spf) Compression mode                         : Lossy Stream size                              : 10.1 MiB (6%) Language
  : English Default                                  : Yes Alternate
  group                          : 1 Encoded date
  : UTC 1904-01-01 00:00:00 Tagged date                              :
  UTC 1904-01-01 00:00:00

and this is the information of my video:

General Complete name                            : 2pass14.mp4 Format 
  : MPEG-4 Format profile                           : Base Media Codec
  ID                                 : isom (isom/iso2/avc1/mp41) File
  size                                : 15.4 MiB Duration
  : 1mn 0s Overall bit rate                         : 2 150 Kbps Encoded
  date                             : UTC 1904-01-01 00:00:00 Tagged date
  : UTC 1904-01-01 00:00:00 Writing application                      :
  Lavf56.40.101
Video ID                                       : 1 Format
  : AVC Format/Info                              : Advanced Video Codec
  Format profile                           : High@L3.2 Format settings,
  CABAC                   : Yes Format settings, ReFrames
  : 5 frames Codec ID                                 : avc1 Codec
  ID/Info                            : Advanced Video Coding Duration
  : 1mn 0s Bit rate                                 : 2 048 Kbps Width
  : 1 280 pixels Height                                   : 720 pixels
  Display aspect ratio                     : 16:9 Frame rate mode
  : Constant Frame rate                               : 50.000 fps Color
  space                              : YUV Chroma subsampling
  : 4:2:0 Bit depth                                : 8 bits Scan type
  : Progressive Bits/(Pixel*Frame)                       : 0.044 Stream
  size                              : 14.4 MiB (94%) Writing library
  : x264 core 148 r2643 5c65704 Encoding settings
  : cabac=1 / ref=5 / deblock=1:3:3 / analyse=0x3:0x113 / me=umh /
  subme=6 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 /
  chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 /
  fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=3 /
  sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0
  / constrained_intra=0 / bframes=10 / b_pyramid=2 / b_adapt=2 /
  b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=300
  / keyint_min=25 / scenecut=42 / intra_refresh=0 / rc_lookahead=0 /
  rc=2pass / mbtree=0 / bitrate=2048 / ratetol=1.0 / qcomp=0.60 /
  qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 /
  vbv_maxrate=2048 / vbv_bufsize=3000 / nal_hrd=none / filler=0 /
  ip_ratio=1.40 / pb_ratio=1.30 / aq=1:1.00 Language
  : English Encoded date                             : UTC 1904-01-01
  00:00:00 Tagged date                              : UTC 1904-01-01
  00:00:00
Audio ID                                       : 2 Format
  : MPEG Audio Format version                           : Version 1
  Format profile                           : Layer 3 Mode
  : Joint stereo Mode extension                           : MS Stereo
  Codec ID                                 : 6B Duration
  : 1mn 0s Duration_LastFrame                       : -1ms Bit rate mode
  : Constant Bit rate                                 : 128 Kbps Maximum
  bit rate                         : 2 048 Kbps Channel(s)
  : 2 channels Sampling rate                            : 48.0 KHz
  Compression mode                         : Lossy Stream size
  : 938 KiB (6%) Language                                 : English
  Default                                  : Yes Alternate group
  : 1 Encoded date                             : UTC 1904-01-01 00:00:00
  Tagged date                              : UTC 1904-01-01 00:00:00

is there anything that I am doing wrong?? any suggestions on how to improve my output quality??
and here is a demo of videos,
the video that has a better quality:
https://ufile.io/b7a1b
my video, that I need to improve quality:
https://ufile.io/363f11

**Tags:** ffmpeg, encoding, h.264

> **Comments:**
> **username_1**: Quite a few parameters are different, but for starters, set `-rc-lookahead` to 60. Try to set as many parameters as you can within x264opts and they will get more reliably flagged if there's a typo.  
> **username_2**: What are you using for source material?  Has it already been encoded in the past?  The quality of lossy compression is HIGHLY dependent on the quality of the source material.   If it has been lossy compressed previously, the quality you will get will be significantly lower per bit as loss compounds, generally pretty close to exponentially.  
> **username_3**: `-tune zerolatency` is going to kill quality. It disables b-frames and cabac.  
> **username_0**: @AJHenderson yes, the source has been encoded before and I expected to have some quality loss, but the other video is also using the same video, but  it has a better quality. It has been encoded before with h264 codec, and its lossy.  
> **username_0**: @username_3 realy? So I should remove it?? I have enabled cabac with coder 1, and when I get video information with mediainfo, it says cabac is set to 1.  

---

## 0 answers

