Open minhnv16 opened 5 years ago
import ffmpeg, time
#Setup for recording windows desktop to mp4 file
process = (
ffmpeg
.input(format='gdigrab',framerate=25,filename="desktop")
.output(crf="0",preset="ultrafast",filename="./output.mp4",c= "libx264" )
.overwrite_output()
)
#Launch video recording
process = process.run_async(pipe_stdin=True)
#Stop video recording
process.communicate(str.encode("q")) #Equivalent to send a Q
# To be sure that the process ends I wait 3 seconds and then terminate de process (wich is more like kill -9)
time.sleep(3)
process.terminate()
Please consider add a wrapper/function to stop the process, or at least add some notes one this line to the readme or api documentation @kkroening Anyway Thank you very much
So it comes that using this library is not much different from creating some wrapper function around the Popen
and ffmpeg
command, and even more it doesn't require you to sort out how to specify your needs via the library. Anyway, thank you for your job, but letting us get rid of direct Popen
communication would make it really beautiful and helpful
I spent a lot of hours on this, but find simpler solution from this post (new method) https://stackoverflow.com/a/60795888/3673470
So I'm starting process like that (all imports from subprocess):
process = Popen(cmd, stdin=PIPE, creationflags=CREATE_NEW_PROCESS_GROUP)
and when I'm closing it with that signal gracefully:
process.send_signal(signal.CTRL_BREAK_EVENT)
This is literally 2 lines, while other methods require external files / executables / etc.
when ffmpeg stream some input and show option press [q] to stop how to implement in code. thankyou