protonemedia / laravel-ffmpeg

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.
https://protone.media/en/blog/how-to-use-ffmpeg-in-your-laravel-projects
MIT License
1.63k stars 194 forks source link

Some videos on the iPhone are reversed horizontally and vertically. #390

Closed madstone-dev closed 2 years ago

madstone-dev commented 2 years ago

Hello 🙂 I am trying to upload a video through this package. But some iPhone videos are uploaded at a 90 degree angle. These videos get reversed direction with getDimensions

$media = FFMpeg::fromDisk('public')
->open($localVideoPath);

$dimensions = $media
->getVideoStream()
->getDimensions();

// Some videos on the iPhone are reversed horizontally and vertically.

How do I rotate the image in the correct orientation?

pascalbaljet commented 2 years ago

There's a rotate filter in the underlying package: https://github.com/PHP-FFMpeg/PHP-FFMpeg#rotate

madstone-dev commented 2 years ago

There's a rotate filter in the underlying package: https://github.com/PHP-FFMpeg/PHP-FFMpeg#rotate

I know a rotate filter exists. But, I don't know how much the video is rotated beforehand.

How do I know how much the video is rotated?

nam-co commented 1 year ago

Hi @madstone-dev I was wondering how did you resolve this?

in my case the video came fine when uploaded, but: $size = $video->getVideoStream()->getDimensions();

provided inverted the $size->getWidth() and $size->getHeight() values Also iPhone video

madstone-dev commented 1 year ago

Hi @nam-co I left an issue here, but couldn't solve it in the end.

nam-co commented 1 year ago

Hi @madstone-dev I figure out a hack to try to fix it, if the rotation exists, I invert width and height

        //CALCULARE RATIO AND SIZE
        $data = FFMpeg::open($file)->getVideoStream()->all();
        $rotation = $data['side_data_list'][0]['rotation'] ?? null;
        if(!empty($rotation) AND $rotation != 0 AND $rotation != 270){
            $widthTemp = $data['width']; $width = $data['height']; $height = $widthTemp;
        }