I'm new to selenium web driver python and not really sure how to word this but here I go.
I have a script which allows you to record the screen using ffmpeg.
recoder_file_name = 'output.mkv'
proc = subprocess.Popen(['ffmpeg', '-f', 'gdigrab', '-framerate', '15', '-offset_x', '0', '-offset_y', '0', '-video_size', '1920x1080','-i', 'desktop', '-c:v', 'libx264', '-vprofile', 'baseline', '-g', '15', '-crf', '1', '-pix_fmt', 'yuv420p','-threads', '4', recoder_file_name])
# all of mine code
proc.kill()
problem with this is that I don't want to record all of the code only part of the code so I have done this
recoder_file_name = 'output.mkv'
proc = subprocess.Popen(['ffmpeg', '-f', 'gdigrab', '-framerate', '15', '-offset_x', '0', '-offset_y', '0', '-video_size', '1920x1080','-i', 'desktop', '-c:v', 'libx264', '-vprofile', 'baseline', '-g', '15', '-crf', '1', '-pix_fmt', 'yuv420p','-threads', '4', recoder_file_name])
#few part of my code
proc.kill()
recoder_file_name = 'output1.mkv'
proc = subprocess.Popen(['ffmpeg', '-f', 'gdigrab', '-framerate', '15', '-offset_x', '0', '-offset_y', '0', '-video_size', '1920x1080','-i', 'desktop', '-c:v', 'libx264', '-vprofile', 'baseline', '-g', '15', '-crf', '1', '-pix_fmt', 'yuv420p','-threads', '4', recoder_file_name])
#another part of my code
proc.kill()
This method is good but I have to keep writing that long code so I though I will make a function and just call the function
def recorder():
proc = subprocess.Popen(['ffmpeg', '-f', 'gdigrab', '-framerate', '15', '-offset_x', '0', '-offset_y', '0', '-video_size', '1920x1080','-i', 'desktop', '-c:v', 'libx264', '-vprofile', 'baseline', '-g', '15', '-crf', '1', '-pix_fmt', 'yuv420p','-threads', '4', recoder_file_name])
recoder_file_name = 'output.mkv'
recorder()
driver.find_element(By.XPATH, "//*[@id='root']/div/div/div/form/input[1]").send_keys(username)
driver.find_element(By.XPATH, "//*[@id='root']/div/div/div/form/input[2]").send_keys(password)
driver.find_element(By.XPATH, "//*[@id='root']/div/div/div/form/button").click()
proc.kill()
Now I am stuck here were it will record but it wont stop recording because proc.kill()
is unresolved reference 'proc'. I don't know how to make proc.kill()
communicate with def recorder()
function. Is there a solution for this or even a better way?
Also sorry for the title I cant think any better than this.
thanks @Rotem His solution was this
def recorder():
proc = subprocess.Popen(['ffmpeg', '-f', 'gdigrab', '-framerate', '15', '-offset_x', '0', '-offset_y', '0', '-video_size', '1920x1080','-i', 'desktop', '-c:v', 'libx264', '-vprofile', 'baseline', '-g', '15', '-crf', '1', '-pix_fmt', 'yuv420p','-threads', '4', recoder_file_name])
return proc
proc = recorder()
recoder_file_name = 'output.mkv'
recorder()
#part of my code
proc.kill()
recoder_file_name = 'output1.mkv'
recorder()
#another part of my code
proc.kill()
For me this will work but if you have a better solution feel free to post for others <3