Added --extra command to video_to_gif2.py, updated documentation in README.md

This commit is contained in:
Amber McCloughan 2024-12-11 00:37:22 -05:00
parent 13fc4bb70c
commit 23d9ae3cc2
2 changed files with 26 additions and 19 deletions

View File

@ -1,32 +1,26 @@
# video-to-gif # video-to-gif
## Usage ## Usage
``` ```
usage: video_to_gif.py [-h] [-w WIDTH] [-r FRAMERATE] usage: video_to_gif.py [-h] [-w WIDTH] [-r FRAMERATE] [-e] [-t TAG] INPUT [INPUT ...]
[-s {fast_bilinear,bilinear,bicubic,experimental,neighbor,area,bicublin,gauss,sinc,lanczos,spline}] [-i {none,dup,blend,mci}]
[-t TAG]
INPUT [INPUT ...]
Use ffmpeg to make GIFs from videos Use ffmpeg and gifski to make GIFs from videos
positional arguments: positional arguments:
INPUT input file, supports passing a glob like /Users/MyName/Videos/*.mov INPUT input file, supports passing a glob like /Users/MyName/Videos/*.mov
options: options:
-h, --help show this help message and exit -h, --help show this help message and exit
-w WIDTH, --width WIDTH -w, --width WIDTH width of the GIF in pixels, respecting aspect ratio (default: 960)
width of the GIF in pixels, respecting aspect ratio (default: 960) -r, --framerate FRAMERATE
-r FRAMERATE, --framerate FRAMERATE
framerate of GIF (default: 12) framerate of GIF (default: 12)
-s {fast_bilinear,bilinear,bicubic,experimental,neighbor,area,bicublin,gauss,sinc,lanczos,spline}, --scaler {fast_bilinear,bilinear,bicubic,experimental,neighbor,area,bicublin,gauss,sinc,lanczos,spline} -e, --extra increase quality at the expense of file size and encoding time
scaling algorithm to use (default: lanczos) -t, --tag TAG optional tag included in file name
-i {none,dup,blend,mci}, --interpolate {none,dup,blend,mci}
interpolation method to use (default: none)
-t TAG, --tag TAG optional tag included in file name
— Be gay and do crime — Be gay and do crime
``` ```
## Docker ## Docker
Docker only works for the video_to_gif.py script.
```sh ```sh
docker build -t video_to_gif:latest . docker build -t video_to_gif:latest .
docker run --rm -it video_to_gif --help docker run --rm -it video_to_gif --help

View File

@ -12,13 +12,15 @@ def get_args() -> Dict[str, Any]:
prog='video_to_gif.py', prog='video_to_gif.py',
description='Use ffmpeg and gifski to make GIFs from videos', description='Use ffmpeg and gifski to make GIFs from videos',
epilog='— Be gay and do crime') epilog='— Be gay and do crime')
parser.add_argument('input', type=str, metavar='INPUT', nargs='+', parser.add_argument('input', type=str, metavar='INPUT', nargs='+', \
help="input file, supports passing a glob like /Users/MyName/Videos/*.mov") help="input file, supports passing a glob like /Users/MyName/Videos/*.mov")
parser.add_argument('-w', '--width', type=str, default='960', parser.add_argument('-w', '--width', type=str, default='960', \
help='width of the GIF in pixels, respecting aspect ratio (default: 960)') help='width of the GIF in pixels, respecting aspect ratio (default: 960)')
parser.add_argument('-r', '--framerate', type=str, parser.add_argument('-r', '--framerate', type=str, \
default='12', help='framerate of GIF (default: 12)'), default='12', help='framerate of GIF (default: 12)')
parser.add_argument('-t', '--tag', type=str, default=get_tag(), parser.add_argument('-e', '--extra', default=False, action='store_true', \
help='increase quality at the expense of file size and encoding time')
parser.add_argument('-t', '--tag', type=str, default=get_tag(), \
help='optional tag included in file name') help='optional tag included in file name')
return vars(parser.parse_args()) return vars(parser.parse_args())
@ -41,13 +43,24 @@ def generate_gif_files(inputs: List[str], args: Dict[str, Any]) -> Dict[str, Tup
tag = args['tag'] tag = args['tag']
width = args['width'] width = args['width']
framerate = args['framerate'] framerate = args['framerate']
extra = args['extra']
extra_cmd = ''
quality = '90'
if extra:
extra_cmd = '--extra'
quality = '100'
output_map = {} output_map = {}
for input in inputs: for input in inputs:
file_name = f"{Path(input).stem}_{tag}.gif" file_name = f"{Path(input).stem}_{tag}.gif"
full_path = f"{Path(input).parent}/{file_name}" full_path = f"{Path(input).parent}/{file_name}"
if extra:
ex_cmd = '--extra'
command = ['-i', input, '-pix_fmt', 'yuv444p', '-f', 'yuv4mpegpipe', '-', '|', 'gifski', \ command = ['-i', input, '-pix_fmt', 'yuv444p', '-f', 'yuv4mpegpipe', '-', '|', 'gifski', \
'--width', f"{width}", '-r', f"{framerate}", '-o', f"{full_path}", '-'] '--width', f"{width}", '-r', f"{framerate}", extra_cmd, '-Q', quality, \
'-o', f"{full_path}", '-']
command = list(filter(None, command))
success = call_ffmpeg(command) success = call_ffmpeg(command)
# Tuple of (was it successful?, path of output) # Tuple of (was it successful?, path of output)
output_map[input] = (success, full_path) output_map[input] = (success, full_path)