Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kevinwright
Last active February 18, 2024 21:14
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kevinwright/24baf2470d4fbd1d12b5cd1118e7d680 to your computer and use it in GitHub Desktop.
Save kevinwright/24baf2470d4fbd1d12b5cd1118e7d680 to your computer and use it in GitHub Desktop.
Use ffmpeg to build prores proxies for Premiere Pro
#!/usr/bin/env bash
# Usage notes
# ===========
#
# proxy_watermark.png needs to be in the same directory as the script
# download from here: http://whoismatt.com/images/2016/7-july/adobe_proxy_logo.png
#
# on OSX, both pv and ffmpeg will need to be installed via homebrew
scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
inputfile=$1
nakedname="${inputfile%.*}"
ext="${inputfile##*.}"
outputfile="Proxies/${nakedname}-proxy.${ext}"
echo "outputfile = $outputfile"
mkdir -p Proxies
# find input resolution
# =====================
# input aspects:
# cine 4K = 4096:2160 (1.9:1 = 1.896) - proxy at 1024:540
# UHD(4K) = 3840:2160 (16:9 = 1.777) - proxy at 720p
# 1080p = 1920:1080 (16:9 = 1.777) - proxy at 720p
# 720p = 1280:720 (16:9 = 1.777)
#
# proxy aspects:
# 1024x540 = 1.9:1
# 1280x720 = 16:9
# 1536x790 = ??? (1.944)
eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width $inputfile)
inputres=${streams_stream_0_width}:${streams_stream_0_height}
#TODO: make this 1024:540 if source is C4K
outputres="1280:720"
echo "inputres = $inputres"
echo "outputres = $outputres"
# EXPLANATION
# ===========
#
# pv = pipeview, shows progress and estimated time
#
# -v warning turn down verbosity to only warnings
#
# -profile:v N
# where N = 0 -> proxy 1 -> lt 2 -> std 3 -> hq
#
# -i logo.png = a SECOND input file, with an overlay image
# -filter_complex "overlay=W-w-5:H-h-5/2" = make an overlay, position 5px from bottom-right
#
pv $inputfile | ffmpeg \
-loglevel warning \
-i pipe:0 \
-i "$scriptdir/proxy_watermark.png" \
-filter_complex "[0:v]scale=$outputres, overlay=W-w-5:H-h-5/2" \
-codec:a copy \
-codec:v prores \
-profile:v 0 \
"$outputfile"
@carbonturtle
Copy link

Since we're using the Prores codec, the output file extension could be hard-coded as ".mov", right? It took me a few minutes to figure out why this Gist wasn't working on .mp4 files.

Also, what is the "-profile:v 0" for?

@kevinwright
Copy link
Author

kevinwright commented Aug 6, 2020

Says right there in the script...

#   -profile:v N
#     where N = 0 -> proxy  1 -> lt  2 -> std  3 -> hq

They're different prores levels

@carbonturtle
Copy link

Oops, sorry I didn't catch that! And also, thanks for making this script-- an excellent idea IMO. For my use case I'm having to make a few modifications:

  1. enclosing filename args in quotes to allow for spaces in filenames,
  2. the aforementioned hard-coding of the output file extension as MOV to avoid this error when making proxies of MP4 (and other non-MOV?) videos:
    [mp4 @ 0x7fa645812200] Could not find tag for codec prores in stream #0, codec not currently supported in container
    Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
    Error initializing output stream 0:0 --
    Conversion failed!
  3. I'm still trying to figure out why I get errors (see below) when using pv (but not when invoking ffmpeg directly), at least on H.264 files regardless of container format. Maybe I need to grab some additional info from ffprobe to feed to ffmpeg to help it parse the pv stream correctly? I'll keep researching it, but if you have any ideas I'd love to hear them. (This question's probably not as easy as my last one though, hahaha.) Here are the errors I get with pv:
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fe14f806800] stream 1, offset 0x24: partial file
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fe14f806800] Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none(bt709), 1280x720, 7392 kb/s): unspecified pixel format
    Consider increasing the value for the 'analyzeduration' and 'probesize' options
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fe14f806800] stream 1, offset 0x24: partial file
    pipe:0: Invalid data found when processing input
    Cannot determine format of input stream 0:0 after EOF
    Error marking filters as finished

@anjszulc
Copy link

anjszulc commented Dec 5, 2022

Hi @kevinwright
I have problem with run script on MacStudio
I install ffmpeg and pv with homebrew.
I try run script in specify folder sudo /Volumes/6TB\ HDD\ Venom/ResilioSync/prores/proresproxy.sh but it says:
sudo: /Volumes/6TB HDD Venom/ResilioSync/prores/proresproxy.sh: command not found

@kevinwright
Copy link
Author

kevinwright commented Dec 5, 2022

Hi @anjszulc
If you copy/pasted the file then you probably haven't flagged it as being executable.

You can do that with

chmod +x /Volumes/6TB\ HDD\ Venom/ResilioSync/prores/proresproxy.sh

I've also updated the gist to quote filenames in a couple of places where it would have got confused by spaces in the script path

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