Advertisement
clockworkpc

Ubuntu Screencasting Script: FFmpeg & VLC & send-notify

Jun 23rd, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 to install pynotify and googlecl:
  14. # sudo apt-get install googlecl python-notify xcowsay
  15.  
  16. import os, datetime, pynotify, subprocess
  17.  
  18. py_notify_title = "Screencast"
  19. py_notify_message = "Video has been merged"
  20.  
  21. def sendmessage(py_notify_title, py_notify_message):
  22.     pynotify.init("Test")
  23.     notice = pynotify.Notification(py_notify_title, py_notify_message)
  24.     notice.show()
  25.     return
  26.  
  27. now = datetime.datetime.now()
  28. nowstring = str(now.strftime("%Y-%m-%d_%A_%H:%M:%S"))
  29.  
  30. # Define folders and files
  31. binFolder = os.getenv("HOME") + "/Videos/Desktop_Recording/" + nowstring + "/"
  32. videoStream = binFolder + "desktop_recording_on_" + nowstring + ".mkv"
  33. audioStream = binFolder + "microphone_input_on_" + nowstring + ".mp3"
  34. mergedVideo = binFolder + "screencast_on_" + nowstring + ".mkv"
  35. #procFFmpeg = "/usr/bin/ffmpeg"
  36. proc1 = "/usr/bin/ffmpeg"
  37. proc2 = "/bin/mkdir"
  38.  
  39. # Create datestamped folder
  40. os.system("mkdir " + binFolder)
  41.  
  42. #Record video stream with FFmpeg
  43. os.system("gnome-terminal --title=Video_Stream -x ffmpeg -f x11grab -r 30 -s 1366x768 -i :0.0 -c:v libx264 -threads 0 " + videoStream)
  44.  
  45. #Record audio stream with FFmpeg
  46. os.system("gnome-terminal --title=Audio_Stream -x ffmpeg -f alsa -ac 2 -i pulse " + audioStream)
  47.  
  48. #Capture webcam with VLC
  49. os.system("gnome-terminal --title=VLC_Capture -x cvlc --intf rc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=320 :v4l2-height=240")
  50.  
  51. #Rename VLC screencast window, move it to top-right corner, and make it sticky
  52. os.system("sleep 1 && xdotool  search --name " + '"' + "VLC Media Player" + '"' + " windowmove 1046 0 set_window --name " + '"' + "TCG Screencast" + '"' + " windowraise")
  53.  
  54. #os.system("sleep 1 && xdotool  search --name " + '"' + "VLC Media Player" + '"' + " windowmove 1046 0 set_window --name " + '"' + "TCG Screencast" + '"' + " windowraise windowactivate key --clearmodifiers alt+space type a")
  55.  
  56. #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
  57.  
  58. #Defining what I need in order to open and edit the text file to be used later
  59.  
  60. convertPrompt = input("""Do you want to merge the streams?
  61. 1. Yes
  62. 2. No
  63.  
  64. Please enter your choice: """)
  65.  
  66. if convertPrompt == 1:
  67.     #os.system("gnome-terminal -x ffmpeg -i " + videoStream + " -i " + audioStream + " -b 2000k " + mergedVideo)
  68.     #subprocess.call(['/usr/bin/ffmpeg', '-i', videoStream, '-i', audioStream, mergedVideo])
  69.     subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-ss', '00:00:02.0', '-b:v', '2000k', mergedVideo])
  70.     sendmessage(py_notify_title, py_notify_message)
  71.     videoTitle = raw_input("Enter the video title: ")
  72.     os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + "'" + videoTitle + "'")
  73. else:
  74.     exitQuestion = input("Are you done? (Press 1) ")       
  75.     if exitQuestion == 1:
  76.         exit()
  77.     else:
  78.         exit()
  79.  
  80. exitQuestionFinal = input("Are you done? (Press 1) ")
  81. if exitQuestionFinal == 1:
  82.     os.system("nautilus " + binFolder)
  83.     exit()
  84. else:
  85.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement