Skip to content

Instantly share code, notes, and snippets.

@OrcaXS
Last active September 23, 2017 07:11
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 OrcaXS/9c05477b916771041578d4b18af6c9fd to your computer and use it in GitHub Desktop.
Save OrcaXS/9c05477b916771041578d4b18af6c9fd to your computer and use it in GitHub Desktop.
Convert video to gif using ffmpeg, written in fish
# Inspired from http://superuser.com/a/556031
function videotrim --description 'Trim video (filename) (fromtime) (totime) (scalepx) (outputname)' --argument filename fromtime totime scalepx outputname
if not test -f "$filename"
echo "File not exists."
return 1
else if not test -r "$filename"
echo "File is not readable."
return 1
end
if not test -n "$fromtime"
echo "Starting time not provided."
return 1
end
if not test -n "$totime"
echo "Ending time not provided."
return 1
end
set duration (math -s3 $totime - $fromtime)
echo "duration" is $duration
if not test -n "$scalepx"
set scalepx 960
end
if not test -n "$outputname"
set outputname $filename"_trimmed"
end
echo "$filename" with "$scalepx" output "$outputname"
echo ffmpeg -ss "$fromtime" -i "$filename" -t "$duration" -filter:v "scale=$scalepx:-2" -map_metadata -1 -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 23 -an "$outputname".mp4
command ffmpeg -ss $fromtime -i $filename -t $duration -filter:v "scale=$scalepx:-2" -map_metadata -1 -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 23 -an $outputname.mp4
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment