Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timmy tries to resize video files #38

Closed
therealgilles opened this issue May 3, 2021 · 6 comments
Closed

Timmy tries to resize video files #38

therealgilles opened this issue May 3, 2021 · 6 comments

Comments

@therealgilles
Copy link

therealgilles commented May 3, 2021

I just ran into an issue where Timmy was trying to resize video files with ffmpeg. Is that expected?
This ended up creating multiple ffmpeg processes that were filling /tmp with magick-* files and filling up memory, resulting in a server crash.

This is what the ffmpeg cmd lines looked like:

> sh -c 'ffmpeg' -nostdin -v -1 -i '/tmp/magick-8802W6_GtpP7yVaH' -vframes 2147483647 -vcodec pam -an -f rawvideo -y '/tmp/magick-8802l3NLfb57smfV.pam' 2> '/tmp/magick-8802l3NLfb57smfV'
> ffmpeg -nostdin -v -1 -i /tmp/magick-8802W6_GtpP7yVaH -vframes 2147483647 -vcodec pam -an -f rawvideo -y /tmp/magick-8802l3NLfb57smfV.pam

I saw this error in wp-content/debug.log:

[ Timber ] WP_Error Object
(
    [errors] => Array
        (
            [image_save_error] => Array
                (
                    [0] => delegate failed `'ffmpeg' -nostdin -v -1 -i '%M%%d.jpg' '%u.%m' 2> '%u'' @ error/delegate.c/InvokeDelegate/1949
                )

        )

    [error_data] => Array
        (
            [image_save_error] => .../some-file-150x150-c-default.mp4
        )

    [additional_data:protected] => Array
        (
        )

)

This is not something I would expect to happen.

@gchtr
Copy link
Member

gchtr commented May 3, 2021

Hey @therealgilles

Timmy should definitely not try to resize MP4 files. Did that happen when you tried to upload an MP4 file in the WordPress admin?

@therealgilles
Copy link
Author

@gchtr: Thanks for following up. It happened when I was trying to access WordPress media library in the backend. I added the following as a workaround:

add_filter(
	'timmy/resize/ignore',
	function ( $return, $attachment ) {
		if ( preg_match( '/video/', $attachment->post_mime_type ) ) {
			return true;
		}

		return $return;
	},
	10,
	2
);

@therealgilles
Copy link
Author

@gchtr: I did not find any code that would stop Timmy from trying to "resize" video files.

@gchtr
Copy link
Member

gchtr commented Jun 8, 2021

@therealgilles Do you have a video file I can use to test this? I’m assuming your video file is encoded in a special way.

If the timmy/resize/ignore filter prevents your error from happening, then that means that WordPress itself tries to create different image sizes from that video. The timmy/resize/ignore filter is called when WordPress calls the image_downsize filter, which should only act on image files, but not on videos.

If I have a video attachment and run image_downsize() on it, then I’m getting a different error.

image_downsize( $attachment->ID );

Results in:

[ Timber ] WP_Error Object
(
    [errors] => Array
        (
            [image_no_editor] => Array
                (
                    [0] => No editor could be selected.
                )

        )

    [error_data] => Array
        (
        )

    [additional_data:protected] => Array
        (
        )

)

@gchtr
Copy link
Member

gchtr commented Sep 22, 2021

Hey @therealgilles

I finally figured out the issue here. My existing checks in timmy/resize/ignore were really not sufficient enough, and Timmy indeed tried to resize video files. I added a fix in #45 that I will release soon.

In the meantime, I’m going to close this issue.

@gchtr gchtr closed this as completed Sep 22, 2021
@therealgilles
Copy link
Author

@gchtr, thank you so much for being persistent and figuring out what the issue was!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants