Skip to content

Commit 100df22

Browse files
Merge pull request #1 from ootsuka-repos/pixeebot/drip-2025-03-25-pixee-python/sandbox-process-creation
Sandbox Process Creation
2 parents 66dce18 + 16608d5 commit 100df22

File tree

8 files changed

+30
-22
lines changed

8 files changed

+30
-22
lines changed

comfyui/comfyui_i2v_run extend.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
# last_flame_save.pyから関数をインポート
1515
from last_flame_save import save_last_frame
16+
from security import safe_command
1617

1718
# 定数と設定
1819
CONFIG = {
@@ -248,7 +249,7 @@ def convert_webp_to_mp4(self, webp_path: str) -> Optional[str]:
248249
'-y',
249250
mp4_path
250251
]
251-
frames_result = subprocess.run(frames_cmd, capture_output=True, text=True)
252+
frames_result = safe_command.run(subprocess.run, frames_cmd, capture_output=True, text=True)
252253

253254
if frames_result.returncode != 0:
254255
print(f"MP4生成エラー: {frames_result.stderr}")
@@ -291,7 +292,7 @@ def concatenate_videos(self, original_mp4: str, generated_mp4: str) -> Optional[
291292
output_path
292293
]
293294

294-
concat_result = subprocess.run(concat_cmd, capture_output=True, text=True)
295+
concat_result = safe_command.run(subprocess.run, concat_cmd, capture_output=True, text=True)
295296

296297
# 一時ファイルを削除
297298
if os.path.exists(temp_list_path):
@@ -360,4 +361,4 @@ def main():
360361
input_mp4 = result_path
361362

362363
if __name__ == "__main__":
363-
main()
364+
main()

comfyui/comfyui_i2v_run.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import time
1111
import subprocess
1212
from typing import Dict, Any, Optional
13+
from security import safe_command
1314

1415
# 定数と設定
1516
CONFIG = {
@@ -244,7 +245,7 @@ def convert_webp_to_mp4(self, webp_path: str) -> Optional[str]:
244245
'-y',
245246
mp4_path
246247
]
247-
frames_result = subprocess.run(frames_cmd, capture_output=True, text=True)
248+
frames_result = safe_command.run(subprocess.run, frames_cmd, capture_output=True, text=True)
248249

249250
if frames_result.returncode != 0:
250251
print(f"MP4生成エラー: {frames_result.stderr}")
@@ -307,4 +308,4 @@ def main():
307308

308309

309310
if __name__ == "__main__":
310-
main()
311+
main()

dataset/video/fps_delete.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import subprocess
55
import glob
6+
from security import safe_command
67

78
# 対象ディレクトリ
89
video_dir = "/home/user/ドキュメント/data"
@@ -33,7 +34,7 @@
3334
video
3435
]
3536

36-
result = subprocess.run(cmd_fps, capture_output=True, text=True)
37+
result = safe_command.run(subprocess.run, cmd_fps, capture_output=True, text=True)
3738
fps_str = result.stdout.strip()
3839

3940
# 分数形式のフレームレートを計算(例:24000/1001)
@@ -51,7 +52,7 @@
5152
video
5253
]
5354

54-
result = subprocess.run(cmd_duration, capture_output=True, text=True)
55+
result = safe_command.run(subprocess.run, cmd_duration, capture_output=True, text=True)
5556
duration = float(result.stdout.strip())
5657

5758
# フレーム数を計算
@@ -87,4 +88,4 @@
8788
else:
8889
print("削除をキャンセルしました。")
8990
else:
90-
print("\n削除対象のファイルはありませんでした。")
91+
print("\n削除対象のファイルはありませんでした。")

utility/clearvoice/clearvoice/models/av_mossformer2_tse/faceDetector/s3fd/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from torchvision import transforms
66
from .nets import S3FDNet
77
from .box_utils import nms_
8+
from security import safe_command
89

910

1011
img_mean = np.array([104., 117., 123.])[:, np.newaxis, np.newaxis].astype('float32')
@@ -20,7 +21,7 @@ def __init__(self, device='cuda'):
2021
if os.path.isfile(PATH_WEIGHT) == False:
2122
Link = "1KafnHz7ccT-3IyddBsL5yi2xGtxAKypt"
2223
cmd = "gdown --id %s -O %s"%(Link, PATH_WEIGHT)
23-
subprocess.call(cmd, shell=True, stdout=None)
24+
safe_command.run(subprocess.call, cmd, shell=True, stdout=None)
2425

2526

2627
# print('[S3FD] loading with', self.device)

utility/clearvoice/clearvoice/streamlit_app.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from clearvoice import ClearVoice
33
import os
44
import tempfile
5+
from security import safe_command
56

67
st.set_page_config(page_title="ClearerVoice Studio", layout="wide")
78
temp_dir = 'temp'
@@ -79,7 +80,7 @@ def main():
7980
# Extract audio
8081
import subprocess
8182
cmd = f"ffmpeg -i {input_path} -vn -acodec pcm_s16le -ar 16000 -ac 1 {audio_path}"
82-
subprocess.call(cmd, shell=True)
83+
safe_command.run(subprocess.call, cmd, shell=True)
8384

8485
input_path = audio_path
8586

@@ -139,4 +140,4 @@ def main():
139140
st.error("Please upload a video file first")
140141

141142
if __name__ == "__main__":
142-
main()
143+
main()

utility/clearvoice/clearvoice/utils/video_process.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from models.av_mossformer2_tse.faceDetector.s3fd import S3FD
1919

2020
from .decode import decode_one_audio_AV_MossFormer2_TSE_16K
21+
from security import safe_command
2122

2223

2324

@@ -75,20 +76,20 @@ def main(video_args, args):
7576
else:
7677
command = ("ffmpeg -y -i %s -qscale:v 2 -threads %d -ss %.3f -to %.3f -async 1 -r 25 %s -loglevel panic" % \
7778
(video_args.videoPath, video_args.nDataLoaderThread, video_args.start, video_args.start + video_args.duration, video_args.videoFilePath))
78-
subprocess.call(command, shell=True, stdout=None)
79+
safe_command.run(subprocess.call, command, shell=True, stdout=None)
7980
sys.stderr.write(time.strftime("%Y-%m-%d %H:%M:%S") + " Extract the video and save in %s \r\n" %(video_args.videoFilePath))
8081

8182
# Extract audio
8283
video_args.audioFilePath = os.path.join(video_args.pyaviPath, 'audio.wav')
8384
command = ("ffmpeg -y -i %s -qscale:a 0 -ac 1 -vn -threads %d -ar 16000 %s -loglevel panic" % \
8485
(video_args.videoFilePath, video_args.nDataLoaderThread, video_args.audioFilePath))
85-
subprocess.call(command, shell=True, stdout=None)
86+
safe_command.run(subprocess.call, command, shell=True, stdout=None)
8687
sys.stderr.write(time.strftime("%Y-%m-%d %H:%M:%S") + " Extract the audio and save in %s \r\n" %(video_args.audioFilePath))
8788

8889
# Extract the video frames
8990
command = ("ffmpeg -y -i %s -qscale:v 2 -threads %d -f image2 %s -loglevel panic" % \
9091
(video_args.videoFilePath, video_args.nDataLoaderThread, os.path.join(video_args.pyframesPath, '%06d.jpg')))
91-
subprocess.call(command, shell=True, stdout=None)
92+
safe_command.run(subprocess.call, command, shell=True, stdout=None)
9293
sys.stderr.write(time.strftime("%Y-%m-%d %H:%M:%S") + " Extract the frames and save in %s \r\n" %(video_args.pyframesPath))
9394

9495
# Scene detection for the video frames
@@ -135,7 +136,7 @@ def main(video_args, args):
135136
command += f"ffmpeg -i {file[:-9]}orig_{idx}.mp4 -i {file[:-9]}est_{idx}.wav -c:v copy -map 0:v:0 -map 1:a:0 -shortest {file[:-9]}est_{idx}.mp4 ;"
136137
# command += f"rm {file[:-9]}est_{idx}.wav ;"
137138

138-
output = subprocess.call(command, shell=True, stdout=None)
139+
output = safe_command.run(subprocess.call, command, shell=True, stdout=None)
139140

140141
rmtree(video_args.pyworkPath)
141142
rmtree(video_args.pyframesPath)
@@ -259,11 +260,11 @@ def crop_video(video_args, track, cropFile):
259260
vOut.release()
260261
command = ("ffmpeg -y -i %s -async 1 -ac 1 -vn -acodec pcm_s16le -ar 16000 -threads %d -ss %.3f -to %.3f %s -loglevel panic" % \
261262
(video_args.audioFilePath, video_args.nDataLoaderThread, audioStart, audioEnd, audioTmp))
262-
output = subprocess.call(command, shell=True, stdout=None) # Crop audio file
263+
output = safe_command.run(subprocess.call, command, shell=True, stdout=None) # Crop audio file
263264
_, audio = wavfile.read(audioTmp)
264265
command = ("ffmpeg -y -i %st.avi -i %s -threads %d -c:v copy -c:a copy %s.avi -loglevel panic" % \
265266
(cropFile, audioTmp, video_args.nDataLoaderThread, cropFile)) # Combine audio and video file
266-
output = subprocess.call(command, shell=True, stdout=None)
267+
output = safe_command.run(subprocess.call, command, shell=True, stdout=None)
267268
os.remove(cropFile + 't.avi')
268269
return {'track':track, 'proc_track':dets}
269270

@@ -338,7 +339,7 @@ def visualization(tracks, est_sources, video_args):
338339
command = ("ffmpeg -y -i %s -i %s -threads %d -c:v copy -c:a copy %s -loglevel panic" % \
339340
(os.path.join(video_args.pyaviPath, 'video_only.avi'), (video_args.pycropPath +'/est_%s.wav' %tidx), \
340341
video_args.nDataLoaderThread, os.path.join(video_args.pyaviPath,'video_out_%s.avi'%tidx)))
341-
output = subprocess.call(command, shell=True, stdout=None)
342+
output = safe_command.run(subprocess.call, command, shell=True, stdout=None)
342343

343344

344345

@@ -348,7 +349,7 @@ def visualization(tracks, est_sources, video_args):
348349
os.path.join(video_args.pyaviPath, 'video_est_%s.mp4' % tidx)
349350
)
350351
command += f"rm {os.path.join(video_args.pyaviPath, 'video_out_%s.avi' % tidx)}"
351-
output = subprocess.call(command, shell=True, stdout=None)
352+
output = safe_command.run(subprocess.call, command, shell=True, stdout=None)
352353

353354

354355
command = "ffmpeg -i %s %s ;" % (
@@ -358,4 +359,4 @@ def visualization(tracks, est_sources, video_args):
358359
command += f"rm {os.path.join(video_args.pyaviPath, 'video_only.avi')} ;"
359360
command += f"rm {os.path.join(video_args.pyaviPath, 'video.avi')} ;"
360361
command += f"rm {os.path.join(video_args.pyaviPath, 'audio.wav')} ;"
361-
output = subprocess.call(command, shell=True, stdout=None)
362+
output = safe_command.run(subprocess.call, command, shell=True, stdout=None)

utility/clearvoice/run.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33
import subprocess
4+
from security import safe_command
45

56
input_file_path = "/home/user/デスクトップ/ClearerVoice-Studio/test.wav"
67
output_path = '/home/user/デスクトップ/ClearerVoice-Studio/MossFormer2_SE_48K_kekka.wav'
@@ -26,7 +27,7 @@ def main():
2627
print(f"入力ファイル: {input_file_path}")
2728
print(f"出力ファイル: {output_path}")
2829

29-
result = subprocess.run([sys.executable, exec_path, input_file_path, output_path],
30+
result = safe_command.run(subprocess.run, [sys.executable, exec_path, input_file_path, output_path],
3031
cwd=clearvoice_dir, # clearvoiceディレクトリで実行
3132
env=my_env,
3233
stdout=subprocess.PIPE,
@@ -42,4 +43,4 @@ def main():
4243
print(result.stderr)
4344

4445
if __name__ == "__main__":
45-
main()
46+
main()

utility/practicalrife/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ opencv-python>=4.1.2
66
moviepy>=1.0.3
77
torchvision>=0.7.0
88
gradio
9+
security==1.3.1

0 commit comments

Comments
 (0)