@@ -9,7 +9,7 @@ def build_command(cmd, media_obj):
99 if type (cmd ) != list :
1010 cmd = [cmd ]
1111
12- cmd += ['-y' , '-i' , media_obj .filename .replace ("\\ " , "/" )]
12+ cmd += ['-y' , '-i' , '"' + media_obj .filename .replace ("\\ " , "/" ) + '"' ]
1313 cmd += ['-c:v' , media_obj .video_format ]
1414
1515 if media_obj .audio_format is not None :
@@ -25,11 +25,14 @@ def build_command(cmd, media_obj):
2525 return " " .join (cmd )
2626
2727
28- def run_async (media , cmd = 'ffmpeg' , pipe_stdin = False , pipe_stdout = False , pipe_stderr = True , universal_newlines = False ):
28+ def run_async (media , cmd = 'ffmpeg' , pipe_stdin = False , pipe_stdout = False , pipe_stderr = subprocess .STDOUT ,
29+ universal_newlines = False ):
30+
2931 commands = build_command (cmd , media )
3032 stdin_stream = subprocess .PIPE if pipe_stdin else None
3133 stdout_stream = subprocess .PIPE if pipe_stdout else None
32- stderr_stream = subprocess .STDOUT if pipe_stderr else False
34+ stderr_stream = pipe_stderr
35+
3336 return subprocess .Popen (shlex .split (commands ), stdout = stdout_stream , stderr = stderr_stream , stdin = stdin_stream
3437 , universal_newlines = universal_newlines )
3538
@@ -46,7 +49,7 @@ def show_progress(media, callable_progress, cmd, c_stdin):
4649 cmd ,
4750 pipe_stdin = c_stdin ,
4851 pipe_stdout = True ,
49- pipe_stderr = True ,
52+ pipe_stderr = subprocess . STDOUT ,
5053 universal_newlines = True
5154 )
5255
@@ -56,7 +59,9 @@ def show_progress(media, callable_progress, cmd, c_stdin):
5659
5760 while True :
5861 line = process .stdout .readline ().strip ()
59- log += [line ]
62+
63+ if line != '' :
64+ log += [line ]
6065
6166 if line == '' and process .poll () is not None :
6267 break
@@ -71,8 +76,9 @@ def show_progress(media, callable_progress, cmd, c_stdin):
7176 callable_progress (percentage , line , media )
7277
7378 clear_tmp_files (media )
79+
7480 if process .poll ():
75- raise RuntimeError ('ffmpeg' , " " .join (log ))
81+ raise RuntimeError ('ffmpeg' , " " .join (log [ - 3 :]), " " . join ( log ))
7682
7783 return media , log
7884
@@ -86,12 +92,12 @@ def run(media, c_progress=None, cmd='ffmpeg', c_stdout=False, c_stderr=True, c_s
8692 cmd ,
8793 pipe_stdin = c_stdin ,
8894 pipe_stdout = c_stdout ,
89- pipe_stderr = c_stderr ,
95+ pipe_stderr = subprocess . PIPE if c_stderr else False ,
9096 )
9197 out , err = process .communicate (c_input , timeout = timeout )
9298
9399 clear_tmp_files (media )
94100
95101 if process .poll ():
96- raise RuntimeError ('ffmpeg' , out , err )
102+ raise RuntimeError ('ffmpeg' , err , out )
97103 return media , [out , err ]
0 commit comments