Closed yarikoptic closed 5 months ago
Just for information, when ffmpeg terminated with command like kill -9, it produces truncated video which can be detected with command like:
mediainfo -i <video_file> | grep "IsTruncated"
And fixed with command like:
ffmpeg -i <video_file> -c copy <video_file_fixed>
and verify that according to mediainfo etc we have non truncated video
chagpt (yet to be verified) says
Yes, there is a way to send a signal to FFmpeg to make it close the file gracefully and complete the encoding process without abrupt termination. You can send the
SIGINT
signal, which is the same as pressing Ctrl+C in the terminal, or theSIGTERM
signal. Both signals will allow FFmpeg to finish processing and exit cleanly.If you are running FFmpeg from a command line and want to terminate it gracefully, you can simply press Ctrl+C. If you are using FFmpeg in a script or another program and want to terminate it programmatically, you can send these signals to the FFmpeg process. Here's how you can do it in different programming environments:
In a Unix/Linux Shell
You can use the
kill
command followed by the process ID (PID) of the FFmpeg process:or
In Python
You can use the
os
module to send the signal:This will ensure that FFmpeg stops recording, finishes writing to the file, and closes the file properly, preserving the integrity of the media data.