Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys, os, subprocess, shlex, re, json, requests
- from subprocess import call
- # FFprobe function
- def FFprobe(filename):
- cmnd = ['ffprobe', '-show_streams', '-print_format', 'json', filename]
- p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- return out
- # Check arguments
- if len(sys.argv) != 3:
- print "Invalid arguments. Give 2 inputs"
- print " Format: python create_bumper.py <input> <output>"
- quit()
- # Defining variables
- inputFile = sys.argv[1]
- outputFile = sys.argv[2]
- # Probing
- probe= FFprobe(inputFile)
- # Parsing JSON
- json = json.loads(probe)
- # Looping each stream
- for stream in json["streams"]:
- if stream["codec_type"] == "video":
- videoIndex = stream["index"]
- elif stream["codec_type"] == "audio":
- audioIndex = stream["index"]
- video = json["streams"][videoIndex]
- audio = json["streams"][audioIndex]
- # Creating arguments for ffmpeg
- executable = ['ffmpeg', '-hide_banner', '-y', '-v', 'error', '-i', inputFile]
- videoCommands = ['-c:v', 'libx264', '-profile:v', video["profile"], '-level', str(video["level"]), '-pix_fmt', video["pix_fmt"], '-filter_complex', 'scale='+str(video["width"])+':'+str(video["height"]), '-bf', '0' ]
- audioCommands = ['-c:a', 'aac', '-ar', audio["sample_rate"]]
- outputCommands = [ outputFile ]
- cmnd = executable + videoCommands + audioCommands + outputCommands
- # Running ffmpeg with the gathererd data
- p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- if err:
- print err
- print cmnd
- else:
- print " >> Converted succesfully!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement