Last active
September 23, 2017 07:11
-
-
Save OrcaXS/9c05477b916771041578d4b18af6c9fd to your computer and use it in GitHub Desktop.
Convert video to gif using ffmpeg, written in fish
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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