Portrait videos are stretching
shankar-bavan opened this issue ยท 5 comments
When I encode mobile portrait video to hls, it got stretch. how to encode without stretching?
This issue only for video recorded from iphone
$video->hls()
->encryption($save_to, $url, 1)
->setFormat($format)
->setHlsTime(5)
->setHlsAllowCache(false)
->autoGenerateRepresentations()
->save($save_path);
Has anyone found solution to this issue?
@aminyazdanpanah any solution for this ?
It seems like the FFmpeg library has an issue with the 'h264 apple encoder'. I will try to reach out to FFmpeg developers and report this bug.
I will be keeping this issue until I(or anyone else) find a solution.
We had such a problem. It is necessary to take into account the aspect ratio when setting the dimensions.
By default you load 1080 by 1920 video for example. And FFMPEG takes and renders 1920 and 1080 and produces a stretched video image.
If the video is 1080 by 1920, then we take the closest available resize - this is 720p.
And set the parameters to resize 1280 x 720.
In general, you need to understand which video comes in and calculate the aspect ratio for each video and there will be no problem
I suspect the cause could be that rotation is not handled by autoGenerateRepresentations()
.
Example input file in portrait format, from an iPhone:
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default)
Metadata:
creation_time : 2023-09-29T12:27:45.000000Z
handler_name : Core Media Audio
vendor_id : [0][0][0][0]
Stream #0:1(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 568x320, 705 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc (default)
Metadata:
rotate : 90
creation_time : 2023-09-29T12:27:45.000000Z
handler_name : Core Media Video
vendor_id : [0][0][0][0]
Side data:
displaymatrix: rotation of -90.00 degrees ๐ This indicates rotation
ffprobe
indicates a resolution of 568x320 (landscape), but due to 90ยฐ rotation the video is actually 320x568 (portrait).