简体   繁体   中英

Killing ffmpeg from Qt results in a corrupt video file

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:password@192.168.0.100/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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM