View difference between Paste ID: 0VeAgdQy and ERkDJzQC
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 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-
videoStream = binFolder + "desktop_recording_on_" + nowstring + ".mp4"
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("ffmpeg -i " + videoStream + " 2> " + durationInfoFile)
89+
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-
	os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"')
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("""Do you want to merge the streams? 
108
1. Yes
109
2. No
110
111
Please enter your choice: """)
112
113
if convertPrompt == 1:
114
	videoTitleInput()
115
	videoTags = raw_input("Enter the video tags: ")
116
	os.system("ffmpeg -i " + audioStream + " 2> " + durationInfoFile)
117
	getVideoInfo()
118
	os.system("gnome-terminal -x zenity --notification --text=" + '"' + videoInfo + '"')
119
	subprocess.call([proc1, '-i', videoStream, '-i', audioStream, '-c:v', 'libx264', '-threads', '0','-ss', '00:00:02.0', '-crf', '24', '-s', '640x360', mergedVideo])
120
	sendmessage(py_notify_title, py_notify_message)
121
	os.system("google youtube post --verbose --category News " + mergedVideo + " --title " + '"' + videoTitle + '"' + ' --summary=' + '"' + videoSummary + '"' + " --tags " + '"' + videoTags + '"')
122
else:
123
	exitQuestion = input("Are you done? (Press 1) ")		
124
	if exitQuestion == 1:
125
		exit()
126
	else:
127
		exit()
128
129
exitQuestionFinal = input("Are you done? (Press 1) ")
130
if exitQuestionFinal == 1:
131
	os.system("nautilus " + binFolder)
132
	exit()
133
else:
134
	exit()