Added --extra command to video_to_gif2.py, updated documentation in README.md
This commit is contained in:
parent
13fc4bb70c
commit
23d9ae3cc2
20
README.md
20
README.md
@ -1,32 +1,26 @@
|
||||
# video-to-gif
|
||||
## Usage
|
||||
```
|
||||
usage: video_to_gif.py [-h] [-w WIDTH] [-r FRAMERATE]
|
||||
[-s {fast_bilinear,bilinear,bicubic,experimental,neighbor,area,bicublin,gauss,sinc,lanczos,spline}] [-i {none,dup,blend,mci}]
|
||||
[-t TAG]
|
||||
INPUT [INPUT ...]
|
||||
usage: video_to_gif.py [-h] [-w WIDTH] [-r FRAMERATE] [-e] [-t TAG] INPUT [INPUT ...]
|
||||
|
||||
Use ffmpeg to make GIFs from videos
|
||||
Use ffmpeg and gifski to make GIFs from videos
|
||||
|
||||
positional arguments:
|
||||
INPUT input file, supports passing a glob like /Users/MyName/Videos/*.mov
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-w WIDTH, --width WIDTH
|
||||
width of the GIF in pixels, respecting aspect ratio (default: 960)
|
||||
-r FRAMERATE, --framerate FRAMERATE
|
||||
-w, --width WIDTH width of the GIF in pixels, respecting aspect ratio (default: 960)
|
||||
-r, --framerate FRAMERATE
|
||||
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}
|
||||
scaling algorithm to use (default: lanczos)
|
||||
-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
|
||||
-e, --extra increase quality at the expense of file size and encoding time
|
||||
-t, --tag TAG optional tag included in file name
|
||||
|
||||
— Be gay and do crime
|
||||
```
|
||||
|
||||
## Docker
|
||||
Docker only works for the video_to_gif.py script.
|
||||
```sh
|
||||
docker build -t video_to_gif:latest .
|
||||
docker run --rm -it video_to_gif --help
|
||||
|
@ -12,13 +12,15 @@ def get_args() -> Dict[str, Any]:
|
||||
prog='video_to_gif.py',
|
||||
description='Use ffmpeg and gifski to make GIFs from videos',
|
||||
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")
|
||||
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)')
|
||||
parser.add_argument('-r', '--framerate', type=str,
|
||||
default='12', help='framerate of GIF (default: 12)'),
|
||||
parser.add_argument('-t', '--tag', type=str, default=get_tag(),
|
||||
parser.add_argument('-r', '--framerate', type=str, \
|
||||
default='12', help='framerate of GIF (default: 12)')
|
||||
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')
|
||||
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']
|
||||
width = args['width']
|
||||
framerate = args['framerate']
|
||||
extra = args['extra']
|
||||
|
||||
extra_cmd = ''
|
||||
quality = '90'
|
||||
if extra:
|
||||
extra_cmd = '--extra'
|
||||
quality = '100'
|
||||
|
||||
output_map = {}
|
||||
for input in inputs:
|
||||
file_name = f"{Path(input).stem}_{tag}.gif"
|
||||
full_path = f"{Path(input).parent}/{file_name}"
|
||||
if extra:
|
||||
ex_cmd = '--extra'
|
||||
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)
|
||||
# Tuple of (was it successful?, path of output)
|
||||
output_map[input] = (success, full_path)
|
||||
|
Loading…
Reference in New Issue
Block a user