Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. #!/usr/bin/python
  2. # python testbed
  3. # _*_ coding: utf-8 _*_
  4. import sys, os, subprocess, math, readline, easygui
  5.  
  6. x11_msg = "Enter Capture Settings"
  7. x11_title = "x11grab capture settings"
  8. x11_field_labels = ["Capture Size","Capture Rate","Capture Offset","Aspect Ratio:"]
  9. x11_def_vals = ["800x600","25","+0+0"]
  10. x11_vals = easygui.multenterbox(x11_msg, x11_title, x11_field_labels, x11_def_vals)
  11. x11_size = x11_vals[0]
  12. x11_rate = x11_vals[1]
  13. x11_offset = x11_vals[2]
  14. x11_aspect = x11_vals[3]
  15. x11_block = "-f x11grab -r %s -s %s -i :0.0%s" % ( x11_rate, x11_size, x11_offset )
  16.  
  17. # auto aspect
  18.  
  19. auto_aspect = eval(x11_size.replace('x', '.000 / '))
  20.  
  21. # insert conditional
  22.  
  23. final_aspect = auto_aspect
  24.  
  25. # audio capture values
  26. alsa_msg = "Enter Audio Capture Settings"
  27. alsa_title = "desktop audio capture settings"
  28. alsa_field_labels = ["Audio Device:","Sampling Rate:","Channels:"]
  29. alsa_def_vals = ["pcm.hw:2,0","44100","2"]
  30. alsa_vals = easygui.multenterbox(alsa_msg, alsa_title, alsa_field_labels, alsa_def_vals)
  31. alsa_device = alsa_vals[0]
  32. alsa_rate = alsa_vals[1]
  33. alsa_channels = alsa_vals[2]
  34.  
  35. alsa_block = "-f alsa -ar %s -ac %s -i %s" % ( alsa_rate, alsa_channels, alsa_device )
  36.  
  37. # audio output values
  38. a_msg = "Enter audio encoder settings"
  39. a_title = "audio encoder settings"
  40. a_field_labels = ["Audio Codec:","Audio Bitrate:","Audio Channels:","Audio Rate:"]
  41. a_def_vals = ["libfaac","128k","2","44100"]
  42. a_vals = easygui.multenterbox(a_msg, a_title, a_field_labels, a_def_vals)
  43. a_codec = a_vals[0]
  44. a_bitrate = a_vals[1]
  45. a_channels = a_vals[2]
  46. a_rate = a_vals[3]
  47. # DEL_PROD: print a_codec, a_bitrate, a_channels, a_rate
  48.  
  49. v_msg = "Enter video encoder settings"
  50. v_title = "video encoder settings"
  51. v_field_labels = ["Video Codec:","Vpre:","Constant Rate Factor:","Frame Rate:","Geometry"]
  52. v_def_vals = ["libx264","ultrafast","28","25"]
  53. v_vals = easygui.multenterbox(v_msg, v_title, v_field_labels, v_def_vals)
  54. v_codec = v_vals[0]
  55. v_vpre = v_vals[1]
  56. v_crf = v_vals[2]
  57. v_frame_rate = v_vals[3]
  58. # fix auto aspect should default to 640 / aspect
  59.  
  60. y_geo = ( 640 / float(final_aspect) )
  61. v_geometry = ( '640' + 'x' + str(int(y_geo)) )
  62.  
  63. # v_geometry = ( 640 / final_aspect )
  64. # print v_geometry
  65.  
  66. # v_geometry = v_vals[4] # manual aspect
  67.  
  68. # DEL_PROD: print v_codec, v_vpre, v_crf, v_frame_rate
  69.  
  70. acct_msg = "Enter the livestream account information and buffer time"
  71. acct_title = "Account information"
  72. acct_field_labels = ["Livestream Channel","Livestream Username","Channel Password","Buffer Time"]
  73.  
  74. # acct_def_vals = ["","","0"]
  75.  
  76. acct_def_vals = ["LIVESTREAM CHANNEL","USERNAME","PASSWORD","BUFFERTIME"] # local account defaults
  77.  
  78. acct_vals = easygui.multenterbox(acct_msg, acct_title, acct_field_labels, acct_def_vals)
  79. channel = acct_vals[0]
  80. username = acct_vals[1]
  81. password = acct_vals[2]
  82. buffertime = acct_vals[3]
  83.  
  84. # define the string field blocks
  85. # begin by defining the audio block and inserting the input variables
  86. a_block = "-acodec %s -ac %s -ar %s -ab %s" % ( a_codec, a_channels, a_rate, a_bitrate )
  87. # print a_block # verify the audio block definitions
  88.  
  89. # define the video block and insert the input variables
  90. 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 )
  91. # DEL_PROD: print v_block # verify the video block definitions
  92.  
  93. # define the account block and insert the input variables
  94. 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 )
  95.  
  96. 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 )
  97.  
  98. 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 )
  99.  
  100. 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 )
  101.  
  102. # concatenate the sub account blocks into the variable acct_master
  103.  
  104. acct_master = ( acct_block_a + acct_block_b + acct_block_c + acct_block_d )
  105. # DEL_PROD: print acct_master
  106.  
  107. stream_init = "ffmpeg %s %s %s %s \"%s\"" % ( x11_block, alsa_block, a_block, v_block, acct_master )
  108. os.system(stream_init)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement