#!/bin/bash #$Id: convid,v 1.2 2026/01/31 07:00:12 RogerSeguin Exp $ ######################################################################## # Copyright (c) 2026 Roger Seguin # https://frogzie.duckdns.org # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ######################################################################## # Convert videos format declare vformat=mp4 # Convert to mp4 declare destDir="" # Destination directory declare -a voptions=() # Video format specific options function usage() { prg=$(basename $0) cat << :end: $prg - Convert videos format Usage: $prg {-d|--destdir} [-f|--1080p|--fhd] files... -d destdir destination directory -f output to Full High Definition (FHD 1080p) :end: exit 1 } # Scan command line declare -r coptions=$(getopt -o 'd:fh' --long 'destdir:,fhd,help,1080p' -n 'parse-options' -- "$@") [ $? -eq 0 ] || { echo "Failed parsing options." >&2 exit 2 } eval set -- "$coptions" while true; do case "$1" in -h | --help) usage ;; -d | --destdir) destDir="$2" [ -d $destDir ] || { echo "Error: $destDir does not exist." 1>&2 exit 2 } shift 2 continue ;; -f | --1080p | --fhd) voptions=('-vf' 'scale=1920:-2') shift continue ;; -- ) shift break ;; *) echo 'Internal error!' >&2 exit 4 ;; esac done ([ -z "$destDir" ] || [ $# -eq 0 ]) && usage # Process video files for f in "$@"; do s="${f##*.}" # File suffix f2=$(basename "$f" .$s 2>/dev/null ).$vformat || { echo "Error: \"$f\" skipped" 1>&2 continue } echo "$f2" ffmpeg -i "$f" ${voptions[@]} "$destDir/$f2" sleep 10 done exit 0