jackson80 jackson80 - 6 months ago 50
C Question

Elegant early exit from a spawned ffmpeg process in C

I have a program where I build an ffmpeg command string to capture videos with options input through a gtk3 gui. Once I have all my options selected, I spawn a process with the ffmpeg command string. And I add a child watch to tell me when the process has completed.

// Spawn child process
ret = g_spawn_async (NULL, argin, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid1, NULL);
if ( !ret )
g_error ("SPAWN FAILED");

/* Add watch function to catch termination of the process. This function
* will clean any remnants of process */
g_child_watch_add (pid1, (GChildWatchFunc)cb_child_watch, widget );

Executing ffmpeg from a terminal using a command line, the program will give an option to input a "q" at the terminal to end the ffmpeg process early.
Is there any way to send a "q" to that spawned process to elegantly end the ffmpeg? I'm fairly sure I could kill the process using the process id, but I would rather stop it using a mechanism that allows ffmpeg to gracefully exit..
This is running Centos 7, kernel 4.7.5, ffmpeg version 3.0.2.
Since I can still access the terminal where the ffmpeg output is displayed, I've tried typing a "q", but it has no effect on the process.


You could, instead of trying to gracefully use q, try using kill and a SIGTERM. This would still offer your graceful shutdown, although it may not always stop ffmpeg immediately.