SHOW:
|
|
- or go back to the newest paste.
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: |
13 | + | # You will need python-notify and zenity for this to work properly: |
14 | - | # sudo apt-get install googlecl python-notify xcowsay |
14 | + | # sudo apt-get install python-notify zenity |
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" |
32 | + | videoStream = binFolder + "desktop_recording_on_" + nowstring + ".mp4" |
33 | audioStream = binFolder + "microphone_input_on_" + nowstring + ".mp3" | |
34 | - | mergedVideo = binFolder + "screencast_on_" + nowstring + ".mkv" |
34 | + | mergedVideo = binFolder + "screencast_on_" + nowstring + ".mp4" |
35 | - | #procFFmpeg = "/usr/bin/ffmpeg" |
35 | + | durationInfoFile = binFolder + "video_information_file.txt" |
36 | ||
37 | # Define how to get video duration and other key information | |
38 | def getVideoInfo(): | |
39 | f = open(durationInfoFile, "r") | |
40 | for line in f: | |
41 | if "Duration" in line: | |
42 | global videoInfo | |
43 | videoInfo = "Video information: " + line | |
44 | ||
45 | ||
46 | # Define executable programs | |
47 | proc1 = "/usr/bin/ffmpeg" | |
48 | proc2 = "/bin/mkdir" | |
49 | ||
50 | # Define how to create a title for the video within YouTube's 60-character limit | |
51 | def videoTitleInput(): | |
52 | running = True | |
53 | while running: | |
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") |
54 | + | global videoTitle |
55 | videoTitle = raw_input("Enter the video title: ") | |
56 | if len(videoTitle) <= 60: | |
57 | print "The video title is " + videoTitle | |
58 | running = False | |
59 | else: | |
60 | print "Not within Youtube's 60-character limit, try again" | |
61 | ||
62 | # Create datestamped folder | |
63 | os.system("mkdir " + binFolder) | |
64 | ||
65 | #Record video stream with FFmpeg | |
66 | os.system("gnome-terminal --title=Video_Stream -x ffmpeg -f x11grab -r 30 -s 1366x768 -i :0.0 -c:v libx264 -threads 0 " + videoStream) | |
67 | - | #os.system("gnome-terminal -x ffmpeg -i " + videoStream + " -i " + audioStream + " -b 2000k " + mergedVideo) |
67 | + | |
68 | - | #subprocess.call(['/usr/bin/ffmpeg', '-i', videoStream, '-i', audioStream, mergedVideo]) |
68 | + | |
69 | - | subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-ss', '00:00:02.0', '-b:v', '2000k', mergedVideo]) |
69 | + | |
70 | ||
71 | - | videoTitle = raw_input("Enter the video title: ") |
71 | + | |
72 | - | os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + "'" + videoTitle + "'") |
72 | + | |
73 | ||
74 | #Rename VLC screencast window, move it to top-right corner, and make it sticky | |
75 | os.system("sleep 1 && xdotool search --name " + '"' + "VLC Media Player" + '"' + " windowmove 1046 0 set_window --name " + '"' + "TCG Screencast" + '"' + " windowraise") | |
76 | ||
77 | #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 | |
78 | ||
79 | #Defining what I need in order to open and edit the text file to be used later | |
80 | ||
81 | convertPrompt = input("""Do you want to merge the streams? | |
82 | 1. Yes | |
83 | 2. No | |
84 | ||
85 | Please enter your choice: """) | |
86 | ||
87 | if convertPrompt == 1: | |
88 | videoTitleInput() | |
89 | os.system("ffmpeg -i " + videoStream + " 2> " + durationInfoFile) | |
90 | getVideoInfo() | |
91 | os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"') | |
92 | subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo]) | |
93 | sendmessage(py_notify_title, py_notify_message) | |
94 | os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"') | |
95 | else: | |
96 | exitQuestion = input("Are you done? (Press 1) ") | |
97 | if exitQuestion == 1: | |
98 | exit() | |
99 | else: | |
100 | exit() | |
101 | ||
102 | exitQuestionFinal = input("Are you done? (Press 1) ") | |
103 | if exitQuestionFinal == 1: | |
104 | os.system("nautilus " + binFolder) | |
105 | exit() | |
106 | else: | |
107 | exit() |