Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #/home/clockworkpc/bin/screencast.py
- # Released under a GPLv3 Licence by Clockwork PC 2013
- # www.clockworkpc.com.au
- # You are entitled to the following four freedoms:
- # Freedom 0: To run this program for any purpose
- # Freedom 1: To study how this program works and change it to make it do what you wish
- # Freedom 2: To redistribute copies so you can help your neighbour
- # Freedom 3: To distribute copies of your modified version to others
- # You will need python-notify and zenity for this to work properly:
- # sudo apt-get install python-notify zenity
- import os, datetime, pynotify, subprocess
- py_notify_title = "Screencast"
- py_notify_message = "Video has been merged"
- def sendmessage(py_notify_title, py_notify_message):
- pynotify.init("Test")
- notice = pynotify.Notification(py_notify_title, py_notify_message)
- notice.show()
- return
- now = datetime.datetime.now()
- nowstring = str(now.strftime("%Y-%m-%d_%A_%H:%M:%S"))
- # Define folders and files
- binFolder = os.getenv("HOME") + "/Videos/Desktop_Recording/" + nowstring + "/"
- videoStream = binFolder + "desktop_recording_on_" + nowstring + ".mp4"
- audioStream = binFolder + "microphone_input_on_" + nowstring + ".mp3"
- mergedVideo = binFolder + "screencast_on_" + nowstring + ".mp4"
- durationInfoFile = binFolder + "video_information_file.txt"
- # Define how to get video duration and other key information
- def getVideoInfo():
- f = open(durationInfoFile, "r")
- for line in f:
- if "Duration" in line:
- global videoInfo
- videoInfo = "Video information: " + line
- # Define executable programs
- proc1 = "/usr/bin/ffmpeg"
- proc2 = "/bin/mkdir"
- # Define how to create a title for the video within YouTube's 60-character limit
- def videoTitleInput():
- running = True
- while running:
- global videoTitle
- videoTitle = raw_input("Enter the video title: ")
- if len(videoTitle) <= 60:
- print "The video title is " + videoTitle
- running = False
- else:
- print "Not within Youtube's 60-character limit, try again"
- # Create datestamped folder
- os.system("mkdir " + binFolder)
- #Record video stream with FFmpeg
- os.system("gnome-terminal --title=Video_Stream -x ffmpeg -f x11grab -r 30 -s 1366x768 -i :0.0 -c:v libx264 -threads 0 " + videoStream)
- #Record audio stream with FFmpeg
- os.system("gnome-terminal --title=Audio_Stream -x ffmpeg -f alsa -ac 2 -i pulse " + audioStream)
- #Capture webcam with VLC
- os.system("gnome-terminal --title=VLC_Capture -x cvlc --intf rc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=320 :v4l2-height=240")
- #Rename VLC screencast window, move it to top-right corner, and make it sticky
- os.system("sleep 1 && xdotool search --name " + '"' + "VLC Media Player" + '"' + " windowmove 1046 0 set_window --name " + '"' + "TCG Screencast" + '"' + " windowraise")
- #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
- #Defining what I need in order to open and edit the text file to be used later
- convertPrompt = input("""Do you want to merge the streams?
- 1. Yes
- 2. No
- Please enter your choice: """)
- if convertPrompt == 1:
- videoTitleInput()
- os.system("ffmpeg -i " + videoStream + " 2> " + durationInfoFile)
- getVideoInfo()
- os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"')
- subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo])
- sendmessage(py_notify_title, py_notify_message)
- os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"')
- else:
- exitQuestion = input("Are you done? (Press 1) ")
- if exitQuestion == 1:
- exit()
- else:
- exit()
- exitQuestionFinal = input("Are you done? (Press 1) ")
- if exitQuestionFinal == 1:
- os.system("nautilus " + binFolder)
- exit()
- else:
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement