Skip to content

Instantly share code, notes, and snippets.

@svale
Created November 13, 2019 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svale/4f77483d3856750088cd33aad8c8f96d to your computer and use it in GitHub Desktop.
Save svale/4f77483d3856750088cd33aad8c8f96d to your computer and use it in GitHub Desktop.

Video Encoding

References:

Todos


mp4 /h264

2k, 8K bitrate, preserve framerate, profile high

ffmpeg  -i [SOURCE] \
  -vf "scale=w=min(iw\,1920):h=-2" \
  -c:v libx264 \
  -profile high \
  -b:v 20000k \
  -pix_fmt yuv420p \
  out2k_8k.mp4

2k, 8K bitrate, 30 framerate, profile high

ffmpeg  -i [SOURCE] \
  -vf "scale=w=min(iw\,1920):h=-2, fps=fps=30" \
  -c:v libx264 \
  -profile:v high \
  -b:v 8000k \
  -pix_fmt yuv420p \
  out2k_30fps_8Mb.mp4

4k, 8K bitrate, 30 framerate, profile high

ffmpeg  -i [SOURCE] \
  -vf "scale=w=min(iw\,3840):h=-2, fps=fps=30" \
  -c:v libx264 \
  -profile:v high \
  -b:v 8000k \
  -pix_fmt yuv420p \
  out4k_30fps_8Mb.mp4

4k, 8K constrained bitrate, 30 framerate

ffmpeg  -i [SOURCE] \
  -vf "scale=w=min(iw\,3840):h=-2, fps=fps=30" \
  -c:v libx264 \
  -b:v 8000k \
  -maxrate 8000k \
  -bufsize 16000k \
  -pix_fmt yuv420p \
  out4k_30fps_8000mbr.mp4

Webm / vp9

References

Alternativ two-pass targeting an average bitrate

result: 24 hour encoding. 6.8MB file. Not good enough quality

ffmpeg -y -i [SOURCE] -an -c:v libvpx-vp9 -pass 1 \
  -b:v 6000k \
  -minrate 3000k \
  -maxrate 8700k \
  -crf 24 \
  -quality best \
  -f webm /dev/null && \
ffmpeg -i [SOURCE] -an -c:v libvpx-vp9 -pass 2 \
  -b:v 6000k \
  -minrate 3000k \
  -maxrate 8700k \
  -crf 24 \
  -quality best \
  -speed 2 \
  -threads 2
  -f webm out-6k-crf24.webm

Constant quality 2-pass

ffmpeg -y -i [SOURCE] \
  -c:v libvpx-vp9 \
  -b:v 0 \
  -pass 1 \
  -an\
   -f webm /dev/null && \
ffmpeg -i [SOURCE] \
  -c:v libvpx-vp9 \
  -b:v 0 \
  -pass 2 \
  -an
  out_avg-br.webm

Initial 2-pass test (too low quality)

1. pass

ffmpeg -y -i [SOURCE] \
  -c:v libvpx-vp9 \
  -pass 1 \
  -b:v 2M \
  -vf "scale=w=min(iw\,1920):h=-2" \
  -crf 30 \
  -speed 4 \
  -an \
  -quality good \
  -f webm  /dev/null

2. pass

ffmpeg -y -i [SOURCE] \
  -c:v libvpx-vp9 \
  -pass 2 \
  -b:v 2M \
  -vf "scale=w=min(iw\,1920):h=-2" \
  -crf 30 \
  -quality good \
  -speed 2 \
  -an \
  -f webm out.webm

Thumbnail

References

ffmpeg -i [SOURCE] \
  -an \
  -frames:v 1 \
  -vf "scale=w=1920:h=-1" \
  image.jpg

Optional forced scaling with crop

  -vf "scale=200:100:force_original_aspect_ratio=increase,crop=200:100"

Documentation

prop desc
-an skip audio
-c:v libx264 codec video
-c:a copy copies audio (no codec)
-b:vf video bitrate
-vf filtergraph
scale scaling. See https://trac.ffmpeg.org/wiki/Scaling
h=-2 (preserve aspec ratio as multiple of 2
w=min(iw,1920) input width but not over 1920 (no upscaling)
fps=fps=30 frame per second in output
-pix_fmt yuv420p Chroma subsampling: 4:2:0. I have no fucking idea...
-r 24 force the frame rate to 24 fps. (NB: Better to use fps filter)
-y Overwrite output files without asking.
>>>>>>>>> For thumbnails
-ss 100 Position
-frames:v 1 Number of frames / images
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment