Reputation: 9087
I'm using Qt to record stream data from a Mobotix camera on Windows 7. The command I use is:
ffmpeg -f mjpeg -i "http://admin:[email protected]/control/faststream.jpg?stream=full" -c:v libx264 -preset slow -crf 22 -c:a copy out.mp4
This works fine from the command line and when I want to stop it I just do Ctrl-C. But I'm doing this from an application using Qt 5.2 via a QProcess. After 10 minutes I want to stop the recording so I tried QProcess::terminate() but this doesn't stop it. QProcess::kill() works but the resulting video won't play. This answer suggests I'm doing it the right way.
I connect to QProcess::finished() so when I call QProcess::kill() the result is:
Apparently this is the return code Qt uses when it kills a process.
So is there any other way for me to either terminate the process gracefully (the same as pressing Ctrl-C) or perform this same functionality via an ffmpeg library so I can stop it properly?
Upvotes: 1
Views: 1642
Reputation: 53
I explain the correct way for handling the same exact issue in that thread: http://qt-project.org/forums/viewthread/47654/
its very simple all you need is to send q for quit signal this is simple example:
myProcess->setProcessChannelMode(QProcess::ForwardedChannels);
myProcess->write("q");
myProcess->closeWriteChannel();
keep in mind you also have to exit your parent process too... good luck.
Upvotes: 3
Reputation: 4195
Qt doesn't have a portable way to do this. However, you can use QProcess::processId()
to get a native process PID which you can use. On POSIX-complitable
systems you can use kill(pid, SIGINT)
to send a Ctrl-C
. Just include signal.h
and sys/types.h
. On Windows it's harder, look on this question: link
Upvotes: 1