Skip to content

Instantly share code, notes, and snippets.

@T31337
Last active January 11, 2017 12:49
Show Gist options
  • Save T31337/1e57d0e6a4a3e27048a6 to your computer and use it in GitHub Desktop.
Save T31337/1e57d0e6a4a3e27048a6 to your computer and use it in GitHub Desktop.
ScreenRecorder&Microphone Audio Recorder Using FFMPEG & Python
#!/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(Seprate File)
Original Source Code: http://pastebin.com/BY1t5AcC
Thanks To Youtube User NoBeansJose
'''
from tkinter import *
from threading import Thread
from os.path import expanduser
import os
import time
import datetime
import tkinter.ttk
def recThread():
recmic = int(chk.getvar(name='chkd'))
os.system('sleep 1s;ffmpeg -f alsa -i hw:0,2 ~/Videos/AudioRecording.wav &')
#os.system("sleep 1s;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 -q:v 3 -r 15 -y ~/Videos/$(date +%d%b_%Hh%Mm).avi &")
os.system("sleep 1s;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 &")
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
os.system("pkill -n ffmpeg")
os.system('sleep 1s')
os.system("pkill -n ffmpeg")
try:
t.stop()
except:
print("")
root = Tk()
recmic = IntVar()
#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,sticky=E)
root.minsize(170,107)
root.maxsize(170,107)
#root.maxsize(160,105)
root.title("CapCam")
root.attributes("-topmost", 1)
root.mainloop()
@pantuts
Copy link

pantuts commented Sep 1, 2014

you can use $(xdpyinfo | grep dimensions | awk '{print $2}') instead of long one used

@T31337
Copy link
Author

T31337 commented Oct 28, 2014

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