Skip to content

Commit d3e3d44

Browse files
committed
logging changes
1 parent 1fbfc08 commit d3e3d44

6 files changed

Lines changed: 44 additions & 25 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ Please cite the paper below if you make use of the software.
88

99
## Dependencies
1010

11+
GPU (CUDA):
1112
```
1213
conda env create -f environment.yml
1314
```
1415

16+
CPU only:
17+
```
18+
conda env create -f environment-cpu.yml
19+
```
20+
21+
The code automatically detects and uses a CUDA GPU if available, and falls back to CPU otherwise.
22+
1523

1624
## Getting Started
1725

SyncNetInstance.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ def evaluate(self, opt, videofile):
5656

5757
os.makedirs(os.path.join(opt.tmp_dir,opt.reference))
5858

59-
command = ["ffmpeg", "-y", "-i", videofile, "-threads", "1", "-f", "image2",
59+
logger.info('Extracting video frames from %s', videofile)
60+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i", videofile, "-threads", "1", "-f", "image2",
6061
os.path.join(opt.tmp_dir, opt.reference, '%06d.jpg')]
6162
subprocess.run(command, check=True)
6263

63-
command = ["ffmpeg", "-y", "-i", videofile, "-async", "1", "-ac", "1", "-vn",
64+
logger.info('Extracting audio from %s', videofile)
65+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i", videofile, "-async", "1", "-ac", "1", "-vn",
6466
"-acodec", "pcm_s16le", "-ar", "16000",
6567
os.path.join(opt.tmp_dir, opt.reference, 'audio.wav')]
6668
subprocess.run(command, check=True)

environment-cpu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ dependencies:
2525
- scenedetect==0.6.7.1
2626
- opencv-contrib-python==4.13.0.92
2727
- python_speech_features==0.6
28+
- tqdm

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ dependencies:
2727
- scenedetect==0.6.7.1
2828
- opencv-contrib-python==4.13.0.92
2929
- python_speech_features==0.6
30+
- tqdm

run_pipeline.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22

3-
import sys, time, os, pdb, argparse, pickle, subprocess, glob, cv2, logging
3+
import sys, time, os, argparse, pickle, subprocess, glob, cv2, logging
44
import numpy as np
55
import torch
66
from shutil import rmtree
@@ -9,6 +9,7 @@
99
logger = logging.getLogger(__name__)
1010

1111
from scenedetect import open_video, SceneManager, ContentDetector
12+
from tqdm import tqdm
1213

1314
from scipy.interpolate import interp1d
1415
from scipy.io import wavfile
@@ -30,6 +31,7 @@
3031
parser.add_argument('--frame_rate', type=int, default=25, help='Frame rate')
3132
parser.add_argument('--num_failed_det', type=int, default=25, help='Number of missed detections allowed before tracking is stopped')
3233
parser.add_argument('--min_face_size', type=int, default=100, help='Minimum face size in pixels')
34+
parser.add_argument('--overwrite', action='store_true', help='Overwrite existing output directories')
3335
opt = parser.parse_args()
3436

3537
setattr(opt,'avi_dir',os.path.join(opt.data_dir,'pyavi'))
@@ -153,7 +155,8 @@ def crop_video(opt,track,cropfile):
153155

154156
# ========== CROP AUDIO FILE ==========
155157

156-
command = ["ffmpeg", "-y", "-i",
158+
logger.info('Cropping audio track for %s', cropfile)
159+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i",
157160
os.path.join(opt.avi_dir, opt.reference, 'audio.wav'),
158161
"-ss", "%.3f" % audiostart, "-to", "%.3f" % audioend,
159162
audiotmp]
@@ -163,7 +166,8 @@ def crop_video(opt,track,cropfile):
163166

164167
# ========== COMBINE AUDIO AND VIDEO FILES ==========
165168

166-
command = ["ffmpeg", "-y", "-i", cropfile+'t.avi', "-i", audiotmp,
169+
logger.info('Merging audio and video for %s', cropfile)
170+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i", cropfile+'t.avi', "-i", audiotmp,
167171
"-c:v", "copy", "-c:a", "copy", cropfile+'.avi']
168172
subprocess.run(command, check=True)
169173

@@ -189,22 +193,19 @@ def inference_video(opt):
189193

190194
dets = []
191195

192-
for fidx, fname in enumerate(flist):
196+
with tqdm(enumerate(flist), total=len(flist), desc='Detecting faces') as pbar:
197+
for fidx, fname in pbar:
193198

194-
start_time = time.time()
199+
image = cv2.imread(fname)
195200

196-
image = cv2.imread(fname)
201+
image_np = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
202+
bboxes = DET.detect_faces(image_np, conf_th=0.9, scales=[opt.facedet_scale])
197203

198-
image_np = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
199-
bboxes = DET.detect_faces(image_np, conf_th=0.9, scales=[opt.facedet_scale])
204+
dets.append([])
205+
for bbox in bboxes:
206+
dets[-1].append({'frame':fidx, 'bbox':(bbox[:-1]).tolist(), 'conf':bbox[-1]})
200207

201-
dets.append([])
202-
for bbox in bboxes:
203-
dets[-1].append({'frame':fidx, 'bbox':(bbox[:-1]).tolist(), 'conf':bbox[-1]})
204-
205-
elapsed_time = time.time() - start_time
206-
207-
logger.info('%s-%05d; %d dets; %.2f Hz', os.path.join(opt.avi_dir,opt.reference,'video.avi'),fidx,len(dets[-1]),(1/elapsed_time))
208+
pbar.set_postfix(dets=len(dets[-1]))
208209

209210
savepath = os.path.join(opt.work_dir,opt.reference,'faces.pckl')
210211

@@ -250,6 +251,9 @@ def scene_detect(opt):
250251
for d in [opt.work_dir, opt.crop_dir, opt.avi_dir, opt.frames_dir, opt.tmp_dir]:
251252
path = os.path.join(d, opt.reference)
252253
if os.path.exists(path):
254+
if not opt.overwrite:
255+
sys.exit(f"Output directory already exists: {path}. Use --overwrite to overwrite.")
256+
logger.warning('Overwriting existing directory: %s', path)
253257
rmtree(path)
254258

255259
# ========== MAKE NEW DIRECTORIES ==========
@@ -259,16 +263,19 @@ def scene_detect(opt):
259263

260264
# ========== CONVERT VIDEO AND EXTRACT FRAMES ==========
261265

262-
command = ["ffmpeg", "-y", "-i", opt.videofile, "-qscale:v", "2", "-async", "1", "-r", "25",
266+
logger.info('Converting video to 25fps: %s', opt.videofile)
267+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i", opt.videofile, "-qscale:v", "2", "-async", "1", "-r", "25",
263268
os.path.join(opt.avi_dir, opt.reference, 'video.avi')]
264269
subprocess.run(command, check=True)
265270

266-
command = ["ffmpeg", "-y", "-i", os.path.join(opt.avi_dir, opt.reference, 'video.avi'),
271+
logger.info('Extracting frames from video')
272+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i", os.path.join(opt.avi_dir, opt.reference, 'video.avi'),
267273
"-qscale:v", "2", "-threads", "1", "-f", "image2",
268274
os.path.join(opt.frames_dir, opt.reference, '%06d.jpg')]
269275
subprocess.run(command, check=True)
270276

271-
command = ["ffmpeg", "-y", "-i", os.path.join(opt.avi_dir, opt.reference, 'video.avi'),
277+
logger.info('Extracting audio from video')
278+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i", os.path.join(opt.avi_dir, opt.reference, 'video.avi'),
272279
"-ac", "1", "-vn", "-acodec", "pcm_s16le", "-ar", "16000",
273280
os.path.join(opt.avi_dir, opt.reference, 'audio.wav')]
274281
subprocess.run(command, check=True)

run_visualise.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import torch
55
import numpy
6-
import time, pdb, argparse, subprocess, pickle, os, glob, logging
6+
import time, argparse, subprocess, pickle, os, glob, logging
77
import cv2
8+
from tqdm import tqdm
89

910
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)s %(levelname)s: %(message)s')
1011
logger = logging.getLogger(__name__)
@@ -66,7 +67,7 @@
6667
fourcc = cv2.VideoWriter_fourcc(*'XVID')
6768
vOut = cv2.VideoWriter(os.path.join(opt.avi_dir,opt.reference,'video_only.avi'), fourcc, opt.frame_rate, (fw,fh))
6869

69-
for fidx, fname in enumerate(flist):
70+
for fidx, fname in tqdm(enumerate(flist), total=len(flist), desc='Rendering'):
7071

7172
image = cv2.imread(fname)
7273

@@ -79,13 +80,12 @@
7980

8081
vOut.write(image)
8182

82-
logger.info('Frame %d', fidx)
83-
8483
vOut.release()
8584

8685
# ========== COMBINE AUDIO AND VIDEO FILES ==========
8786

88-
command = ["ffmpeg", "-y", "-i",
87+
logger.info('Combining audio and video into output file')
88+
command = ["ffmpeg", "-y", "-loglevel", "error", "-i",
8989
os.path.join(opt.avi_dir, opt.reference, 'video_only.avi'),
9090
"-i", os.path.join(opt.avi_dir, opt.reference, 'audio.wav'),
9191
"-c:v", "copy", "-c:a", "copy",

0 commit comments

Comments
 (0)