Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(preprocessor): quanlity improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Larryjianfeng committed Aug 5, 2019
1 parent 47efaba commit 7300e05
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions gnes/preprocessor/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@


def get_video_length(video_path):
import subprocess
import re
process = subprocess.Popen(['ffmpeg', '-i', video_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = process.communicate()
process = sp.Popen(['ffmpeg', '-i', video_path],
stdout=sp.PIPE,
stderr=sp.STDOUT)
stdout, _ = process.communicate()
stdout = str(stdout)
matches = re.search(r"Duration:\s{1}(?P<hours>\d+?):(?P<minutes>\d+?):(?P<seconds>\d+\.\d+?),", stdout, re.DOTALL).groupdict()
h = float(matches['hours'])
Expand All @@ -55,8 +56,8 @@ def split_mp4_random(video_path, avg_length, max_clip_second=10):

ts_group = [[] for _ in range(num_part)]

for i in range(len(s)):
ts_group[i % num_part].append(' -ss {} -t {} -i {} '.format(start[i], s[i], video_path))
for i, (_start, _du) in enumerate(zip(start, s)):
ts_group[i % num_part].append(' -ss {} -t {} -i {} '.format(_start, _du, video_path))

prefix = os.path.basename(video_path).replace('.mp4', '')
for i in range(num_part):
Expand All @@ -74,7 +75,7 @@ def get_video_frames(buffer_data: bytes, image_format: str = 'cv2',
# (-vsync, vfr)
# (-vf, select=eq(pict_type\,I))
for k, v in kwargs.items():
if type(v) in [int, float]:
if isinstance(v, (float, int)):
v = str(v)
ffmpeg_cmd.append('-' + k)
ffmpeg_cmd.append(v)
Expand Down

0 comments on commit 7300e05

Please sign in to comment.