Last active
January 11, 2017 12:49
-
-
Save T31337/1e57d0e6a4a3e27048a6 to your computer and use it in GitHub Desktop.
ScreenRecorder&Microphone Audio Recorder Using FFMPEG & Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
This Script Is Mainly From A Youtube User, | |
I Only Modified It Slightly To Make It Python3 Compatable, | |
And Added Custom Microphone Recording Support | |
Original Source Code: http://pastebin.com/BY1t5AcC | |
Thanks To Youtube User NoBeansJose | |
''' | |
import tkinter | |
from tkinter import Label,Button,Tk,ACTIVE,DISABLED,Checkbutton | |
from threading import Thread | |
from os.path import expanduser | |
import os | |
import time | |
import datetime | |
import tkinter.ttk | |
import subprocess | |
def recThread(): | |
if int(chk.getvar(name='chkd')) == 1: | |
'''record Mic Only''' | |
#subprocess.call('ffmpeg -f alsa -i hw:0,2 ~/Videos/AudioRecording.wav',shell=True) | |
'''Record Audio&Video''' | |
subprocess.call("ffmpeg -f x11grab -s $(xdpyinfo | grep 'dimensions:' | awk '{print $2}' | cut -dx -f1)x$(xdpyinfo | grep 'dimensions:' | awk '{print $2}' | cut -dx -f2) -r 15 -i :0.0 -r 15 -f alsa -i hw:0,2 -y ~/Videos/$(date +%d%b_%Hh%Mm).avi",shell=True) | |
else: | |
'''Record Video Only''' | |
subprocess.call("ffmpeg -f x11grab -s $(xdpyinfo | grep 'dimensions:' | awk '{print $2}' | cut -dx -f1)x$(xdpyinfo | grep 'dimensions:' | awk '{print $2}' | cut -dx -f2) -r 15 -i :0.0 -r 15 -y ~/Videos/$(date +%d%b_%Hh%Mm).avi",shell=True) | |
def rec(): | |
global videoFile | |
mydate = datetime.datetime.now() | |
videoFile = mydate.strftime("%d%b_%Hh%Mm.avi") | |
pathSt=os.getcwd()+"/Videos/" | |
l['text']=os.path.expanduser('~')+"/Videos/" | |
l1['text']=videoFile | |
b.config(state=DISABLED) | |
b1.config(state=ACTIVE) | |
t = Thread(target=recThread) | |
t.start() | |
global count_flag, secs, mins | |
count_flag = True | |
secs=0 | |
mins=0 | |
while True: | |
if count_flag == False: | |
break | |
label['text'] = str("%02dm:%02ds" % (mins,secs)) | |
if secs == 0: | |
time.sleep(0) | |
else: | |
time.sleep(1) | |
if(mins==0 and secs==1): | |
b1.config(bg="red") | |
b.config(fg="white") | |
b.config(bg="white") | |
if secs==60: | |
secs=0 | |
mins+=1 | |
label['text'] = str("%02dm:%02ds" % (mins,secs)) | |
root.update() | |
secs = secs+1 | |
def stop(): | |
b.config(state=ACTIVE) | |
b1.config(state=DISABLED) | |
b1.config(fg="white") | |
b1.config(bg="white") | |
b.config(fg="white") | |
b.config(bg="green") | |
global count_flag | |
count_flag = False | |
subprocess.call('pkill -n ffmpeg',shell=True) | |
try: | |
t.stop() | |
except: | |
print("") | |
root = Tk() | |
#fontTime = tkFont.Font(family="Helvetica", size=12) | |
#fontButton = tkFont.Font(family="Monospace", size=11,weight="bold") | |
label = Label(root, text="00m:00s",fg="blue") | |
b = Button(root,text="Record",command=rec,state=ACTIVE,bg="green") | |
b1 = Button(root,text=" Stop ",command=stop,state=DISABLED,bg="white") | |
l = Label(root, text="") | |
l1 = Label(root, text="") | |
label.grid(row=0, column=0, columnspan=2) | |
b.grid(row=1, column=0, padx=1, pady=5) | |
b1.grid(row=1, column=1, padx=1) | |
l.grid(row=3, column=0,columnspan=2)#row=2 | |
l1.grid(row=4, column=0,columnspan=2)#row=3 | |
chk = Checkbutton(root,variable='chkd',text='Record Mic?') | |
chk.grid(row=2,column=1) | |
root.minsize(width=167,height=110) | |
root.maxsize(width=167,height=110) | |
#root.maxsize(160,105) | |
root.title("CapCam") | |
root.attributes("-topmost", 1) | |
root.mainloop() |
Thanks, Im Not Experienced Much In Bash Programming
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you can use $(xdpyinfo | grep dimensions | awk '{print $2}') instead of long one used