Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. #!/usr/bin/python
  2. # python testbed
  3. # _*_ coding: utf-8 _*_
  4. #
  5. import sys, datetime, os, subprocess, math, readline, easygui
  6.  
  7. # check sys.argv for null value by iterating the array pockets - IMPROVE ME
  8.  
  9. count = 0
  10. for f in sys.argv[:]:
  11. count+=1
  12.  
  13. # DEP_PROD: print count
  14. # open the easygui file dialogue box if no file was defined as a script argument
  15.  
  16. if count is 1:
  17. file_path = easygui.fileopenbox()
  18.  
  19. # define the file_path variable as the first argument passed to the script
  20.  
  21. else:
  22. file_path = sys.argv[1]
  23.  
  24. # define the command strings that will be used to generate the file aspect ratio
  25.  
  26. # >> and > both write to the file > clears the file before writing. the file node is preserved DONT DELETE the width and height files
  27.  
  28. 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
  29.  
  30. 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
  31.  
  32. # execute the commands and print the current job iteration
  33.  
  34. cmd_array = [width_cmd, height_cmd]
  35. count=0
  36. for cur_cmd in cmd_array:
  37. print "process %s" % count
  38. subprocess.call(cur_cmd, shell=True)
  39. count+=1
  40. pyff_vals = open('/tmp/pyff.txt')
  41. read_probe_one = float(pyff_vals.readline())
  42. read_probe_two = float(pyff_vals.readline())
  43. aspect = ( read_probe_one / read_probe_two )
  44. pyff_vals.close()
  45. # limit the aspect float to three decimals
  46.  
  47. f_aspect = "%.3f" % aspect
  48. # DEL_PROD: print f_aspect # verify the aspect limit
  49.  
  50. a_msg = "Enter audio encoder settings"
  51. a_title = "audio encoder settings"
  52. a_field_labels = ["Audio Codec:","Audio Bitrate:","Audio Channels:","Audio Rate:"]
  53. a_def_vals = ["libmp3lame","64k","2","44100"]
  54. a_vals = easygui.multenterbox(a_msg, a_title, a_field_labels, a_def_vals)
  55. a_codec = a_vals[0]
  56. a_bitrate = a_vals[1]
  57. a_channels = a_vals[2]
  58. a_rate = a_vals[3]
  59. # DEL_PROD: print a_codec, a_bitrate, a_channels, a_rate
  60.  
  61. v_msg = "Enter video encoder settings"
  62. v_title = "video encoder settings"
  63. v_field_labels = ["Video Codec:","Vpre:","Constant Rate Factor:","Frame Rate:"]
  64. v_def_vals = ["libx264","faster","28","25"]
  65. v_vals = easygui.multenterbox(v_msg, v_title, v_field_labels, v_def_vals)
  66. v_codec = v_vals[0]
  67. v_vpre = v_vals[1]
  68. v_crf = v_vals[2]
  69. v_frame_rate = v_vals[3]
  70. # DEL_PROD: print v_codec, v_vpre, v_crf, v_frame_rate
  71.  
  72. acct_msg = "Enter the livestream account information and buffer time"
  73. acct_title = "Account information"
  74. acct_field_labels = ["Livestream Channel","Livestream Username","Channel Password","Buffer Time"]
  75.  
  76. # acct_def_vals = ["","","0"]
  77.  
  78. acct_def_vals = ["CHANNEL","USERNAME","PASSWORD","BUFFERTIME (ms)"] # local account defaults
  79.  
  80. acct_vals = easygui.multenterbox(acct_msg, acct_title, acct_field_labels, acct_def_vals)
  81. channel = acct_vals[0]
  82. username = acct_vals[1]
  83. password = acct_vals[2]
  84. buffertime = acct_vals[3]
  85.  
  86. # define the string field blocks
  87. # begin by defining the audio block and inserting the input variables
  88. a_block = "-acodec %s -ac %s -ar %s -ab %s" % ( a_codec, a_channels, a_rate, a_bitrate )
  89. # print a_block # verify the audio block definitions
  90.  
  91. # define the video block and insert the input variables
  92. v_block = "-vcodec %s -vpre %s -r %s -crf %s -async 1 -f flv" % ( v_codec, v_vpre, v_frame_rate, v_crf )
  93. # DEL_PROD: print v_block # verify the video block definitions
  94.  
  95. # define the account block and insert the input variables
  96. 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 )
  97.  
  98. 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 )
  99.  
  100. 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 )
  101.  
  102. 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 )
  103.  
  104. # concatenate the sub account blocks into the variable acct_master
  105.  
  106. acct_master = ( acct_block_a + acct_block_b + acct_block_c + acct_block_d )
  107. # DEL_PROD: print acct_master
  108.  
  109. stream_init = "ffmpeg -i \"%s\" -re %s %s \"%s\"" % ( file_path, a_block, v_block, acct_master )
  110. os.system(stream_init)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement