Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import json
- from subprocess import Popen, PIPE
- INPUTFILE='Benzaie Potter.avi'
- fileInfoProcess = Popen(['ffprobe', '-show_streams', '-print_format', 'json', '-i', INPUTFILE], stdout = PIPE)
- fileInfoOutput, _ = fileInfoProcess.communicate()
- fileInfo = json.loads(fileInfoOutput)
- commandLine = ['ffmpeg', '-i', INPUTFILE]
- filterOutputId = 0
- filterList = []
- mapLine = []
- fileOutputId = 0
- def getFilterOutput():
- global filterOutputId
- res = 'audio%s' % filterOutputId
- filterOutputId += 1
- return res
- def getFileOutput(stereo):
- global fileOutputId
- if stereo:
- left = 'audio_%s_left.wav' % fileOutputId
- right = 'audio_%s_right.wav' % fileOutputId
- fileOutputId += 1
- return left, right
- else:
- res = 'audio_%s.wav' % fileOutputId
- fileOutputId += 1
- return res
- for stream in fileInfo['streams']:
- if stream['codec_type'] != 'audio':
- continue
- if stream['channels'] == 1:
- mapLine += ['-map', '[0:%s]' % stream['index'], getFileOutput(False)]
- elif stream['channels'] == 2:
- leftName, rightName = getFileOutput(True)
- leftOutputName, rightOutputName = getFilterOutput(), getFilterOutput()
- filterList += [
- '[0:%s]pan=1c|c0=c0[%s]' % (stream['index'], leftOutputName),
- '[0:%s]pan=1c|c0=c1[%s]' % (stream['index'], rightOutputName)
- ]
- mapLine += ['-map', '[%s]' % leftOutputName, leftName]
- mapLine += ['-map', '[%s]' % rightOutputName, rightName]
- commandLine += ['-filter_complex'] + [';'.join(filterList)] + mapLine
- Popen(commandLine).wait()
Advertisement
Add Comment
Please, Sign In to add comment