-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.py
79 lines (62 loc) · 2.38 KB
/
main.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
import os
import re
import argparse
import youtube_dl
import sys
import warnings
from os.path import join
from signal import signal, SIGINT, SIG_DFL
from detect_fake_videos import test_full_image_network
def warn(*args, **kwargs):
pass
warnings.warn = warn
def banner():
print("[FVD : Fake Video Detector]")
print("""
############################
/$$$$$$$$ /$$ /$$ /$$$$$$$
| $$_____/| $$ | $$| $$__ $$
| $$ | $$ | $$| $$ \ $$
| $$$$$ | $$ / $$/| $$ | $$
| $$__/ \ $$ $$/ | $$ | $$
| $$ \ $$$/ | $$ | $$
| $$ \ $/ | $$$$$$$/
|__/ \_/ |_______/
############################
""")
def main():
signal(SIGINT, SIG_DFL)
p = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
p.add_argument('--model_path', '-mi',dest='model', type=str, default='./models/full/xception/full_c23.p')
p.add_argument('--output_path', '-o',dest='videoOut', type=str, default='.')
p.add_argument('--start_frame', type=int, default=0)
p.add_argument('--end_frame', type=int, default=None)
p.add_argument('--cuda', action='store_true')
p.add_argument('--fast', action='store_true')
requiredNamed = p.add_argument_group('required arguments')
requiredNamed.add_argument('--video_path', '-i', dest='videoIn', type=str, required=True)
args = p.parse_args()
video_path = args.videoIn
prediction = None
if video_path.endswith('.mp4') or video_path.endswith('.avi'):
prediction = test_full_image_network(args.videoIn,args.model,args.videoOut,args.fast)
else:
video_url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', args.videoIn)
if video_url:
default_path = 'video.mp4'
filename = ""
ydl_opts = {'outtmpl':default_path}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(video_url[0], download=True)
filename = ydl.prepare_filename(info)
prediction = test_full_image_network(filename,args.model,args.videoOut, args.fast)
os.remove(filename)
else:
print("Not valid input format")
sys.exit(-1)
print("The Fake Score is: " + str(prediction["score"]))
print("Output video in: " + prediction["file"])
if __name__ == '__main__':
banner()
main()