Skip to content

Video editing with Python

fix import of os for other systems than win

Florian Zierer699ebf085df6
diff --git a/moviepy/audio/io/ffmpeg_audiowriter.py b/moviepy/audio/io/ffmpeg_audiowriter.py
index b7f65cc2..a05dc182 100644
--- a/moviepy/audio/io/ffmpeg_audiowriter.py
+++ b/moviepy/audio/io/ffmpeg_audiowriter.py
@@ -2,10 +2,10 @@
import numpy as np
import subprocess as sp
+import os
try:
from subprocess import DEVNULL # py3k
except ImportError:
- import os
DEVNULL = open(os.devnull, 'wb')
from tqdm import tqdm
diff --git a/moviepy/audio/io/readers.py b/moviepy/audio/io/readers.py
index 83e65d80..896860ba 100644
--- a/moviepy/audio/io/readers.py
+++ b/moviepy/audio/io/readers.py
@@ -7,12 +7,13 @@ from moviepy.tools import cvsecs
from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos
from moviepy.conf import FFMPEG_BINARY
+import os
try:
from subprocess import DEVNULL # py3k
except ImportError:
- import os
DEVNULL = open(os.devnull, 'wb')
+
class FFMPEG_AudioReader:
"""
A class to read the audio in either video files or audio files
diff --git a/moviepy/conf.py b/moviepy/conf.py
index 44b5bedb..796828bb 100644
--- a/moviepy/conf.py
+++ b/moviepy/conf.py
@@ -34,7 +34,11 @@ You can run this file to check that FFMPEG has been detected.
FFMPEG_BINARY = None
IMAGEMAGICK_BINARY = 'convert'
-
+import os
+try:
+ from subprocess import DEVNULL # py3k
+except ImportError:
+ DEVNULL = open(os.devnull, 'wb')
# =====================================================================
# CODE. Don't write anything below this line !
@@ -43,7 +47,14 @@ import subprocess as sp
def try_cmd(cmd):
try:
- proc = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
+ popen_params = {"stdout": sp.PIPE,
+ "stderr": sp.PIPE,
+ "stdin": DEVNULL}
+
+ if os.name == "nt":
+ popen_params["creationflags"] = 0x08000000
+
+ proc = sp.Popen(cmd, **popen_params)
proc.communicate()
except:
return False
diff --git a/moviepy/tools.py b/moviepy/tools.py
index 16f4aa16..a570ecba 100644
--- a/moviepy/tools.py
+++ b/moviepy/tools.py
@@ -7,12 +7,13 @@ import sys
import warnings
import re
+import os
try:
from subprocess import DEVNULL # py3k
except ImportError:
- import os
DEVNULL = open(os.devnull, 'wb')
+
def sys_write_flush(s):
""" Writes and flushes without delay a text in the console """
sys.stdout.write(s)
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 8df8878f..22d0fcad 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -41,10 +41,10 @@ from ..decorators import (apply_to_mask,
convert_to_seconds)
+import os
try:
from subprocess import DEVNULL # py3k
except ImportError:
- import os
DEVNULL = open(os.devnull, 'wb')
diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py
index e4e77e3d..160aba50 100644
--- a/moviepy/video/io/ffmpeg_reader.py
+++ b/moviepy/video/io/ffmpeg_reader.py
@@ -12,10 +12,10 @@ import numpy as np
from moviepy.conf import FFMPEG_BINARY # ffmpeg, ffmpeg.exe, etc...
from moviepy.tools import cvsecs
+import os
try:
from subprocess import DEVNULL # py3k
except ImportError:
- import os
DEVNULL = open(os.devnull, 'wb')
diff --git a/moviepy/video/io/ffmpeg_writer.py b/moviepy/video/io/ffmpeg_writer.py
index 794d79e1..3296306f 100644
--- a/moviepy/video/io/ffmpeg_writer.py
+++ b/moviepy/video/io/ffmpeg_writer.py
@@ -6,10 +6,10 @@ out of VideoClips
import numpy as np
import subprocess as sp
+import os
try:
from subprocess import DEVNULL # py3k
except ImportError:
- import os
DEVNULL = open(os.devnull, 'wb')
diff --git a/moviepy/video/io/gif_writers.py b/moviepy/video/io/gif_writers.py
index 4f00282d..727f86ad 100644
--- a/moviepy/video/io/gif_writers.py
+++ b/moviepy/video/io/gif_writers.py
@@ -7,9 +7,8 @@ from moviepy.tools import verbose_print, subprocess_call
import numpy as np
try:
- from subprocess import DEVNULL # py3k
+ from subprocess import DEVNULL # py3k
except ImportError:
- import os
DEVNULL = open(os.devnull, 'wb')