androidiosvideoaws-media-convertaws-elastictranscoder

Video Rotation issue when Stitching wide video (e.g. 6:4) with vertical video recorded with a mobile phone (e.g any Android/iPhone 9:16)


When a vertical video is recorded via mobile phone and needs to be stitched with a horizontal video, the provided output has the vertical video part, rotated.

What may cause it:

  1. It seems the limitation of the elastic transcoder for ignoring the rotation param encoded in the header of the mp4 file by the mobile phone. (I have assumed it after analyzing several videos by using FFprobe utility which comes along FFmpeg)
  2. I have also noticed that if I use AWS console (Web UI) to perform an mp4 to mp4 conversion to standardize the mp4 file header it went fine but when I do the same thing with the code the AWS applied rotation=0 instead of my provided value i.e rotation=auto. If I can pass rotation=auto correctly from the code, I believe the whole problem will get solved. If someone can guide me on how to pass the rotation parameter correctly then it will be a great help. Here is code snippet which I am using:
 $transcoderService = app('ITranscoderService');

        $inputs = [ 
            [
                'Key' => $this->media->getOriginal('media_url'),
            ]
         ];
        $this->prepend && array_unshift($inputs, ['Key' => $this->prepend]);
        $this->append && array_push($inputs, ['Key' => $this->append]);

        $outputs = [
                [
                    "Key" => $this->getOutputFilename(),
                    'Rotate' => 'auto',
                    "PresetId" =>  '1653583660869-5jx367',//'1653583311105-8tip2c'//'1351620000001-000020',//$this->presetId
                ],
        ];

        $transcoderJob = $transcoderService->createJob([
            'PipelineId' => config('aws.elastic_transcoder.pipeline_id'),
            'Inputs' => $inputs,
            'OutputKeyPrefix' => $this->getFileDirectory() ,
            'Outputs' => $outputs,
        ]);

Solution

  • I did found the solution after a bit of struggle with AWS Documentation. They didn't pointed that I must have to pass all input parameters even if I want default values (i.e auto), as I asume that word auto or default should automatically considered true when value is not provided. (DATED: 20 OCT 2022).

    Solution:

    In addition to each input we have to explicitly tell AWS Elastic Transcoder that we want to use 'auto' value for FrameRate, Resolution, AspectRatio, Interlaced and Container, so that it uses these parameters from given file's meta. i.e in my case it:

    $inputs = [ 
                [
                 'Key' => $this->media->getOriginal('media_url'),
                 'FrameRate' => 'auto',
                 'Resolution' => 'auto',
                 'AspectRatio' => 'auto',
                 'Interlaced' => 'auto',
                 'Container' => 'auto'
                ]
             ];