Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Remove letterboxing #109

Open
rpdelaney opened this issue Sep 30, 2024 · 0 comments
Open

Feature request: Remove letterboxing #109

rpdelaney opened this issue Sep 30, 2024 · 0 comments

Comments

@rpdelaney
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant