Guest User

Untitled

a guest
Feb 10th, 2017
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import json
  4. from subprocess import Popen, PIPE
  5.  
  6. INPUTFILE='Benzaie Potter.avi'
  7.  
  8. fileInfoProcess = Popen(['ffprobe', '-show_streams', '-print_format', 'json', '-i', INPUTFILE], stdout = PIPE)
  9. fileInfoOutput, _ = fileInfoProcess.communicate()
  10. fileInfo = json.loads(fileInfoOutput)
  11.  
  12. commandLine = ['ffmpeg', '-i', INPUTFILE]
  13.  
  14. filterOutputId = 0
  15. filterList = []
  16. mapLine = []
  17. fileOutputId = 0
  18.  
  19. def getFilterOutput():
  20.     global filterOutputId
  21.     res = 'audio%s' % filterOutputId
  22.     filterOutputId += 1
  23.     return res
  24.  
  25. def getFileOutput(stereo):
  26.     global fileOutputId
  27.     if stereo:
  28.         left = 'audio_%s_left.wav' % fileOutputId
  29.         right = 'audio_%s_right.wav' % fileOutputId
  30.         fileOutputId += 1
  31.         return left, right
  32.     else:
  33.         res = 'audio_%s.wav' % fileOutputId
  34.         fileOutputId += 1
  35.         return res
  36.  
  37. for stream in fileInfo['streams']:
  38.     if stream['codec_type'] != 'audio':
  39.         continue
  40.     if stream['channels'] == 1:
  41.         mapLine += ['-map', '[0:%s]' % stream['index'], getFileOutput(False)]
  42.     elif stream['channels'] == 2:
  43.         leftName, rightName = getFileOutput(True)
  44.         leftOutputName, rightOutputName = getFilterOutput(), getFilterOutput()
  45.         filterList += [
  46.             '[0:%s]pan=1c|c0=c0[%s]' % (stream['index'], leftOutputName),
  47.             '[0:%s]pan=1c|c0=c1[%s]' % (stream['index'], rightOutputName)
  48.             ]
  49.         mapLine += ['-map', '[%s]' % leftOutputName, leftName]
  50.         mapLine += ['-map', '[%s]' % rightOutputName, rightName]
  51.        
  52. commandLine += ['-filter_complex'] + [';'.join(filterList)] + mapLine
  53.  
  54. Popen(commandLine).wait()
Advertisement
Add Comment
Please, Sign In to add comment