Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # python testbed
- # _*_ coding: utf-8 _*_
- #
- import sys, datetime, os, subprocess, math, readline, easygui
- # check sys.argv for null value by iterating the array pockets - IMPROVE ME
- count = 0
- for f in sys.argv[:]:
- count+=1
- # DEP_PROD: print count
- # open the easygui file dialogue box if no file was defined as a script argument
- if count is 1:
- file_path = easygui.fileopenbox()
- # define the file_path variable as the first argument passed to the script
- else:
- file_path = sys.argv[1]
- # define the command strings that will be used to generate the file aspect ratio
- # >> and > both write to the file > clears the file before writing. the file node is preserved DONT DELETE the width and height files
- width_cmd = "ffprobe -show_streams \"%s\" 2>/dev/null | grep width | tr -d \"width=\" > /tmp/pyff.txt" % file_path # first the width file is written
- height_cmd = "ffprobe -show_streams \"%s\" 2>/dev/null | grep height | tr -d \"height=\" >> /tmp/pyff.txt" % file_path # then the height file is appended
- # execute the commands and print the current job iteration
- cmd_array = [width_cmd, height_cmd]
- count=0
- for cur_cmd in cmd_array:
- print "process %s" % count
- subprocess.call(cur_cmd, shell=True)
- count+=1
- pyff_vals = open('/tmp/pyff.txt')
- read_probe_one = float(pyff_vals.readline())
- read_probe_two = float(pyff_vals.readline())
- aspect = ( read_probe_one / read_probe_two )
- pyff_vals.close()
- # limit the aspect float to three decimals
- f_aspect = "%.3f" % aspect
- # DEL_PROD: print f_aspect # verify the aspect limit
- a_msg = "Enter audio encoder settings"
- a_title = "audio encoder settings"
- a_field_labels = ["Audio Codec:","Audio Bitrate:","Audio Channels:","Audio Rate:"]
- a_def_vals = ["libmp3lame","64k","2","44100"]
- a_vals = easygui.multenterbox(a_msg, a_title, a_field_labels, a_def_vals)
- a_codec = a_vals[0]
- a_bitrate = a_vals[1]
- a_channels = a_vals[2]
- a_rate = a_vals[3]
- # DEL_PROD: print a_codec, a_bitrate, a_channels, a_rate
- v_msg = "Enter video encoder settings"
- v_title = "video encoder settings"
- v_field_labels = ["Video Codec:","Vpre:","Constant Rate Factor:","Frame Rate:"]
- v_def_vals = ["libx264","faster","28","25"]
- v_vals = easygui.multenterbox(v_msg, v_title, v_field_labels, v_def_vals)
- v_codec = v_vals[0]
- v_vpre = v_vals[1]
- v_crf = v_vals[2]
- v_frame_rate = v_vals[3]
- # DEL_PROD: print v_codec, v_vpre, v_crf, v_frame_rate
- acct_msg = "Enter the livestream account information and buffer time"
- acct_title = "Account information"
- acct_field_labels = ["Livestream Channel","Livestream Username","Channel Password","Buffer Time"]
- # acct_def_vals = ["","","0"]
- acct_def_vals = ["CHANNEL","USERNAME","PASSWORD","BUFFERTIME (ms)"] # local account defaults
- acct_vals = easygui.multenterbox(acct_msg, acct_title, acct_field_labels, acct_def_vals)
- channel = acct_vals[0]
- username = acct_vals[1]
- password = acct_vals[2]
- buffertime = acct_vals[3]
- # define the string field blocks
- # begin by defining the audio block and inserting the input variables
- a_block = "-acodec %s -ac %s -ar %s -ab %s" % ( a_codec, a_channels, a_rate, a_bitrate )
- # print a_block # verify the audio block definitions
- # define the video block and insert the input variables
- v_block = "-vcodec %s -vpre %s -r %s -crf %s -async 1 -f flv" % ( v_codec, v_vpre, v_frame_rate, v_crf )
- # DEL_PROD: print v_block # verify the video block definitions
- # define the account block and insert the input variables
- acct_block_a = "rtmp://fme.mogulus.com/mogulus/%s/username=%s/password=%s/isAutoLive=true/autoVOD=false/autoRecord=false/aspectWidth=%s/aspectHeight=1/bufferTime=%s " % ( channel, username, password, f_aspect, buffertime )
- acct_block_b = "app=mogulus/%s/username=%s/password=%s/isAutoLive=true/autoRecord=false/aspectWidth=%s/aspectHeight=1/bufferTime=%s " % ( channel, username, password, f_aspect, buffertime )
- acct_block_c = "tcurl=rtmp://fme.mogulus.com/mogulus/%s/username=%s/password=%s/isAutolive=true/autoRecord=false/aspectWidth=%s/aspectHeight=1/bufferTime=%s " % ( channel, username, password, f_aspect, buffertime )
- acct_block_d = "swfUrl=rtmp://publish.livestream.om/mogulus/%s/username=%s/password=%s/isAutolive=true/autoRecord=false/aspectWidth=%s/aspectHeight=1/bufferTime=%s flashver=FME/2.5\20(compatible;\20FMSc/0.9) live=true" % ( channel, username, password, f_aspect, buffertime )
- # concatenate the sub account blocks into the variable acct_master
- acct_master = ( acct_block_a + acct_block_b + acct_block_c + acct_block_d )
- # DEL_PROD: print acct_master
- stream_init = "ffmpeg -i \"%s\" -re %s %s \"%s\"" % ( file_path, a_block, v_block, acct_master )
- os.system(stream_init)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement