Search code examples
asp.net-web-apivideoazure-blob-storageazure-media-services

Windows Azure Media Encoding - incorrect... errors during the encode process.. value must be an even number between 64 and 1280 and a multiple of 4


We've been investigation an issue whereby portrait iOS videos fail to encode by Azure Media Encoding services. Is there some workaround?

The error occurs where a video is 720 wide and 1280 high, without any rotation meta data.

Windows Azure Media Encoder ran into errors during the encode process on source Invalid Width specified. The value must be an even number between 64 and 1280 and a multiple of 4.

Similar videos which are 1280 wide and 720 high with rotation 90 degrees meta data, are encoded without a problem.

We've tried different xml preset values believing that video aren't being handled correctly.

<Presets Rotation="Auto">
<Preset
  Version="5.0">

Having looked at the source of these videos, we have determined that these are mp4 videos produced from Snapchat, with some effect added to them. Videos without effects seem fine. Therefore Snapchat is corrupting them in some way.

We believe that the error provided above is therefore false and that the actual error, some other problem with the video, is being caught by this dimension error handler.

It would be nice to provide users with a useful error. Actually saying the dimensions are incorrect it's useful as other videos with this dimension are fine.


Solution

  • First and foremost, you are using a deprecated media processor, "Windows Azure Media Encoder" (explains the incorrect error message). This component will be removed from production deployments before the end of the calendar year.

    Please update your code to use "Media Encoder Standard" - see this page and related documentation.

    Secondly, if the input MP4 does not contain rotation metadata, do you know which videos were captured in portrait mode and which ones were captured in landscape mode? The instructions below will help with MP4s where you know for sure they are in portrait mode - the same encoder settings will produce unexpected results if the video is in landscape mode.

    Forcing Rotation in Media Encoder Standard Below is a modified JSON preset that will force the encoder to apply a 90 degree rotation to the input video, and produce two layers one at 720x1280, and another at 360x640. You can edit it to add other layers, of course. Note the use of two custom settings, "Rotation" and "StretchMode". You can save the JSON to a local file and use the instructions here to submit an encoding Task. Alternatively, you can download and use http://aka.ms/amse on a PC.

    {  
      "Version": 1.0,
      "Sources": [
        {
          "Streams": [],
          "Filters": {
             "Rotation": "90"
          }
        }
       ], 
      "Codecs": [  
       {  
        "KeyFrameInterval": "00:00:02", 
        "StretchMode" : "None",
        "H264Layers": [
          {  
            "Profile": "Auto",  
            "Level": "auto",  
            "Bitrate": 3400,  
            "MaxBitrate": 3400,  
            "BufferWindow": "00:00:05",  
            "Width": 720,  
            "Height": 1280,  
            "BFrames": 3,  
            "ReferenceFrames": 3,  
            "AdaptiveBFrame": true,  
            "Type": "H264Layer",  
            "FrameRate": "0/1"  
          },  
          {  
            "Profile": "Auto",  
            "Level": "auto",  
            "Bitrate": 650,  
            "MaxBitrate": 650,  
            "BufferWindow": "00:00:05",  
            "Width": 360,  
            "Height": 640,  
            "BFrames": 3,  
            "ReferenceFrames": 3,  
            "AdaptiveBFrame": true,  
            "Type": "H264Layer",  
            "FrameRate": "0/1"  
          } 
        ],  
        "Type": "H264Video"  
      },  
      {  
        "Profile": "AACLC",  
        "Channels": 2,  
        "SamplingRate": 48000,  
        "Bitrate": 128,  
        "Type": "AACAudio"  
       }  
      ],  
      "Outputs": [  
        {  
          "FileName": "{Basename}_{Resolution}.mp4",  
          "Format": {  
            "Type": "MP4Format"  
          }  
        }  
      ]  
    }