Skip to content

Instantly share code, notes, and snippets.

@luizomf
Last active November 10, 2024 17:08
Show Gist options
  • Save luizomf/7f74ee08a73898f0c3bff2c700d24530 to your computer and use it in GitHub Desktop.
Save luizomf/7f74ee08a73898f0c3bff2c700d24530 to your computer and use it in GitHub Desktop.
Upscale 1080p to 4k using ffmpeg

Upscale 1080p to 4k using ffmpeg

Just use the command below:

ffmpeg -i INPUT_FILE \
  -vf scale=3840x2160:flags=lanczos \
  -c:v libx264 \
  -crf 13 \
  -c:a aac -b:a 512k \
  -preset slow \
  OUTPUT_FILE

Where:

  • INPUT_FILE is the path to your input file
  • -vf scale=3840x2160:flags=lanczosis the new resolution using lanczos
  • -c:v libx264 is the codec H264
  • -crf 13 is the desired quality - From 0 to 51, the higher the number the worse. The smaller the number, the larger the file size
  • -c:a aac -b:a 512k is the audio codec and bitrate
  • -preset slow is the preset used. To go faster, use ultrafast
  • OUTPUT_FILE is the output file

Hope it helps.

@jbrower95
Copy link

If you want something that you can copy and paste into your terminal:

function upscale_to_4k { \
ffmpeg -i $1 \
  -vf scale=3840x2160:flags=lanczos \
  -c:v libx264 \
  -crf 13 \
  -c:a aac -b:a 512k \
  -preset slow \
  $2
}

Then you can use upscale_to_4k input.mov output.mov

@olodar
Copy link

olodar commented Apr 30, 2024

Is lanczos algorithm better than default for upscaling?

@jwaresoft
Copy link

jwaresoft commented Oct 31, 2024

This gist is great thanks for posting it and thanks to @jbrower95 for the awesome function. I made one minor tweak which was to add "" around the positional parameters to handle files with spaces in the names. Works flawless. Thanks again @luizomf!

function upscale_to_4k { \
ffmpeg -i "$1" \
  -vf scale=3840x2160:flags=lanczos \
  -c:v libx264 \
  -crf 13 \
  -c:a aac -b:a 512k \
  -preset slow \
  "$2"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment