Skip to content

Instantly share code, notes, and snippets.

@colhountech
Created June 8, 2022 11: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 colhountech/3e5eb8a5fc368fde5a2ad3899ccd139b to your computer and use it in GitHub Desktop.
Save colhountech/3e5eb8a5fc368fde5a2ad3899ccd139b to your computer and use it in GitHub Desktop.
Compress Video and Remove Silence at Start and throughout
#!/bin/bash
: << 'COPYRIGHT_NOTICE'
MIT License
Copyright (c) 2022 ColhounTech Limited
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
COPYRIGHT_NOTICE
# you may want to tweak these settings
LOGLEVEL="info"
#verbose
#info
#error
#fatal
#panic
# input arguments
inargs=(
-y
-vsync 0
-hwaccel cuda
-hwaccel_output_format cuda
-resize 1280x720
)
# output arguments
outargs=(
-af silenceremove=1:0:-50dB
-c:v h264_nvenc
-b:v 1M
)
# some other useful output args
# -filter:a loudnorm
# -c:v copy
# -c:a copy instead of (-af silenceremove=1:0:-50dB) if we are just copying audio
#
# don't change anything below this line, unless you know what you are doing
#
# track times from start to end
STARTTIME=`date +%s`
# get infile and outfile
BASENAME=$(basename "$1" | rev | cut -d. -f2-| rev )
PATHTO=$(dirname "$1" )
infile=$1
outfile="$PATHTO/$BASENAME-compressed.mp4"
# find out if ffmpeg support a filter
# ffmpeg -hide_banner -filters | grep silenceremove
echo ">>>>>>"
echo ">>>>>> INPUT : $infile"
echo ">>>>>> OUTPUT : $outfile"
echo ">>>>>> IN ARGS : ${inargs[@]}"
echo ">>>>>> OUT ARGS : ${outargs[@]}"
echo ">>>>>>"
echo ffmpeg -hide_banner "${inargs[@]}" -i "$infile" "${outargs[@]}" "$outfile"
ffmpeg -hide_banner "${inargs[@]}" -i "$infile" "${outargs[@]}" "$outfile"
ENDTIME=`date +%s` RUNTIME=$((ENDTIME-STARTTIME))
echo "Done! (took $RUNTIME seconds)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment