Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # python testbed
- # _*_ coding: utf-8 _*_
- import sys, os, subprocess, math, readline, easygui
- x11_msg = "Enter Capture Settings"
- x11_title = "x11grab capture settings"
- x11_field_labels = ["Capture Size","Capture Rate","Capture Offset","Aspect Ratio:"]
- x11_def_vals = ["800x600","25","+0+0"]
- x11_vals = easygui.multenterbox(x11_msg, x11_title, x11_field_labels, x11_def_vals)
- x11_size = x11_vals[0]
- x11_rate = x11_vals[1]
- x11_offset = x11_vals[2]
- x11_aspect = x11_vals[3]
- x11_block = "-f x11grab -r %s -s %s -i :0.0%s" % ( x11_rate, x11_size, x11_offset )
- # auto aspect
- auto_aspect = eval(x11_size.replace('x', '.000 / '))
- # insert conditional
- final_aspect = auto_aspect
- # audio capture values
- alsa_msg = "Enter Audio Capture Settings"
- alsa_title = "desktop audio capture settings"
- alsa_field_labels = ["Audio Device:","Sampling Rate:","Channels:"]
- alsa_def_vals = ["pcm.hw:2,0","44100","2"]
- alsa_vals = easygui.multenterbox(alsa_msg, alsa_title, alsa_field_labels, alsa_def_vals)
- alsa_device = alsa_vals[0]
- alsa_rate = alsa_vals[1]
- alsa_channels = alsa_vals[2]
- alsa_block = "-f alsa -ar %s -ac %s -i %s" % ( alsa_rate, alsa_channels, alsa_device )
- # audio output values
- 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 = ["libfaac","128k","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:","Geometry"]
- v_def_vals = ["libx264","ultrafast","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]
- # fix auto aspect should default to 640 / aspect
- y_geo = ( 640 / float(final_aspect) )
- v_geometry = ( '640' + 'x' + str(int(y_geo)) )
- # v_geometry = ( 640 / final_aspect )
- # print v_geometry
- # v_geometry = v_vals[4] # manual aspect
- # 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 = ["LIVESTREAM CHANNEL","USERNAME","PASSWORD","BUFFERTIME"] # 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 -s %s -async 1 -f flv" % ( v_codec, v_vpre, v_frame_rate, v_crf, v_geometry )
- # 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, final_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, final_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, final_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, final_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 %s %s %s %s \"%s\"" % ( x11_block, alsa_block, a_block, v_block, acct_master )
- os.system(stream_init)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement