ffpmeg – how to detect if video crop is completed?

Thanks in advance.

I’m trying to crop a .mp4 video using an ffmpeg binary (within the context of an electron-react-app).

(The binary is run in a child process using execFile() and outputs to a temp folder which is later deleted)

ffmpeg varies considerably in the time it takes to complete the creation of a cropped video file (1sec to 18sec) depending on the computer (mac vs Windows).

I need to read the cropped video file.

I’ve set up an event listener in the Main process of electron

if (!monitorCroppedFile) {
        console.log(`${croppedFilePath} doesn't exist`);
      } else {
        console.log(`${croppedFilePath} exists !`)
        ...readFile...;

Once monitorCroppedFile = true I read it using fs.readfile().

The problem is that ffmpeg initally creates the cropped file path but it sometimes takes ages to complete the process of cropping.

This results in the read file often being blank (as the read is triggered on detecting the file path of the cropped file).

I’ve tried using -preset ultrafast in the ffmpeg arguments but this only improves things on Windows marginally.

The problem doesn’t occur on Macs.

Can anybody suggest a possible solution ? Is there a way to detect when the crop is fully completed ?

Many thanks.

Answer

Add -progress FILE to your command where FILE should be a filename. ffmpeg will log processing status to that file. Search for the line progress=end in it. Once you find it, you can read the file.