Skip to content

Instantly share code, notes, and snippets.

@unreturned
Last active January 10, 2026 18:43
Show Gist options
  • Select an option

  • Save unreturned/c5a3ec32f7003b4e0e6cf0de2020305c to your computer and use it in GitHub Desktop.

Select an option

Save unreturned/c5a3ec32f7003b4e0e6cf0de2020305c to your computer and use it in GitHub Desktop.
Convert for iphone
function ffconvert() {
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then echo "Usage: $FUNCNAME (FILE|URL) [OUTPUT.mp4]"; return 1; fi
local input="$1"
local output="$2"
local video_file="$input"
local temp_dir
if [[ "$input" == https://* ]]; then
temp_dir=$(mktemp -d)
yt-dlp --cookies-from-browser firefox --no-part -o "$temp_dir/%(title)s.%(ext)s" "$input" || return 1
video_file=$(find "$temp_dir" -type f \( -name "*.mp4" -o -name "*.mkv" -o -name "*.webm" -o -name "*.avi" \) -print | head -1)
[ -z "$video_file" ] && return 1
[ -z "$output" ] && output="${video_file##*/}"
output="${output%.*}.mp4"
else
[ -z "$output" ] && output="${input%.*}_converted.${input##*.}"
fi
output="${output// /-}"
ffmpeg -i "$video_file" -c:v libx264 -crf 23 -preset medium -c:a aac -b:a 128k -movflags +faststart "$output" || { [ -n "$temp_dir" ] && rm -rf "$temp_dir"; return 1; }
[ -n "$temp_dir" ] && rm -rf "$temp_dir"
echo "$output"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment