Ticket #7045: new_mov_pixeldensity.patch

File new_mov_pixeldensity.patch, 4.9 KB (added by broly, 2 years ago)

updated patch

  • libavformat/movenc.c

    diff --git a/libavformat/movenc.c b/libavformat/movenc.c
    index a961390..c5eb12d 100644
    a b  
    7878    { "delay_moov", "Delay writing the initial moov until the first fragment is cut, or until the first fragment flush", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_DELAY_MOOV}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
    7979    { "global_sidx", "Write a global sidx index at the start of the file", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_GLOBAL_SIDX}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
    8080    { "skip_sidx", "Skip writing of sidx atom", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SKIP_SIDX}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     81    { "write_pixeldensity", "Write pixeldensity metdata for HiDPI videos in QT", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_PIXELDENSITY}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
    8182    { "write_colr", "Write colr atom even if the color info is unspecified (Experimental, may be renamed or changed, do not use from scripts)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_WRITE_COLR}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
    8283    { "prefer_icc", "If writing colr atom prioritise usage of ICC profile if it exists in stream packet side data", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_PREFER_ICC}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
    8384    { "write_gama", "Write deprecated gama atom", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_WRITE_GAMA}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
     
    34133414    return size;
    34143415}
    34153416
     3417static int mov_write_pixeldensity_meta_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track, AVFormatContext *s)
     3418{
     3419    int size = 0;
     3420    int64_t pos = avio_tell(pb);
     3421    avio_wb32(pb, 0); /* meta atom size */
     3422    ffio_wfourcc(pb, "meta");
     3423
     3424    /* Metadata atom information as described in
     3425     * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW9
     3426     */
     3427    avio_wb32(pb, 33); /* hdlr atom size: size (4) + 'hdlr' (4) + version/flags (4) + predefined (4) + 'mdta' (4) +
     3428                          reserved (3*4) + name (1) = 33 */
     3429    ffio_wfourcc(pb, "hdlr");
     3430    avio_wb32(pb, 0); /* version (1 Byte) and flags (3 Bytes), must be zero */
     3431    avio_wb32(pb, 0); /* "predefined", must be zero */
     3432    ffio_wfourcc(pb, "mdta");
     3433    avio_wb32(pb, 0); /* Reseverved, uint32_t[3] */
     3434    avio_wb32(pb, 0);
     3435    avio_wb32(pb, 0);
     3436    avio_w8(pb, 0); /* Empty name (NULL-terminated) */
     3437
     3438    avio_wb32(pb, 56); /* keys atom size: size (4) + 'keys' (4) + version/flasgs (4) + entry_count (4) +
     3439                          keys (32+8) = 56 */
     3440    ffio_wfourcc(pb, "keys");
     3441    avio_wb32(pb, 0);      /* version (1 Byte) and flags (3 Bytes), must be zero */
     3442    avio_wb32(pb, 1);      /* entry count */
     3443    avio_wb32(pb, 32 + 8); /* key size: size (4) + 'mdta' (4) + strlen(key) */
     3444    ffio_wfourcc(pb, "mdta");
     3445    avio_write(pb, "com.apple.quicktime.pixeldensity", 32);
     3446
     3447    avio_wb32(pb, 48); /* ilst atom size: size (4) + 'ilst' (4) + value atom size (40) = 48 */
     3448    ffio_wfourcc(pb, "ilst");
     3449    avio_wb32(pb, 40); /* value atom size: size (4) + key (4) + data atom (32) = 40 */
     3450    avio_wb32(pb, 1);  /* metadata key index */
     3451
     3452    avio_wb32(pb, 32); /* data atom size: size (4) + 'data' (4) + data_type (4) + locale (4) + value (4 * 4) = 32 */
     3453    ffio_wfourcc(pb, "data");
     3454    avio_wb32(pb, 0x1e); /* data type */
     3455    avio_wb32(pb, 0);    /* locale */
     3456
     3457    /* actual data (value): consisting of 4 uint32_t: pixel width, pixel height, display width, display height */
     3458    avio_wb32(pb, track->par->width);
     3459    avio_wb32(pb, track->par->height);
     3460    avio_wb32(pb, track->par->width / 2);
     3461    avio_wb32(pb, track->par->height / 2);
     3462
     3463    size = update_size(pb, pos);
     3464    return size;
     3465}
     3466
    34163467static int mov_write_trak_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov,
    34173468                              MOVTrack *track, AVStream *st)
    34183469{
    static int mov_write_trak_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext  
    34603511            mov_write_tapt_tag(pb, track);
    34613512        }
    34623513    }
     3514    if (mov->flags & FF_MOV_FLAG_PIXELDENSITY) {
     3515         mov_write_pixeldensity_meta_tag(pb, mov, track, st);
     3516    }
    34633517    mov_write_track_udta_tag(pb, mov, st);
    34643518    track->entry = entry_backup;
    34653519    track->chunkCount = chunk_backup;
  • libavformat/movenc.h

    diff --git a/libavformat/movenc.h b/libavformat/movenc.h
    index 68d6f23..ed7ea41 100644
    a b typedef struct MOVMuxContext {  
    265265#define FF_MOV_FLAG_SKIP_SIDX             (1 << 21)
    266266#define FF_MOV_FLAG_CMAF                  (1 << 22)
    267267#define FF_MOV_FLAG_PREFER_ICC            (1 << 23)
     268#define FF_MOV_FLAG_PIXELDENSITY          (1 << 24)
    268269
    269270int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
    270271