Skip to content

Instantly share code, notes, and snippets.

@bugre
Forked from mikoim/README.md
Created March 2, 2022 02:11
Show Gist options
  • Select an option

  • Save bugre/06808702c26a1c8672c89bba4474686c to your computer and use it in GitHub Desktop.

Select an option

Save bugre/06808702c26a1c8672c89bba4474686c to your computer and use it in GitHub Desktop.

Revisions

  1. @mikoim mikoim revised this gist Aug 13, 2020. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    # Parameters

    If you like to encode HDR video, this comment might be helpful. https://gist.github.com/mikoim/27e4e0dc64e384adbcb91ff10a2d3678#gistcomment-2859601

    ## Container: MP4

    | Parameter | YouTube recommends setting |
    @@ -19,7 +17,7 @@ If you like to encode HDR video, this comment might be helpful. https://gist.git
    | -g 30 | GOP of **half the frame rate**. | |
    | | CABAC | Normally, x264 uses CABAC as an entropy encoder. |
    | -crf 18 | Variable bitrate. | Currently, YouTube does not have a bitrate limit. Refer official document: https://support.google.com/youtube/answer/1722171?hl=en |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 | |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 | If you like to encode HDR video, this comment might be helpful. https://gist.github.com/mikoim/27e4e0dc64e384adbcb91ff10a2d3678#gistcomment-2859601 |

    ## Audio codec: AAC-LC

  2. @mikoim mikoim revised this gist Aug 13, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Parameters

    If you like to encode HDR video, this comment might be helpful. https://gist.github.com/mikoim/27e4e0dc64e384adbcb91ff10a2d3678#gistcomment-2859601

    ## Container: MP4

    | Parameter | YouTube recommends setting |
  3. @mikoim mikoim revised this gist Aug 13, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@

    | Parameter | YouTube recommends setting |
    |---------------------|-------------------------------------------------|
    | -movflags +faststart | moov atom at the front of the file (Fast Start) |
    | -movflags faststart | moov atom at the front of the file (Fast Start) |

    ## Video codec: H.264

  4. @mikoim mikoim revised this gist Aug 13, 2020. 6 changed files with 174 additions and 77 deletions.
    36 changes: 36 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    # Parameters

    ## Container: MP4

    | Parameter | YouTube recommends setting |
    |---------------------|-------------------------------------------------|
    | -movflags +faststart | moov atom at the front of the file (Fast Start) |

    ## Video codec: H.264

    | Parameter | YouTube recommends setting | Note |
    |---------------------|----------------------------|------|
    | -c:v libx264 | H.264 | |
    | -profile:v high | High Profile | |
    | -bf 2 | 2 consecutive B frames | |
    | | Closed GOP | x264 produces closed gop as default |
    | -g 30 | GOP of **half the frame rate**. | |
    | | CABAC | Normally, x264 uses CABAC as an entropy encoder. |
    | -crf 18 | Variable bitrate. | Currently, YouTube does not have a bitrate limit. Refer official document: https://support.google.com/youtube/answer/1722171?hl=en |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 | |

    ## Audio codec: AAC-LC

    | Parameter | YouTube recommends setting | Note |
    |-----------------------------|---------------------------------------------------------|------|
    | -c:a libfdk_aac -profile:a aac_low | AAC-LC | Fraunhofer FDK AAC is a high-quality codec library, but it does not compatible GPL. So your FFmpeg most likely does not contain it. Build FFmpeg manually or use a built-in AAC encoder instead of libfdk_aac. |
    | -b:a 384k | Mono 128 kbps, Stereo 384 kbps, 5.1 512 kbps | |

    # Sample video
    - https://youtu.be/UCTPyB0l37Y

    # References
    - Recommended upload encoding settings - YouTube Help https://support.google.com/youtube/answer/1722171
    - Encode/H.264 – FFmpeg https://trac.ffmpeg.org/wiki/Encode/H.264
    - Encode/AAC – FFmpeg https://trac.ffmpeg.org/wiki/Encode/AAC
    - x264 FFmpeg Options Guide - Linux Encoding https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
    68 changes: 68 additions & 0 deletions encode.log
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    ffmpeg version N-98725-gcfc6552032 Copyright (c) 2000-2020 the FFmpeg developers
    built with gcc 10 (GCC)
    configuration: --prefix=xxx --enable-nonfree --enable-gpl --enable-libfdk-aac --enable-libx264 --enable-libx265
    libavutil 56. 58.100 / 56. 58.100
    libavcodec 58.100.100 / 58.100.100
    libavformat 58. 50.100 / 58. 50.100
    libavdevice 58. 11.101 / 58. 11.101
    libavfilter 7. 87.100 / 7. 87.100
    libswscale 5. 8.100 / 5. 8.100
    libswresample 3. 8.100 / 3. 8.100
    libpostproc 55. 8.100 / 55. 8.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'source.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf58.20.100
    Duration: 00:00:23.60, start: 0.000000, bitrate: 13088 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 3840x2160, 12970 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
    handler_name : ?Mainconcept Video Media Handler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
    Metadata:
    handler_name : #Mainconcept MP4 Sound Media Handler
    Stream mapping:
    Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
    Stream #0:1 -> #0:1 (aac (native) -> aac (libfdk_aac))
    Press [q] to stop, [?] for help
    [libx264 @ 0x2337f40] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
    [libx264 @ 0x2337f40] profile High, level 5.1, 4:2:0, 8-bit
    [libx264 @ 0x2337f40] 264 - core 159 r2999 296494a - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 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=27 lookahead_threads=4 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=2 b_pyramid=2 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=12 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=12 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'output.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf58.50.100
    Stream #0:0(eng): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 3840x2160, q=-1--1, 23.98 fps, 24k tbn, 23.98 tbc (default)
    Metadata:
    handler_name : ?Mainconcept Video Media Handler
    encoder : Lavc58.100.100 libx264
    Side data:
    cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
    Stream #0:1(eng): Audio: aac (libfdk_aac) (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 384 kb/s (default)
    Metadata:
    handler_name : #Mainconcept MP4 Sound Media Handler
    encoder : Lavc58.100.100 libfdk_aac
    [mp4 @ 0x2346280] Starting second pass: moving the moov atom to the beginning of the file0.881x
    frame= 565 fps= 20 q=-1.0 Lsize= 50496kB time=00:00:23.57 bitrate=17548.0kbits/s speed=0.828x
    video:49380kB audio:1107kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.017619%
    [libx264 @ 0x2337f40] frame I:54 Avg QP:12.52 size:145222
    [libx264 @ 0x2337f40] frame P:508 Avg QP:15.73 size: 83671
    [libx264 @ 0x2337f40] frame B:3 Avg QP:15.72 size: 72715
    [libx264 @ 0x2337f40] consecutive B-frames: 98.9% 1.1% 0.0%
    [libx264 @ 0x2337f40] mb I I16..4: 32.3% 61.1% 6.6%
    [libx264 @ 0x2337f40] mb P I16..4: 18.7% 32.0% 0.7% P16..4: 21.4% 3.8% 1.2% 0.0% 0.0% skip:22.1%
    [libx264 @ 0x2337f40] mb B I16..4: 4.4% 10.4% 0.4% B16..8: 48.1% 7.4% 0.4% direct: 3.5% skip:25.4% L0:65.6% L1:33.4% BI: 1.0%
    [libx264 @ 0x2337f40] 8x8 transform intra:62.0% inter:85.3%
    [libx264 @ 0x2337f40] direct mvs spatial:33.3% temporal:66.7%
    [libx264 @ 0x2337f40] coded y,uvDC,uvAC intra: 25.4% 34.5% 3.6% inter: 5.2% 15.3% 0.0%
    [libx264 @ 0x2337f40] i16 v,h,dc,p: 11% 21% 8% 60%
    [libx264 @ 0x2337f40] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 18% 23% 4% 5% 5% 6% 5% 5%
    [libx264 @ 0x2337f40] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 16% 18% 5% 8% 7% 6% 4% 4%
    [libx264 @ 0x2337f40] i8c dc,h,v,p: 56% 22% 17% 5%
    [libx264 @ 0x2337f40] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 0x2337f40] ref P L0: 72.7% 1.1% 15.9% 6.0% 2.6% 1.7%
    [libx264 @ 0x2337f40] ref B L0: 89.1% 7.4% 3.5%
    [libx264 @ 0x2337f40] kb/s:17165.92
    16 changes: 14 additions & 2 deletions encode.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,14 @@
    #/bin/sh
    ffmpeg -i input -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low output
    #!/bin/bash

    AAC_ENCODER=libfdk_aac
    # AAC_ENCODER=aac

    AUDIO_PARAMS="-c:a $AAC_ENCODER -profile:a aac_low -b:a 384k"
    VIDEO_PARAMS="-pix_fmt yuv420p -c:v libx264 -profile:v high -preset slow -crf 18 -g 30 -bf 2"
    CONTAINER_PARAMS="-movflags faststart"

    # You need to adjust the GOP length to fit your source video.
    # 60 fps -> -g 30
    # 23.976 (24000/1001) -> -g 24000/1001/2 (???) <- plz comment

    ffmpeg -i "$1" $AUDIO_PARAMS $VIDEO_PARAMS $CONTAINER_PARAMS "$2"
    56 changes: 56 additions & 0 deletions mediainfo-output-mp4.log
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    General
    Complete name : output.mp4
    Format : MPEG-4
    Format profile : Base Media
    Codec ID : isom (isom/iso2/avc1/mp41)
    File size : 49.3 MiB
    Duration : 23 s 616 ms
    Overall bit rate : 17.5 Mb/s
    Writing application : Lavf58.50.100

    Video
    ID : 1
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : [email protected]
    Format settings : CABAC / 5 Ref Frames
    Format settings, CABAC : Yes
    Format settings, Reference frames : 5 frames
    Format settings, GOP : M=1, N=11
    Codec ID : avc1
    Codec ID/Info : Advanced Video Coding
    Duration : 23 s 566 ms
    Bit rate : 17.2 Mb/s
    Width : 3 840 pixels
    Height : 2 160 pixels
    Display aspect ratio : 16:9
    Frame rate mode : Constant
    Frame rate : 23.976 (24000/1001) FPS
    Color space : YUV
    Chroma subsampling : 4:2:0
    Bit depth : 8 bits
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.086
    Stream size : 48.2 MiB (98%)
    Writing library : x264 core 159 r2999 296494a
    Encoding settings : cabac=1 / ref=5 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=8 / 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=27 / lookahead_threads=4 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=2 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=3 / weightb=1 / open_gop=0 / weightp=2 / keyint=12 / keyint_min=1 / scenecut=40 / intra_refresh=0 / rc_lookahead=12 / rc=crf / mbtree=1 / crf=18.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / ip_ratio=1.40 / aq=1:1.00
    Language : English
    Codec configuration box : avcC

    Audio
    ID : 2
    Format : AAC LC
    Format/Info : Advanced Audio Codec Low Complexity
    Codec ID : mp4a-40-2
    Duration : 23 s 616 ms
    Bit rate mode : Constant
    Bit rate : 384 kb/s
    Channel(s) : 2 channels
    Channel layout : L R
    Sampling rate : 48.0 kHz
    Frame rate : 46.875 FPS (1024 SPF)
    Compression mode : Lossy
    Stream size : 1.08 MiB (2%)
    Language : English
    Default : Yes
    Alternate group : 1
    27 changes: 0 additions & 27 deletions parameters.md
    Original file line number Diff line number Diff line change
    @@ -1,27 +0,0 @@
    # Parameters

    I tested on ffmpeg 3.2.x Hypatia.

    ## Container: MP4

    | Parameter | YouTube recommends setting |
    |---------------------|-------------------------------------------------|
    | -movflags faststart | moov atom at the front of the file (Fast Start) |

    ## Video codec: H.264

    | Parameter | YouTube recommends setting |
    |---------------------|----------------------------|
    | -profile:v high | High Profile |
    | -bf 2 | 2 consecutive B frames |
    | -g 30 | Closed GOP. GOP of **half the frame rate**. |
    | -coder 1 | CABAC |
    | -crf 18 | Variable bitrate. |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |

    ## Audio codec: AAC-LC

    | Parameter | YouTube recommends setting |
    |-----------------------------|---------------------------------------------------------|
    | -c:a aac -profile:a aac_low | AAC-LC |
    | -b:a 384k | Recommended audio bitrates for uploads: Stereo 384 kbps |
    48 changes: 0 additions & 48 deletions test.log
    Original file line number Diff line number Diff line change
    @@ -1,48 +0,0 @@
    ffmpeg version 3.2.1-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2016 the FFmpeg developers
    built with gcc 5.4.1 (Debian 5.4.1-3) 20161019
    configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
    libavutil 55. 34.100 / 55. 34.100
    libavcodec 57. 64.101 / 57. 64.101
    libavformat 57. 56.100 / 57. 56.100
    libavdevice 57. 1.100 / 57. 1.100
    libavfilter 6. 65.100 / 6. 65.100
    libswscale 4. 2.100 / 4. 2.100
    libswresample 2. 3.100 / 2. 3.100
    libpostproc 54. 1.100 / 54. 1.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf57.41.100
    Duration: 00:57:34.77, start: 0.000000, bitrate: 146955 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], 146781 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    [libx264 @ 0x403f240] using SAR=1/1
    [libx264 @ 0x403f240] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 0x403f240] profile High, level 3.2
    [libx264 @ 0x403f240] 264 - core 148 r292 72d53ab - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=2 b_pyramid=2 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=30 keyint_min=3 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'out.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf57.56.100
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 60 fps, 15360 tbn, 60 tbc (default)
    Metadata:
    handler_name : VideoHandler
    encoder : Lavc57.64.101 libx264
    Side data:
    cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 384 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    encoder : Lavc57.64.101 aac
    Stream mapping:
    Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
    Stream #0:1 -> #0:1 (aac (native) -> aac (native))
    Press [q] to stop, [?] for help
  5. @mikoim mikoim revised this gist Dec 4, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions parameters.md
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,8 @@ I tested on ffmpeg 3.2.x Hypatia.
    | -crf 18 | Variable bitrate. |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |

    ## Audio codec: AAC-LC

    | Parameter | YouTube recommends setting |
    |-----------------------------|---------------------------------------------------------|
    | -c:a aac -profile:a aac_low | AAC-LC |
  6. @mikoim mikoim revised this gist Dec 4, 2016. 3 changed files with 25 additions and 19 deletions.
    2 changes: 1 addition & 1 deletion encode.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    #/bin/sh
    ffmpeg -i input -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a copy output
    ffmpeg -i input -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low output
    9 changes: 7 additions & 2 deletions parameters.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Parameters

    I tested on ffmpeg 3.2 Hypatia.
    I tested on ffmpeg 3.2.x Hypatia.

    ## Container: MP4

    @@ -17,4 +17,9 @@ I tested on ffmpeg 3.2 Hypatia.
    | -g 30 | Closed GOP. GOP of **half the frame rate**. |
    | -coder 1 | CABAC |
    | -crf 18 | Variable bitrate. |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |

    | Parameter | YouTube recommends setting |
    |-----------------------------|---------------------------------------------------------|
    | -c:a aac -profile:a aac_low | AAC-LC |
    | -b:a 384k | Recommended audio bitrates for uploads: Stereo 384 kbps |
    33 changes: 17 additions & 16 deletions test.log
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,32 @@
    ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
    built with gcc 5.4.0 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
    ffmpeg version 3.2.1-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2016 the FFmpeg developers
    built with gcc 5.4.1 (Debian 5.4.1-3) 20161019
    configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
    libavutil 55. 34.100 / 55. 34.100
    libavcodec 57. 64.100 / 57. 64.100
    libavcodec 57. 64.101 / 57. 64.101
    libavformat 57. 56.100 / 57. 56.100
    libavdevice 57. 1.100 / 57. 1.100
    libavfilter 6. 65.100 / 6. 65.100
    libswscale 4. 2.100 / 4. 2.100
    libswresample 2. 3.100 / 2. 3.100
    libpostproc 54. 1.100 / 54. 1.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\b.mp4':
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf57.41.100
    Duration: 01:49:48.77, start: 0.000000, bitrate: 149125 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], 148951 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Duration: 00:57:34.77, start: 0.000000, bitrate: 146955 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], 146781 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    [libx264 @ 0000000002f0d100] using SAR=1/1
    [libx264 @ 0000000002f0d100] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 0000000002f0d100] profile High, level 3.2
    [libx264 @ 0000000002f0d100] 264 - core 148 r2721 72d53ab - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=2 b_pyramid=2 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=30 keyint_min=3 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'D:\encode_b.mp4':
    [libx264 @ 0x403f240] using SAR=1/1
    [libx264 @ 0x403f240] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 0x403f240] profile High, level 3.2
    [libx264 @ 0x403f240] 264 - core 148 r292 72d53ab - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=2 b_pyramid=2 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=30 keyint_min=3 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'out.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    @@ -35,13 +35,14 @@ Output #0, mp4, to 'D:\encode_b.mp4':
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 60 fps, 15360 tbn, 60 tbc (default)
    Metadata:
    handler_name : VideoHandler
    encoder : Lavc57.64.100 libx264
    encoder : Lavc57.64.101 libx264
    Side data:
    cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 160 kb/s (default)
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 384 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    encoder : Lavc57.64.101 aac
    Stream mapping:
    Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
    Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    Stream #0:1 -> #0:1 (aac (native) -> aac (native))
    Press [q] to stop, [?] for help
  7. @mikoim mikoim revised this gist Nov 27, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parameters.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ I tested on ffmpeg 3.2 Hypatia.
    |---------------------|----------------------------|
    | -profile:v high | High Profile |
    | -bf 2 | 2 consecutive B frames |
    | -g 30 | Closed GOP. GOP of half the frame rate. |
    | -g 30 | Closed GOP. GOP of **half the frame rate**. |
    | -coder 1 | CABAC |
    | -crf 18 | Variable bitrate. |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |
  8. @mikoim mikoim revised this gist Nov 27, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions parameters.md
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,5 @@ I tested on ffmpeg 3.2 Hypatia.
    | -bf 2 | 2 consecutive B frames |
    | -g 30 | Closed GOP. GOP of half the frame rate. |
    | -coder 1 | CABAC |
    | -crf 18 | Variable bitrate. |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |
  9. @mikoim mikoim revised this gist Nov 27, 2016. No changes.
  10. @mikoim mikoim revised this gist Nov 27, 2016. 1 changed file with 47 additions and 0 deletions.
    47 changes: 47 additions & 0 deletions test.log
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers
    built with gcc 5.4.0 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
    libavutil 55. 34.100 / 55. 34.100
    libavcodec 57. 64.100 / 57. 64.100
    libavformat 57. 56.100 / 57. 56.100
    libavdevice 57. 1.100 / 57. 1.100
    libavfilter 6. 65.100 / 6. 65.100
    libswscale 4. 2.100 / 4. 2.100
    libswresample 2. 3.100 / 2. 3.100
    libpostproc 54. 1.100 / 54. 1.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'D:\b.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf57.41.100
    Duration: 01:49:48.77, start: 0.000000, bitrate: 149125 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv420p(tv, bt470bg/unknown/unknown), 1280x720 [SAR 1:1 DAR 16:9], 148951 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
    handler_name : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    [libx264 @ 0000000002f0d100] using SAR=1/1
    [libx264 @ 0000000002f0d100] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
    [libx264 @ 0000000002f0d100] profile High, level 3.2
    [libx264 @ 0000000002f0d100] 264 - core 148 r2721 72d53ab - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=2 b_pyramid=2 b_adapt=1 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=30 keyint_min=3 scenecut=40 intra_refresh=0 rc_lookahead=30 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'D:\encode_b.mp4':
    Metadata:
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf57.56.100
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 60 fps, 15360 tbn, 60 tbc (default)
    Metadata:
    handler_name : VideoHandler
    encoder : Lavc57.64.100 libx264
    Side data:
    cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, 160 kb/s (default)
    Metadata:
    handler_name : SoundHandler
    Stream mapping:
    Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
    Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
  11. @mikoim mikoim revised this gist Nov 27, 2016. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion encode.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,2 @@
    #/bin/sh
    ffmpeg -i input -c:v libx264 -preset slow -coder 1 -pix_fmt yuv420p -movflags faststart -bf 2 -profile:v high -crf 18 -c:a copy output
    ffmpeg -i input -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a copy output
    2 changes: 1 addition & 1 deletion parameters.md
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,6 @@ I tested on ffmpeg 3.2 Hypatia.
    |---------------------|----------------------------|
    | -profile:v high | High Profile |
    | -bf 2 | 2 consecutive B frames |
    | [default] | Closed GOP |
    | -g 30 | Closed GOP. GOP of half the frame rate. |
    | -coder 1 | CABAC |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |
  12. @mikoim mikoim revised this gist Nov 27, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parameters.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ I tested on ffmpeg 3.2 Hypatia.

    | Parameter | YouTube recommends setting |
    |---------------------|----------------------------|
    | -movflags faststart | High Profile |
    | -profile:v high | High Profile |
    | -bf 2 | 2 consecutive B frames |
    | [default] | Closed GOP |
    | -coder 1 | CABAC |
  13. @mikoim mikoim created this gist Nov 27, 2016.
    2 changes: 2 additions & 0 deletions encode.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    #/bin/sh
    ffmpeg -i input -c:v libx264 -preset slow -coder 1 -pix_fmt yuv420p -movflags faststart -bf 2 -profile:v high -crf 18 -c:a copy output
    19 changes: 19 additions & 0 deletions parameters.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # Parameters

    I tested on ffmpeg 3.2 Hypatia.

    ## Container: MP4

    | Parameter | YouTube recommends setting |
    |---------------------|-------------------------------------------------|
    | -movflags faststart | moov atom at the front of the file (Fast Start) |

    ## Video codec: H.264

    | Parameter | YouTube recommends setting |
    |---------------------|----------------------------|
    | -movflags faststart | High Profile |
    | -bf 2 | 2 consecutive B frames |
    | [default] | Closed GOP |
    | -coder 1 | CABAC |
    | -pix_fmt yuv420p | Chroma subsampling: 4:2:0 |