User Tools

Site Tools


video:encoding

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
video:encoding [2022/10/01 11:02]
Jan Forman [Encode with HDR10 Metadata]
video:encoding [2022/10/03 12:10] (current)
Jan Forman
Line 1: Line 1:
 +====== 7.1 channel sound to 5.1 ======
 +You must add for proper channel mapping
 +<code>-ac 6</code>
 +
 +====== FFMPEG and NVENC ======
 +| nVidia | -hwaccel cuvid -c:v h264_cuvid |
 +| Start from frame | -ss 5 |
 +| HQ framerate 30fps | -r ntsc |
 +| Use photoshop levels | -vf curves=psfile=input.acv |
 +| Deblocking, Autolevels | ,pp=ha/va/al |
 +| Convert colors |-vf colormatrix=bt709:bt601 |
 +
 +====== Show codec parameters ======
 +<code>ffmpeg -h encoder=h264_omx</code>
 +
 +====== Quality based encoder NVENC (Ampere) ======
 +<file bat h264crf.bat>
 +ffmpeg -i "%1" -codec:v h264_nvenc -rc:v vbr_hq -qmin:v 12 -qmax:v 18 -maxrate:v 60M -profile:v high -preset slow -bf 3 -rc-lookahead 16 -g 220 -sws_dither none -sws_flags lanczos -s 1920x1080 -codec:a libopus -ab 192k "%1_1080p.mp4"
 +</file>
 +
 +<file bat h265crf.bat>
 +ffmpeg -i input.mp4 -c:v hevc_nvenc -preset:v p7 -profile:v main10 -rc:v constqp -rc-lookahead 1 -spatial-aq 0 -temporal-aq 1 -weighted_pred 0 -init_qpI 20 -init_qpP 20 -init_qpB 23 -b_ref_mode 2 -dpb_size 3 -multipass 0 -g 240 -bf 5 -pix_fmt p010le -color_range tv -color_primaries bt709 -color_trc bt709 -colorspace bt709 -movflags +faststart -codec:a copy output.mp4
 +</file>
 +
 +<file bat h265hdrcrf.bat> 
 +ffmpeg -i input.mkv  -c:v hevc_nvenc -preset:v p7 -profile:v main10 -rc:v constqp -rc-lookahead 1 -spatial-aq 0 -temporal-aq 1 -weighted_pred 0 -init_qpI 20 -init_qpP 20 -init_qpB 23 -b_ref_mode 2 -dpb_size 3 -multipass 0 -g 240 -bf 5 -pix_fmt p010le -codec:a copy  -color_primaries bt2020 -colorspace bt2020nc -color_trc smpte2084 -bsf:v hevc_metadata=transfer_characteristics=16:colour_primaries=9:video_full_range_flag=0:matrix_coefficients=9 output.mkv
 +</file>
 +====== Create GIF ======
 +<file bat creategif.bat>
 +@set /p CLUT=How Many Colors (4..256): 
 +@echo Number of colors: %CLUT%
 +
 +@set /p BS=Bayer_Strength (0..5 lower is stronger): 
 +@echo Bayer Strength: %BS%
 +
 +@ffmpeg.exe -y -stats -hide_banner -i "%1" -an -sn -dn -sws_dither ed -filter_complex "crop=1920:784:0:148,scale=640:-2:sws_flags=spline+accurate_rnd+full_chroma_int+full_chroma_inp:in_range='mpeg/tv':out_range='jpeg/full/pc',hqdn3d=5,smartblur=lr=1.75:ls=-0.50:lt=-5.5:cr=0.5:cs=1.0:ct=0.5,minterpolate=fps=25/2:mi_mode=mci:me_mode=bidir:me=epzs:vsbmc=1,scale=320:-2:sws_flags=spline+accurate_rnd+full_chroma_int+full_chroma_inp,xbr=2,scale=iw/2:-2:sws_flags=spline+accurate_rnd+full_chroma_int+full_chroma_inp,format=pix_fmts=rgb444le,split=2[vid][clut];[clut]palettegen=max_colors=%CLUT%:reserve_transparent=0:stats_mode=diff[out2]" -map [vid] -c:v ffv1 "%~n1_ll.mkv" -map [out2] "%~n1_CLUT%CLUT%_D.png"
 +
 +@ffmpeg.exe -y -stats -hide_banner -i "%~n1_ll.mkv" -i "%~n1_CLUT%CLUT%_D.png" -lavfi "paletteuse=dither=bayer:bayer_scale=%BS%" -loop 0 -vsync 0 "%~n1_CLUT%CLUT%_D_BS%BS%.gif"
 +
 +@rem  Optimizing GIF...
 +@gifsicle.exe -V -O3 "%~n1_CLUT%CLUT%_D_BS%BS%.gif" -o "%~n1_CLUT%CLUT%_D_BS%BS%_o.gif"
 +</file>
 +
 +====== Defish ======
 +<code>
 +ffmpeg -i "$1" \ -filter_complex 'extractplanes=y+u+v[y][u][v]; [u] scale=w=3840:h=2160:flags=print_info+neighbor+bitexact [us]; [v] scale=w=3840:h=2160:flags=print_info+neighbor+bitexact [vs]; [y][us][vs]mergeplanes=0x001020:yuv444p,format=pix_fmts=yuv444p10le,hqdn3d=3:3:5:5,frei0r=lenscorrection:0.5:0.5:0.16:0.6,scale=w=1920:h=1080:flags=print_info+bicubic+full_chroma_inp+full_chroma_int' \ -sws_dither none \ -q 0 -quant_mat hq \ -c:v prores_ks \ -profile:v 4 \ -c:a copy \ -c:s copy \ -c:d copy \ -map 0 \ "$2/$1"
 +</code>
 +
 +====== 23fps to 60fps ======
 +23,976 / 60 = 0.3996 (39.96%)\\
 +Speed up 239.76%
 +
 +====== Rotate 90degree ======
 +<file bat rotate90.bat>
 +ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4
 +</file>
 +
 +Real rotate
 +<code>
 +-vf "transpose=2"
 +</code>
 +====== Create slideshow from pictures ======
 +
 +<file bat slideshow.bat>
 +c:\programs\stream\ffmpeg -f concat -i list.txt -codec:v libx265 -b:v 1000k -x265-params "pass=1" -pix_fmt yuv420p10le -preset fast -filter:v "crop=in_w:in_h-480" -maxrate 20000k -sws_flags spline -s 3840x2160 -aspect 16:9 -f mp4 nul
 +c:\programs\stream\ffmpeg -f concat -i list.txt -codec:v libx265 -b:v 1000k -x265-params "pass=2" -pix_fmt yuv420p10le -preset fast -filter:v "crop=in_w:in_h-480" -maxrate 20000k -sws_flags spline -s 3840x2160 -aspect 16:9 -f mp4 output.mp4
 +</file>
 +
 +Transform bt601 to bt709
 +<code>-vf "colormatrix=bt601:bt709"</code>
 +
 +<file txt list.txt>
 +file '0.jpg'
 +duration 10
 +file '0_02.jpg'
 +duration 10
 +</file>
 +
 +====== 2-pass x264 ======
 +<file bat x264hq.bat>
 +c:\programs\stream\ffmpeg -y -i input.mov -vf curves=psfile=input.acv -preset veryslow -pix_fmt yuvj420p -c:v libx264 -b:v 30000k -pass 1 -an -f mp4 nul
 +c:\programs\stream\ffmpeg -i input.mov -vf curves=psfile=input.acv -preset veryslow -pix_fmt yuvj420p -c:v libx264 -b:v 30000k -pass 2 -c:a aac -b:a 320k output.mp4
 +</file>
 +
 +====== Archiving in HEVC ======
 +<file bat x265archive.bat>
 +c:\programs\stream\ffmpeg -i "uhqresize.avs" -codec:v libx265 -crf 12 -preset slow -c:a libopus -b:a 320k output.mkv</file>
 +
 +====== Rip to MP3 ======
 +<file bat ripmp3.bat>
 +c:\programs\stream\ffmpeg -i video.mp4 -b:a 192K -vn music.mp3
 +</file>
 +
 +====== Recode audio to AC3 ======
 +<file bat convertac3.bat>
 +ffmpeg -i FILE.mkv -map 0:v -map 0:a:0 -map 0:s -c copy -c:a ac3 -b:a 640k -cutoff 18000 FILE-AC3.mkv
 +</file>
 +
 +====== Convert HDR to SDR ======
 +<code>
 +ffmpeg.exe -i input.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,
 +zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,
 +format=yuv420p -c:v libx265 -crf 18 -preset slower output.mkv
 +</code>
 +
 +====== Encode HDR ======
 +<code>
 +ffmpeg -i source.webm -c:v libx265 -pix_fmt yuv420p10le -x265-params "level=5.2:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084" -crf 12 -preset medium -c:a copy output.mkv
 +</code>
 +
 +====== Patch some old videos ======
 +<code>c:\programs\stream\ffmpeg -fflags +genpts -r 30 -i "input.mkv" -codec copy -bsf:v mpeg4_unpack_bframes output.mkv</code>
 +
 +====== Encode Dolby Pro Logic ======
 +<code>c:\programs\stream\ffmpeg -i input.mp4 -c:v copy -c:a:0 aac -ac 2 -b:a 320k -af "aresample=matrix_encoding=dplii" dolby-prologic.mp4</code>
 +
 +====== Double framerate by motion ======
 +ffmpeg -i input.hevc -filter "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1'" output.hevc
 +
 +====== Export video for Premiere almost lossless ======
 +<code>c:\programs\stream\ffmpeg -i input.mp4 -c:v v210 -c:a copy output.avi</code>
 +
 +
 +====== Insert HDR10 Metadata ======
 +<code>
 +mkvmerge -o output.mkv --colour-matrix 0:9 --colour-range 0:1 --colour-transfer-characteristics 0:16 --colour-primaries 0:9 --max-content-light 0:1000 --max-frame-light 0:128 --max-luminance 0:1000 --min-luminance 0:0.005 --chromaticity-coordinates 0:0.68,0.32,0.265,0.690,0.15,0.06 --white-colour-coordinates 0:0.3127,0.3290 input.mkv
 +</code>
 +
 +====== Insert Stereo into 5.1 Layout ======
 +<code>
 +c:\programs\stream\ffmpeg -i input.mkv -filter_complex "[0:a]pan=5.1(side)|FL=FL|FR=FR|FC=FL+FR|LFE<FL+FR|SL=0.7*FL|SR=0.7*FR[a]" -map 0 -map -0:a -map "[a]" -c copy -c:a ac3 -b:a 640k output.mkv
 +</code>
 +
 +====== Normalize audio ======
 +<code>ffmpeg -i video.mkv -af "volumedetect" -vn -sn -dn -f null /dev/null</code>
 +<code>ffmpeg -i input.mkv -af "volume=5dB" output.mkv</code>
 +====== Dynamic Normalization ======
 +<code>ffmpeg -i input.mkv -af "dynaudnorm=m=4" output.mkv</code>
 +
 +====== Save frames from video ======
 +<code>c:\programs\stream\ffmpeg -i input.mp4 -vf fps=10/60 -qscale:v 2 image-%%03d.jpg</code>
 +
 +====== Encode pictures to video ======
 +<code>ffmpeg -framerate 25 -i %%06d.png -pix_fmt yuv420p -vf crop=3840:1998:0:161,curves=psfile=enc.acv,smartblur=lr=2.00:ls=-0.1:lt=-5.0:cr=2:cs=-0.1:ct=-1.0 -codec:v libx265 -x265-params "crf=22:keyint=340:vbv-maxrate=60000:vbv-bufsize=65535" -preset veryslow output.mkv</code>
 +
 +====== Decode pictures from video ======
 +<code>ffmpeg -i input.mkv -qscale:v 2 image-%%06d.jpg</code>
 +
 +====== Encrypt ======
 +<code>
 +ffmpeg -i input.mp4 -vcodec copy -acodec copy -encryption_scheme cenc-aes-ctr -encryption_key 100b6c20940f779a4589152b57d2dacb -encryption_kid eb676abbcb345e96bbcf616630f1a3da encrypted.mp4
 +</code>
 +
 +====== Inverse Telecine ======
 +
 +<code>ffmpeg -i input.mpg -vf fieldmatch,yadif=deint=interlaced,decimate -pix_fmt yuv420p10le -codec:v libx265 -x265-params "crf=20:keyint=340:vbv-maxrate=60000:vbv-bufsize=65535"  -preset superfast output.mkv
 +</code>
 +
 +====== Tune ======
 +You can optionally use -tune to change settings based upon the specifics of your input. Current tunings include:
 +
 +| film | use for high quality movie content; lowers deblocking |
 +| animation | good for cartoons; uses higher deblocking and more reference frames |
 +| grain | preserves the grain structure in old, grainy film material |
 +| stillimage | good for slideshow-like content |
 +
 +====== Encode with HDR10 Metadata ======
 +Color Primaries: bt2020\\
 +Mastering Display: Display P3\\
 +Luminance: **min:0.001cm/m2 max: 1000cd/m2**\\
 +**1000 / 400 average**
 +<code>x265-params "crf=21:keyint=340:vbv-maxrate=60000:vbv-bufsize=65535:colorprim=bt2020:colormatrix=bt2020nc:transfer=smpte2084:hdr=1:info=1:repeat-headers=1:max-cll=1000,400:max-fall=400:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,1)"</code>
 +\\
 +bt2020\\
 +master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(10000000,1)
  
video/encoding.txt · Last modified: 2022/10/03 12:10 by Jan Forman