caydey / ffshare

An android app to compress image, video and audio files through ffmpeg before sharing them
GNU General Public License v3.0
615 stars 30 forks source link

Feature request: Remove letterboxing #109

Open rpdelaney opened 1 month ago

rpdelaney commented 1 month ago

ffmpeg can remove letterboxing, as demonstrated in this bash script:

#!/usr/bin/env bash
#
# Remove letterboxing from media files using ffmpeg's cropdetect function
#

set -o nounset -o pipefail

if ! command -v ffmpeg >/dev/null 2>&1 ; then echo "Missing dependency: ffmpeg" 1>&2 ; exit 1 ; fi
if ! command -v grep >/dev/null 2>&1 ; then echo "Missing dependency: grep" 1>&2 ; exit 1 ; fi
if ! command -v bak >/dev/null 2>&1 ; then echo "Missing dependency: bak" 1>&2 ; exit 1 ; fi

CROP_PATTERN="crop=\d+:\d+:\d+:\d+"

input_file="$1"
output_file="${input_file%.*}_unboxed.${input_file##*.}"

# detect crop area
crop_area="$( \
  ffmpeg -i "$input_file" -vf cropdetect -f null - 2>&1 | \
  grep -Po "$CROP_PATTERN" | \
  tail -n1 \
)" || return

if bak "$input_file" ; then  # make a backup of the original
  # crop the video
  ( set -x ; \
    ffmpeg \
    -y \
    -i "$input_file" \
    -acodec copy \
    -vf "$crop_area" \
    "$output_file" \
  ) && \
  mv -f "$output_file" "$input_file"
else
  exit
fi

# EOF

Since this approach requires calling ffmpeg twice, I wasn't able to replicate it inside ffshare with the additional options parameter.

Could this be incorporated into ffmpeg in some way?