static int init_dimensions(H264Context *h)
{
    SPS *sps = h->ps.sps;
    int width  = h->width  - (sps->crop_right + sps->crop_left);
    int height = h->height - (sps->crop_top   + sps->crop_bottom);

    /* handle container cropping */
    if (h->width_from_caller > 0 && h->height_from_caller > 0     &&
        !sps->crop_top && !sps->crop_left                         &&
        FFALIGN(h->width_from_caller,  16) == FFALIGN(width,  16) &&
        FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16)) {
        width  = h->width_from_caller;
        height = h->height_from_caller;
    } else {
        h->width_from_caller  = 0;
        h->height_from_caller = 0;
    }

    h->avctx->coded_width  = h->width;
    h->avctx->coded_height = h->height;
    h->avctx->width        = width;
    h->avctx->height       = height;

    return 0;
}