Skip to content

Instantly share code, notes, and snippets.

@shinchiro
Last active August 19, 2022 21:02
Show Gist options
  • Save shinchiro/b9b4fb7ce63ef93eb67f10330b51d570 to your computer and use it in GitHub Desktop.
Save shinchiro/b9b4fb7ce63ef93eb67f10330b51d570 to your computer and use it in GitHub Desktop.
#Encode HDR video from Samsung:
* Encode and crop 100px from top
ffmpeg.exe -hide_banner -i input -vf scale=-2:480:flags=spline,crop=out_h=in_h-80:y=in_h-80 -an -c:v libx264 -pix_fmt yuv420p -preset veryslow -tune film out.mpv
ffmpeg.exe -hide_banner -i input -vf scale=-2:1080:flags=spline -c:v libx264 -pix_fmt yuv420p -preset veryslow -tune film -crf 18 -c:a aac -b:a 192k out.mp4
*Test encode first frame pic
ffmpeg.exe -hide_banner -i input.mp4 -vf scale=-1:360:flags=spline,zscale=transfer=linear:npl=100,format=gbrpf32le,zscale=primaries=bt709,tonemap=hable:desat=0,zscale=transfer=bt709:matrix=bt709:range=limited,format=yuv420p -vframes 1 output.png
ffmpeg.exe -hide_banner -i input.mp4 -vf scale=-1:720:flags=spline,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -map 0 -c copy -c:v libx264 -pix_fmt yuv420p -preset medium -tune film -crf 20 -c:a copy output.mp4
*tonemap=linear will render color similar as mpv render HDR
*without sound
ffmpeg.exe -hide_banner -i input.mp4 -vf scale=-1:720:flags=spline,zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -map 0 -c copy -c:v libx264 -pix_fmt yuv420p -preset medium -tune film -crf 20 -an output.mp4
*with cropping without keeping aspect ratio
ffmpeg.exe -hide_banner -i input.mp4 -vf scale=-1:720:flags=spline,crop=(iw/2)+100:ih:iw-(iw-200):0,zscale=transfer=linear:npl=100,format=gbrpf32le,zscale=primaries=bt709,tonemap=hable:desat=0,zscale=transfer=bt709:matrix=bt709:range=limited,format=yuv420p -preset medium -tune film -crf 12 -c:a copy output.mp4
Reference: https://github.com/jellyfin/jellyfin/issues/415
https://www.linuxuprising.com/2020/01/ffmpeg-how-to-crop-videos-with-examples.html
# Downscale to 1080p and rotate image by 90 degrees clockwise
ffmpeg -i image.jpg -qscale:v 2 -vf scale=-1:1080:flags=spline,transpose=1 out.jpeg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment