Last active
June 28, 2021 21:17
-
-
Save shelldandy/7bdc16b8d7f8ac84ace2181a30885d86 to your computer and use it in GitHub Desktop.
Linux DaVinci Resolve back to original bitrate on h265 using nvidia hwaccel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# | |
# Author: BowlineDandy | |
# | |
# Convert DaVinci Resolve Videos Back to Original GoPro sizes | |
# And have them be web friendly as well | |
# Outperforms Compressor in Mac | |
# Requires Nvidia GPU | |
# Requires CUDA Enabled ffmpeg (Custom compiled from Source) | |
# | |
# See: https://developer.nvidia.com/blog/nvidia-ffmpeg-transcoding-guide/ | |
# | |
# cuda_gopro_export example.mov | |
VERSION=1.0 | |
# Check if input file exists | |
if [[ ! -f "$1" ]]; then | |
echo "Input file not found!" | |
exit 1 | |
fi | |
DEBUG=1 | |
FILENAME=$1 | |
RESIZE=$2 | |
CUSTOM_BITRATE=$3 | |
VERBOSE=info | |
HWACCEL=cuda | |
VIDEO_CODEC=hevc_nvenc | |
if [[ $CUSTOM_BITRATE ]]; then | |
VIDEO_BITRATE=$CUSTOM_BITRATE | |
else | |
VIDEO_BITRATE=60M # Same bitrate GoPro 7 4k footages comes at | |
fi | |
AUDIO_CODEC=aac | |
AUDIO_BITRATE=128k | |
FFMPEG_PARAM=('-vsync' "0") | |
FFMPEG_PARAM+=('-hwaccel' "$HWACCEL") | |
FFMPEG_PARAM+=('-hwaccel_output_format' "$HWACCEL") | |
FFMPEG_PARAM+=('-y') | |
FFMPEG_PARAM+=('-i' "$FILENAME") | |
FFMPEG_PARAM+=('-v' "$VERBOSE") | |
FFMPEG_PARAM+=('-c:v' "$VIDEO_CODEC") | |
if [[ $RESIZE ]]; then | |
if [[ $RESIZE == "1080" ]]; then | |
FFMPEG_PARAM+=('-vf' "scale=1920:1080") | |
else | |
FFMPEG_PARAM+=('-vf' "scale=$RESIZE") | |
fi | |
fi | |
FFMPEG_PARAM+=('-b:v' "$VIDEO_BITRATE") | |
FFMPEG_PARAM+=('-movflags' "+faststart") # Web Optimized | |
NAME=$(basename $FILENAME | sed 's/\(.*\)\..*/\1/') | |
PASS_1_PARAMS=('-pass' '1') | |
PASS_1_PARAMS+=('-an') | |
PASS_1_PARAMS+=('-f' 'null') | |
PASS_1_PARAMS+=('/dev/null') | |
PASS_2_PARAMS=('-pass' '2') | |
PASS_2_PARAMS+=('-c:a' "$AUDIO_CODEC") | |
PASS_2_PARAMS+=('-b:a' "$AUDIO_BITRATE") | |
if [[ $RESIZE ]]; then | |
PASS_2_PARAMS+=("$NAME-$RESIZE.mp4") | |
else | |
PASS_2_PARAMS+=("$NAME-cuda.mp4") | |
fi | |
FN_1_ARGS="${FFMPEG_PARAM[@]} ${PASS_1_PARAMS[@]}" | |
FN_2_ARGS="${FFMPEG_PARAM[@]} ${PASS_2_PARAMS[@]}" | |
if [[ $DEBUG -ne 0 ]]; then | |
echo "[[ NAME ]] - ${NAME}" | |
echo | |
echo "[[ FN_1_ARGS ]] ${FN_1_ARGS}" | |
echo | |
echo "[[ FN_2_ARGS ]] ${FN_2_ARGS}" | |
fi | |
ffmpeg $FN_1_ARGS && ffmpeg $FN_2_ARGS | |
# Check if input file exists | |
if [[ -f "ffmpeg2pass-0.log" ]]; then | |
echo "Cleaning up" | |
rm ffmpeg2pass-0.log | |
fi |
Better compression/quality than Apple's Compressor with much faster encode times (Using nvidia geforce gtx 1060 ssc)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on Ubuntu/Pop_OS! 20.04 lts