forked from open-mmlab/mmagic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_interpolation_demo.py
89 lines (75 loc) · 2.78 KB
/
video_interpolation_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright (c) OpenMMLab. All rights reserved.
import argparse
import torch
from mmedit.apis import init_model, video_interpolation_inference
from mmedit.utils import modify_args
VIDEO_EXTENSIONS = ('.mp4', '.mov', '.avi')
def parse_args():
modify_args()
parser = argparse.ArgumentParser(description='Restoration demo')
parser.add_argument('config', help='test config file path')
parser.add_argument('checkpoint', help='checkpoint file')
parser.add_argument('input_dir', help='directory of the input video')
parser.add_argument('output_dir', help='directory of the output video')
parser.add_argument(
'--fps',
type=float,
default=0,
help='frame rate of the output video, which is needed when '
'`fps-multiplier` is 0 and a video is desired as output.')
parser.add_argument(
'--fps-multiplier',
type=float,
default=0,
help='multiply the fps based on the input video, if `fps-multiplier` '
'is 0, `fps` will be utilized.')
parser.add_argument(
'--start-idx',
type=int,
default=0,
help='the index of the first frame to be processed in the sequence')
parser.add_argument(
'--end-idx',
type=int,
default=None,
help='The index corresponds to the last interpolated frame in the'
'sequence. If it is None, interpolate to the last frame of video'
'or sequence. Default: None.')
parser.add_argument(
'--batch-size',
type=int,
default=4,
help='batch size of video interpolation model')
parser.add_argument(
'--filename-tmpl',
default='{:08d}.png',
help='template of the file names')
parser.add_argument(
'--device', type=int, default=None, help='CUDA device id')
args = parser.parse_args()
return args
def main():
"""Demo for video interpolation models.
Note that we accept video as input(output), when 'input_dir'('output_dir')
is set to the path to the video. But using videos introduces video
compression, which lower the visual quality. If you want actual quality,
please save them as separate images (.png).
"""
args = parse_args()
if args.device < 0 or not torch.cuda.is_available():
device = torch.device('cpu')
else:
device = torch.device('cuda', args.device)
model = init_model(args.config, args.checkpoint, device=device)
video_interpolation_inference(
model=model,
input_dir=args.input_dir,
start_idx=args.start_idx,
end_idx=args.end_idx,
batch_size=args.batch_size,
fps_multiplier=args.fps_multiplier,
fps=args.fps,
output_dir=args.output_dir,
filename_tmpl=args.filename_tmpl)
if __name__ == '__main__':
main()