[FFmpeg-user] Raspberrypi h264_omx encoder pixel aspect ratio

Simon Hyland snhyland at gmail.com
Mon Jun 13 22:43:55 CEST 2016

First post, please forgive me if I appear clueless.

Transcoding on a Pi3 from MPEG2 TS to h264 MP4 using the GPU encoder,
results are generally great and very fast, well done devs this is much

The input is 720x576 broadcast stream with SAR 64:45 and DAR 16:9 which
displays nicely on a 16:9 TV.

No matter which aspect options I try (aspect, sar,dar) the output is always
stretched vertically. The only way I can regain a 16:9 aspect is by using
-vf scale=720:404.
This looks good but obviously picture quality suffers due to the cropping.

If I use the software libx264 encoder this problem goes away as this
encoder appears to respect SAR pixel aspect settings.

The h264_omx encoder seems to be fixed at 1:1 pixel aspect ratio, the
display aspect controlled by lines and columns only.

I had a quick look through the source, and In the src for the omx encoder
(at FFmpeg/libavcodec/omx.c) the encoder params seem to be set here:

 err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition,
    out_port_params.bEnabled   = OMX_TRUE;
    out_port_params.bPopulated = OMX_FALSE;
    out_port_params.eDomain    = OMX_PortDomainVideo;
    out_port_params.format.video.pNativeRender = NULL;
    out_port_params.format.video.nFrameWidth   = avctx->width;
    out_port_params.format.video.nFrameHeight  = avctx->height;
    out_port_params.format.video.nStride       = 0;
    out_port_params.format.video.nSliceHeight  = 0;
    out_port_params.format.video.nBitrate      = avctx->bit_rate;
    out_port_params.format.video.xFramerate    =
    out_port_params.format.video.bFlagErrorConcealment  = OMX_FALSE;
    if (avctx->codec->id == AV_CODEC_ID_MPEG4)
        out_port_params.format.video.eCompressionFormat =
    else if (avctx->codec->id == AV_CODEC_ID_H264)
        out_port_params.format.video.eCompressionFormat =

    err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition,

with no code for setting pixel ratio is apparent.

By including code here to set the outport parameter for pixel aspect ratio,
maybe by using something along the lines of

       set pixel aspect ratio to a valid OMX_IndexParamBrcmPixelAspectRatio
value of 16:11 ( value from cmd line)

it may be possible to implement the pixel aspect ratio feature?

If it was I'd be eternally grateful!

Best regards, thanks for the hard work,
Simon Hyland

More information about the ffmpeg-user mailing list