From b7931572a73d408dceecc4b17b784a0338e0e35b Mon Sep 17 00:00:00 2001 From: tassaron Date: Thu, 13 Jul 2017 14:46:22 -0400 Subject: [PATCH] added option to include audio from Video components --- src/components/video.py | 8 +++----- src/core.py | 16 ++++++++++++++-- src/video_thread.py | 4 ++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/video.py b/src/components/video.py index 49bd145..53487b1 100644 --- a/src/components/video.py +++ b/src/components/video.py @@ -143,7 +143,6 @@ class Component(Component): super().update() def previewRender(self, previewWorker): - self.videoFormats = previewWorker.core.videoFormats width = int(previewWorker.core.settings.value('outputWidth')) height = int(previewWorker.core.settings.value('outputHeight')) self.updateChunksize(width, height) @@ -156,8 +155,7 @@ class Component(Component): def properties(self): props = [] if self.useAudio: - # props.append('audio') - pass + props.append('audio') if self.videoPath and not os.path.exists(self.videoPath): props.append('error') return props @@ -168,7 +166,7 @@ class Component(Component): "layer %s does not exist!" % str(self.compPos) def audio(self): - return (self.videoPath, {}) + return (self.videoPath, {'map': '-v'}) def preFrameRender(self, **kwargs): super().preFrameRender(**kwargs) @@ -216,7 +214,7 @@ class Component(Component): imgDir = self.settings.value("componentDir", os.path.expanduser("~")) filename, _ = QtWidgets.QFileDialog.getOpenFileName( self.page, "Choose Video", - imgDir, "Video Files (%s)" % " ".join(self.videoFormats) + imgDir, "Video Files (%s)" % " ".join(self.core.videoFormats) ) if filename: self.settings.setValue("componentDir", os.path.dirname(filename)) diff --git a/src/core.py b/src/core.py index 64f55eb..d72760d 100644 --- a/src/core.py +++ b/src/core.py @@ -526,13 +526,25 @@ class Core: if 'audio' in comp.properties() ] if extraAudio: - for extraInputFile, params in extraAudio: + unwantedVideoStreams = [] + for compNo, params in enumerate(extraAudio): + extraInputFile, params = params ffmpegCommand.extend([ '-i', extraInputFile ]) + if 'map' in params and params['map'] == '-v': + # a video stream to remove + unwantedVideoStreams.append(compNo + 1) + + if unwantedVideoStreams: + ffmpegCommand.extend(['-map', '0']) + for compNo in unwantedVideoStreams: + ffmpegCommand.extend([ + '-map', '-%s:v' % str(compNo) + ]) ffmpegCommand.extend([ '-filter_complex', - 'amix=inputs=%s:duration=longest:dropout_transition=3' % str( + 'amix=inputs=%s:duration=first:dropout_transition=3' % str( len(extraAudio) + 1 ), ]) diff --git a/src/video_thread.py b/src/video_thread.py index f736013..bfb0cc4 100644 --- a/src/video_thread.py +++ b/src/video_thread.py @@ -175,8 +175,8 @@ class Worker(QtCore.QObject): self.staticComponents[compNo] = None ffmpegCommand = self.core.createFfmpegCommand(inputFile, outputFile) - print('###### FFMPEG COMMAND ######\n %s' % " ".join(ffmpegCommand)) - print('###### -------------- ######') + print('###### FFMPEG COMMAND ######\n%s' % " ".join(ffmpegCommand)) + print('############################') self.out_pipe = openPipe( ffmpegCommand, stdin=sp.PIPE, stdout=sys.stdout, stderr=sys.stdout )