WordPress.org

Make WordPress Core

Opened 2 months ago

Last modified 2 months ago

#53944 new defect (bug)

Video resolution in portrait orientation

Reported by: mazursv Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8
Component: Media Keywords: has-patch
Focuses: Cc:

Description

Hi!

I uploaded mp4 video file having portrait orientation and found that attachment metadata contains swapped width and height parameters. I see that WP is using getID3 library to read video metadata and found that it can detect when video is rotated.

I used following filter to fix that:

<?php

add_filter('wp_read_video_metadata', [$this, 'wp_read_video_metadata'], 20, 4);
...
public function wp_read_video_metadata( $metadata, $file, $file_format, $id3_data ) {
                if( !empty( $id3_data['video']['rotate'] ) ) {
                        if( $id3_data['video']['rotate'] === 90 || $id3_data['video']['rotate'] === 270 ) {
                                $metadata['width'] = $id3_data['video']['resolution_y'];
                                $metadata['height'] = $id3_data['video']['resolution_x'];
                        }
                }

                return $metadata;
        }

Change History (2)

#1 @mazursv
2 months ago

  • Component changed from General to Media

This ticket was mentioned in PR #1597 on WordPress/wordpress-develop by costdev.


2 months ago

  • Keywords has-patch added

Check if the video has been rotated 90/270 degrees and if so, swap the width and height values.

Trac ticket: https://core.trac.wordpress.org/ticket/53944

Note: See TracTickets for help on using tickets.