Irene T.
Irene T.

Reputation: 1393

Hide system message while running ffmpeg

I am using the code bellow to grab an image from a video file and it is working great. But when i am running the php file that contains the code bellow all system procceses appears, and i mean some infos about the convertion, export etc.

How can i make it run silent?

$stderr = system("ffmpeg -i $videoPath -vframes 1 -an -s 306x173 -ss 03 $finalfilename 2>&1 >/dev/null", $exit_status);

if ($exit_status === 0) {
    print 'Done! :)';
} else {
    print 'Error... :/';
    // $stderr will help you figure out what happened...
}

Upvotes: 2

Views: 1281

Answers (3)

llogan
llogan

Reputation: 134063

You can also use -loglevel quiet as a global option but this will not be helpful if you experience errors.

Upvotes: 1

Paulo Freitas
Paulo Freitas

Reputation: 13649

First of all: sorry! On the other question I made a mistake suggesting you to use system() function, but you clearly need the exec() one.

Furthermore, you might want to suppress any ffmpeg verbose output with -v error to get only error messages on $stderr. You also need to pass -y to avoid getting stuck when $finalfilename already exists. Fixing all together:

exec("ffmpeg -v error -y -i $videoPath -vframes 1 -an -s 306x173 -ss 03 $finalfilename 2>&1 >/dev/null", $stderr, $exit_status);

if ($exit_status === 0) {
    print 'Done! :)';
} else {
    print 'Error... :/';
    // implode("\n", $stderr) will help you figure out what happened...
}

Upvotes: 0

Lajos Veres
Lajos Veres

Reputation: 13725

You should change the order of redirections. Like this:

>/dev/null 2>&1 

Or direct everything directly to /dev/null:

>/dev/null 2>/dev/null

Upvotes: 1

Related Questions