Advertisement
clockworkpc

Ubuntu Screencasting Script: FFmpeg & VLC & send-notify

Jul 2nd, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.69 KB | None | 0 0
  1. #!/usr/bin/python
  2. #/home/clockworkpc/bin/screencast.py
  3.  
  4. # Released under a GPLv3 Licence by Clockwork PC 2013
  5. # www.clockworkpc.com.au
  6.  
  7. # You are entitled to the following four freedoms:
  8. # Freedom 0: To run this program for any purpose
  9. # Freedom 1: To study how this program works and change it to make it do what you wish
  10. # Freedom 2: To redistribute copies so you can help your neighbour
  11. # Freedom 3: To distribute copies of your modified version to others
  12.  
  13. # You will need python-notify and zenity for this to work properly:
  14. # sudo apt-get install python-notify zenity
  15.  
  16. import os, datetime, pynotify, subprocess
  17.  
  18. #Define notification
  19. py_notify_title = "Screencast"
  20. py_notify_message = "Video has been merged"
  21.  
  22. def sendmessage(py_notify_title, py_notify_message):
  23.     pynotify.init("Test")
  24.     notice = pynotify.Notification(py_notify_title, py_notify_message)
  25.     notice.show()
  26.     return
  27.  
  28. #Define datetime
  29. now = datetime.datetime.now()
  30. nowstring = str(now.strftime("%Y-%m-%d_%A_%H:%M:%S"))
  31.  
  32. #Define video summary
  33. videoSummary = """Sponsored Readings on eBay:
  34. http://myworld.ebay.com.au/thecriticalg
  35. Sponsored Readings on YouTube:
  36. http://goo.gl/OdXtx
  37. The Critical G's Blog:
  38. http://www.thecriticalg.blogspot.com
  39. The Critical G on Facebook:
  40. http://www.facebook.com/critical.gman
  41. The Critical G on Google+
  42. http://goo.gl/bF3DF
  43. Reading Requests:
  44. http://goo.gl/sXpUu
  45. Politically incorrect T-shirts on RedBubble:
  46. http://goo.gl/1yi24
  47. Geeky T-shirts on RedBubble:
  48. http://goo.gl/mJiC1"""
  49.  
  50. # Define folders and files
  51. binFolder = os.getenv("HOME") + "/Videos/Desktop_Recording/" + nowstring + "/"
  52. videoStream = binFolder + "desktop_recording_on_" + nowstring + ".mkv"
  53. audioStream = binFolder + "microphone_input_on_" + nowstring + ".mp3"
  54. mergedVideo = binFolder + "screencast_on_" + nowstring + ".mp4"
  55. durationInfoFile = binFolder + "video_information_file.txt"
  56.  
  57. # Define how to get video duration and other key information
  58. def getVideoInfo():
  59.     f = open(durationInfoFile, "r")
  60.     for line in f:
  61.         if "Duration" in line:
  62.             global videoInfo
  63.             videoInfo = "Video information: " + line       
  64.  
  65.  
  66. # Define executable programs
  67. proc1 = "/usr/bin/ffmpeg"
  68. proc2 = "/bin/mkdir"
  69.  
  70. # Define how to create a title for the video within YouTube's 60-character limit
  71. def videoTitleInput():
  72.     running = True
  73.     while running:
  74.         global videoTitle
  75.         videoTitle = raw_input("Enter the video title: ")
  76.         if len(videoTitle) <= 60:
  77.             print "The video title is " + videoTitle
  78.             running = False
  79.         else:
  80.             print "Not within Youtube's 60-character limit, try again"
  81.  
  82. # Create datestamped folder
  83. os.system("mkdir " + binFolder)
  84.  
  85. #Record video stream with FFmpeg
  86. os.system("gnome-terminal --title=Video_Stream -x ffmpeg -f x11grab -r 30 -s 1366x768 -i :0.0 -c:v libx264 -threads 0 " + videoStream)
  87.  
  88. #Record audio stream with FFmpeg
  89. os.system("gnome-terminal --title=Audio_Stream -x ffmpeg -f alsa -ac 2 -i pulse " + audioStream)
  90.  
  91. #Capture webcam with VLC
  92. os.system("gnome-terminal --title=VLC_Capture -x cvlc --intf rc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=320 :v4l2-height=240")
  93.  
  94. #Move and resize other windows
  95. os.system("xdotool search --name Video_Stream windowsize 640 450 windowmove 750 295a")
  96. os.system("xdotool search --name Screencast_Terminal windowmove 0 0 windowsize 300 250")
  97. os.system("xdotool search --name VLC_Capture windowmove 375 0 windowsize 665 250")
  98. os.system("xdotool search --name Audio_Stream windowmove 0 295 windowsize 650 450")
  99.  
  100. #Rename VLC screencast window, move it to top-right corner, and make it sticky
  101. os.system("sleep 1 && xdotool  search --name " + '"' + "VLC Media Player" + '"' + " windowmove 1046 0 set_window --name " + '"' + "TCG Screencast" + '"' + " windowraise")
  102.  
  103. #Not sure how to make it visible in all workspaces though, for some reason the command "wmctrl -r <WIN> -b add,sticky" doesn't work with os.system
  104.  
  105. #Defining what I need in order to open and edit the text file to be used later
  106.  
  107. convertPrompt = input("""What do you want to do?
  108. 1. Merge the streams and upload to The Critical G
  109. 2. Merge the streams and upload to Clockwork PC
  110. 3. Merge the streams and upload to My Outcast State
  111. 4. Merge the streams and upload to Tabula Lex
  112. 5. Merge the streams and open the folder
  113. 6. Quit
  114.  
  115. Please enter your choice: """)
  116.  
  117. if convertPrompt == 1:
  118.     videoTitleInput()
  119.     videoTags = raw_input("Enter the video tags: ")
  120.     os.system("ffmpeg -i " + audioStream + " 2> " + durationInfoFile)
  121.     getVideoInfo()
  122.     os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"')
  123.     subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo])
  124.     sendmessage(py_notify_title, py_notify_message)
  125.     os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"' + ' --summary=' + '"' + videoSummary + '"' + " --tags " + '"' + videoTags + '"' + " --user=<insert google username>" + " && xcowsay DONE")
  126. elif convertPrompt == 2:
  127.     videoTitleInput()
  128.     videoTags = raw_input("Enter the video tags: ")
  129.     os.system("ffmpeg -i " + audioStream + " 2> " + durationInfoFile)
  130.     getVideoInfo()
  131.     os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"')
  132.     subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo])
  133.     sendmessage(py_notify_title, py_notify_message)
  134.     os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"' + ' --summary=' + '"' + videoSummary + '"' + " --tags " + '"' + videoTags + '"' + " --user=<insert google username>" + " && xcowsay DONE")
  135. elif convertPrompt == 3:
  136.     videoTitleInput()
  137.     videoTags = raw_input("Enter the video tags: ")
  138.     os.system("ffmpeg -i " + audioStream + " 2> " + durationInfoFile)
  139.     getVideoInfo()
  140.     os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"')
  141.     subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo])
  142.     sendmessage(py_notify_title, py_notify_message)
  143.     os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"' + ' --summary=' + '"' + videoSummary + '"' + " --tags " + '"' + videoTags + '"' + " --user=<insert google username>" + " && xcowsay DONE")
  144. elif convertPrompt == 4:
  145.     videoTitleInput()
  146.     videoTags = raw_input("Enter the video tags: ")
  147.     os.system("ffmpeg -i " + audioStream + " 2> " + durationInfoFile)
  148.     getVideoInfo()
  149.     os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"')
  150.     subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo])
  151.     sendmessage(py_notify_title, py_notify_message)
  152.     os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"' + ' --summary=' + '"' + videoSummary + '"' + " --tags " + '"' + videoTags + '"' + " --user=<insert google username>" + " && xcowsay DONE")
  153. elif convertPrompt == 5:
  154.     os.system("ffmpeg -i " + audioStream + " 2> " + durationInfoFile)
  155.     getVideoInfo()
  156.     os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"')
  157.     subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo])
  158.     sendmessage(py_notify_title, py_notify_message)
  159. elif convertPrompt == 6:
  160.     exit()
  161.  
  162. #Finish
  163. exitQuestionFinal = input("Are you done? (Press 1) ")
  164. if exitQuestionFinal == 1:
  165.     os.system("nautilus " + binFolder)
  166.     exit()
  167. else:
  168.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement