Revision ec072669

View differences:

libavformat/mov.c
1371 1371

  
1372 1372
static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1373 1373
{
1374
    int i;
1375
    int width;
1376
    int height;
1377
    int64_t disp_transform[2];
1378
    int display_matrix[3][2];
1374 1379
    AVStream *st = c->fc->streams[c->fc->nb_streams-1];
1375 1380
    int version = get_byte(pb);
1376 1381

  
......
1402 1407
    get_be16(pb); /* volume */
1403 1408
    get_be16(pb); /* reserved */
1404 1409

  
1405
    url_fskip(pb, 36); /* display matrix */
1406

  
1407
    /* those are fixed-point */
1408
    get_be32(pb); /* track width */
1409
    get_be32(pb); /* track height */
1410
    //read in the display matrix (outlined in ISO 14496-12, Section 6.2.2)
1411
    // they're kept in fixed point format through all calculations
1412
    // ignore u,v,z b/c we don't need the scale factor to calc aspect ratio
1413
    for (i = 0; i < 3; i++) {
1414
        display_matrix[i][0] = get_be32(pb);   // 16.16 fixed point
1415
        display_matrix[i][1] = get_be32(pb);   // 16.16 fixed point
1416
        get_be32(pb);           // 2.30 fixed point (not used)
1417
    }
1410 1418

  
1419
    width = get_be32(pb);       // 16.16 fixed point track width
1420
    height = get_be32(pb);      // 16.16 fixed point track height
1421

  
1422
    //transform the display width/height according to the matrix
1423
    // skip this if the display matrix is the default identity matrix
1424
    // to keep the same scale, use [width height 1<<16]
1425
    if (width && height &&
1426
        (display_matrix[0][0] != 65536 || display_matrix[0][1]           ||
1427
        display_matrix[1][0]           || display_matrix[1][1] != 65536  ||
1428
        display_matrix[2][0]           || display_matrix[2][1])) {
1429
        for (i = 0; i < 2; i++)
1430
            disp_transform[i] =
1431
                (int64_t)  width  * display_matrix[0][i] +
1432
                (int64_t)  height * display_matrix[1][i] +
1433
                ((int64_t) display_matrix[2][i] << 16);
1434

  
1435
        //sample aspect ratio is new width/height divided by old width/height
1436
        st->codec->sample_aspect_ratio = av_d2q(
1437
            ((double) disp_transform[0] * height) /
1438
            ((double) disp_transform[1] * width), INT_MAX);
1439
    }
1411 1440
    return 0;
1412 1441
}
1413 1442

  

Also available in: Unified diff