|
12 | 12 | import logging
|
13 | 13 | import os
|
14 | 14 | from pathlib import Path
|
15 |
| -import subprocess as sp |
| 15 | +import subprocess |
16 | 16 | import sys
|
17 | 17 | from tempfile import NamedTemporaryFile
|
18 | 18 | import time
|
19 | 19 | import typing as tp
|
20 | 20 | import warnings
|
| 21 | +from unittest import mock |
21 | 22 |
|
22 | 23 | from einops import rearrange
|
23 | 24 | import torch
|
|
37 | 38 | BATCHED_DURATION = 15
|
38 | 39 | INTERRUPTING = False
|
39 | 40 | MBD = None
|
40 |
| -# We have to wrap subprocess call to clean a bit the log when using gr.make_waveform |
41 |
| -_old_call = sp.call |
42 | 41 |
|
43 |
| - |
44 |
| -def _call_nostderr(*args, **kwargs): |
45 |
| - # Avoid ffmpeg vomiting on the logs. |
46 |
| - kwargs['stderr'] = sp.DEVNULL |
47 |
| - kwargs['stdout'] = sp.DEVNULL |
48 |
| - _old_call(*args, **kwargs) |
49 |
| - |
50 |
| - |
51 |
| -sp.call = _call_nostderr |
52 | 42 | # Preallocating the pool of processes.
|
53 | 43 | pool = ProcessPoolExecutor(4)
|
54 | 44 | pool.__enter__()
|
@@ -82,12 +72,20 @@ def _cleanup(self):
|
82 | 72 | file_cleaner = FileCleaner()
|
83 | 73 |
|
84 | 74 |
|
| 75 | +def _call_nostderr(*args, **kwargs): |
| 76 | + # Avoid ffmpeg vomiting on the logs. |
| 77 | + kwargs['stderr'] = subprocess.DEVNULL |
| 78 | + kwargs['stdout'] = subprocess.DEVNULL |
| 79 | + return subprocess.call(*args, **kwargs) |
| 80 | + |
| 81 | + |
85 | 82 | def make_waveform(*args, **kwargs):
|
86 | 83 | # Further remove some warnings.
|
87 | 84 | be = time.time()
|
88 | 85 | with warnings.catch_warnings():
|
89 | 86 | warnings.simplefilter('ignore')
|
90 |
| - out = gr.make_waveform(*args, **kwargs) |
| 87 | + with mock.patch('subprocess.call', _call_nostderr): |
| 88 | + out = gr.make_waveform(*args, **kwargs) |
91 | 89 | print("Make a video took", time.time() - be)
|
92 | 90 | return out
|
93 | 91 |
|
|
0 commit comments