ffmpeg dist setup
This commit is contained in:
+59
-30
@@ -56,38 +56,67 @@ class FFMPEGProc:
|
||||
def stop(self):
|
||||
self._should_stop = True
|
||||
|
||||
def _read_stderr_loop(self, stderr_lines: list):
|
||||
"""Read stderr in a loop (used on Windows where select.poll is unavailable)."""
|
||||
while True:
|
||||
line = self._proc.stderr.readline()
|
||||
if not line and self._proc.poll() is not None:
|
||||
break
|
||||
if line:
|
||||
stderr_lines.append(line)
|
||||
match = self._progress_re.match(line)
|
||||
if match and self._update_callback:
|
||||
self._update_callback(
|
||||
int(match.group('frame')),
|
||||
int(match.group('fps')),
|
||||
self._match_to_sec(match),
|
||||
self._duration,
|
||||
float(match.group('speed')),
|
||||
)
|
||||
elif self._duration is None:
|
||||
dm = self._duration_re.match(line)
|
||||
if dm:
|
||||
self._duration = self._match_to_sec(dm)
|
||||
|
||||
def run(self):
|
||||
self._proc = Popen(self._cmd, shell=self._shell, stderr=PIPE, stdin=self._stdin, stdout=self._stdout, universal_newlines=True)
|
||||
poll = select.poll()
|
||||
poll.register(self._proc.stderr)
|
||||
while self._proc.poll() is None and not self._should_stop:
|
||||
if not poll.poll(1):
|
||||
sleep(0.1)
|
||||
continue
|
||||
sleep(0.001)
|
||||
line = self._proc.stderr.readline()
|
||||
match = self._progress_re.match(line)
|
||||
if not match:
|
||||
self.stderr += line
|
||||
|
||||
if match and self._update_callback:
|
||||
self._update_callback(
|
||||
int(match.group('frame')),
|
||||
int(match.group('fps')),
|
||||
self._match_to_sec(match),
|
||||
self._duration,
|
||||
float(match.group('speed'))
|
||||
)
|
||||
elif self._duration is None:
|
||||
match = self._duration_re.match(line)
|
||||
if match:
|
||||
self._duration = self._match_to_sec(match)
|
||||
|
||||
try:
|
||||
out, err = self._proc.communicate(timeout=1)
|
||||
self.stderr += err
|
||||
except TimeoutExpired as ex:
|
||||
pass
|
||||
if getattr(select, 'poll', None):
|
||||
poll = select.poll()
|
||||
poll.register(self._proc.stderr)
|
||||
while self._proc.poll() is None and not self._should_stop:
|
||||
if not poll.poll(1):
|
||||
sleep(0.1)
|
||||
continue
|
||||
sleep(0.001)
|
||||
line = self._proc.stderr.readline()
|
||||
match = self._progress_re.match(line)
|
||||
if not match:
|
||||
self.stderr += line
|
||||
if match and self._update_callback:
|
||||
self._update_callback(
|
||||
int(match.group('frame')),
|
||||
int(match.group('fps')),
|
||||
self._match_to_sec(match),
|
||||
self._duration,
|
||||
float(match.group('speed')),
|
||||
)
|
||||
elif self._duration is None:
|
||||
match = self._duration_re.match(line)
|
||||
if match:
|
||||
self._duration = self._match_to_sec(match)
|
||||
try:
|
||||
_, err = self._proc.communicate(timeout=1)
|
||||
self.stderr += err or ''
|
||||
except TimeoutExpired:
|
||||
pass
|
||||
else:
|
||||
stderr_lines = []
|
||||
reader = Thread(target=self._read_stderr_loop, args=(stderr_lines,), daemon=True)
|
||||
reader.start()
|
||||
while self._proc.poll() is None and not self._should_stop:
|
||||
sleep(0.2)
|
||||
reader.join(timeout=2)
|
||||
self.stderr = ''.join(stderr_lines)
|
||||
return self._proc.returncode
|
||||
|
||||
class TqdmAbsolute(tqdm):
|
||||
|
||||
Reference in New Issue
Block a user