From bcb8f27c2e4434d2296dcd66bf279b76ee0d0a4f Mon Sep 17 00:00:00 2001 From: tassaron Date: Sat, 15 Jul 2017 13:13:53 -0400 Subject: use -t on inputs so ffmpeg knows when to stop filters + better feedback in cmd mode --- src/components/video.py | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/components/video.py') diff --git a/src/components/video.py b/src/components/video.py index b3b6a59..0b93293 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -116,6 +116,7 @@ class Component(Component): page = self.loadUi('video.ui') self.videoPath = '' self.badVideo = False + self.badAudio = False self.x = 0 self.y = 0 self.loopVideo = False @@ -161,22 +162,14 @@ class Component(Component): if self.useAudio: props.append('audio') - # test if an audio stream really exists - audioTestCommand = [ - self.core.FFMPEG_BIN, - '-i', self.videoPath, - '-vn', '-f', 'null', '-' - ] - try: - checkOutput(audioTestCommand, stderr=subprocess.DEVNULL) - except subprocess.CalledProcessError: - self.badAudio = True + self.testAudioStream() + if self.badAudio: return ['error'] return props def error(self): - if hasattr(self, 'badAudio'): + if self.badAudio: return "Could not identify an audio stream in this video." if not self.videoPath: return "There is no video selected." @@ -185,6 +178,20 @@ class Component(Component): if self.badVideo: return "The video selected is corrupt!" + def testAudioStream(self): + # test if an audio stream really exists + audioTestCommand = [ + self.core.FFMPEG_BIN, + '-i', self.videoPath, + '-vn', '-f', 'null', '-' + ] + try: + checkOutput(audioTestCommand, stderr=subprocess.DEVNULL) + except subprocess.CalledProcessError: + self.badAudio = True + else: + self.badAudio = False + def audio(self): return (self.videoPath, {'map': '-v'}) @@ -277,7 +284,7 @@ class Component(Component): if not arg.startswith('preset=') and '=' in arg: key, arg = arg.split('=', 1) if key == 'path' and os.path.exists(arg): - if os.path.splitext(arg)[1] in self.core.videoFormats: + if '*%s' % os.path.splitext(arg)[1] in self.core.videoFormats: self.page.lineEdit_video.setText(arg) self.page.spinBox_scale.setValue(100) self.page.checkBox_loop.setChecked(True) @@ -285,10 +292,17 @@ class Component(Component): else: print("Not a supported video format") quit(1) + elif arg == 'audio': + if not self.page.lineEdit_video.text(): + print("'audio' option must follow a video selection") + quit(1) + self.page.checkBox_useAudio.setChecked(True) + return super().command(arg) def commandHelp(self): print('Load a video:\n path=/filepath/to/video.mp4') + print('Using audio:\n path=/filepath/to/video.mp4 audio') def scale(scale, width, height, returntype=None): -- cgit v1.2.3