Ticket #7045: mov_pixeldensity.patch

File mov_pixeldensity.patch, 4.8 KB (added by Daniel Kaiser, 5 years ago)
  • movenc.c

    diff --git a/movenc.c b/movenc.c
    index a961390..c5eb12d 100644
    a b static const AVOption options[] = {  
    7676    { "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" },
    7777    { "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" },
    7878    { "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" },
     79    { "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" },
    7980    { "write_colr", "Write colr atom (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" },
    8081    { "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" },
    8182    { "use_metadata_tags", "Use mdta atom for metadata.", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_USE_MDTA}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
    static int mov_write_track_udta_tag(AVIOContext *pb, MOVMuxContext *mov,  
    31183119    return 0;
    31193120}
    31203121
     3122static int mov_write_pixeldensity_meta_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track, AVFormatContext *s)
     3123{
     3124    int size = 0;
     3125    int64_t pos = avio_tell(pb);
     3126    avio_wb32(pb, 0); /* meta atom size */
     3127    ffio_wfourcc(pb, "meta");
     3128
     3129    /* Metadata atom information as described in
     3130     * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW9
     3131     */
     3132    avio_wb32(pb, 33); /* hdlr atom size: size (4) + 'hdlr' (4) + version/flags (4) + predefined (4) + 'mdta' (4) +
     3133                          reserved (3*4) + name (1) = 33 */
     3134    ffio_wfourcc(pb, "hdlr");
     3135    avio_wb32(pb, 0); /* version (1 Byte) and flags (3 Bytes), must be zero */
     3136    avio_wb32(pb, 0); /* "predefined", must be zero */
     3137    ffio_wfourcc(pb, "mdta");
     3138    avio_wb32(pb, 0); /* Reseverved, uint32_t[3] */
     3139    avio_wb32(pb, 0);
     3140    avio_wb32(pb, 0);
     3141    avio_w8(pb, 0); /* Empty name (NULL-terminated) */
     3142
     3143    avio_wb32(pb, 56); /* keys atom size: size (4) + 'keys' (4) + version/flasgs (4) + entry_count (4) +
     3144                          keys (32+8) = 56 */
     3145    ffio_wfourcc(pb, "keys");
     3146    avio_wb32(pb, 0);      /* version (1 Byte) and flags (3 Bytes), must be zero */
     3147    avio_wb32(pb, 1);      /* entry count */
     3148    avio_wb32(pb, 32 + 8); /* key size: size (4) + 'mdta' (4) + strlen(key) */
     3149    ffio_wfourcc(pb, "mdta");
     3150    avio_write(pb, "com.apple.quicktime.pixeldensity", 32);
     3151
     3152    avio_wb32(pb, 48); /* ilst atom size: size (4) + 'ilst' (4) + value atom size (40) = 48 */
     3153    ffio_wfourcc(pb, "ilst");
     3154    avio_wb32(pb, 40); /* value atom size: size (4) + key (4) + data atom (32) = 40 */
     3155    avio_wb32(pb, 1);  /* metadata key index */
     3156
     3157    avio_wb32(pb, 32); /* data atom size: size (4) + 'data' (4) + data_type (4) + locale (4) + value (4 * 4) = 32 */
     3158    ffio_wfourcc(pb, "data");
     3159    avio_wb32(pb, 0x1e); /* data type */
     3160    avio_wb32(pb, 0);    /* locale */
     3161
     3162    /* actual data (value): consisting of 4 uint32_t: pixel width, pixel height, display width, display height */
     3163    avio_wb32(pb, track->par->width);
     3164    avio_wb32(pb, track->par->height);
     3165    avio_wb32(pb, track->par->width / 2);
     3166    avio_wb32(pb, track->par->height / 2);
     3167
     3168    size = update_size(pb, pos);
     3169    return size;
     3170}
     3171
    31213172static int mov_write_trak_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov,
    31223173                              MOVTrack *track, AVStream *st)
    31233174{
    static int mov_write_trak_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext  
    31653216            mov_write_tapt_tag(pb, track);
    31663217        }
    31673218    }
     3219    if (mov->flags & FF_MOV_FLAG_PIXELDENSITY) {
     3220         mov_write_pixeldensity_meta_tag(pb, mov, track, st);
     3221    }
    31683222    mov_write_track_udta_tag(pb, mov, st);
    31693223    track->entry = entry_backup;
    31703224    track->chunkCount = chunk_backup;
  • movenc.h

    diff --git a/movenc.h b/movenc.h
    index 68d6f23..ed7ea41 100644
    a b typedef struct MOVMuxContext {  
    258258#define FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS  (1 << 19)
    259259#define FF_MOV_FLAG_FRAG_EVERY_FRAME      (1 << 20)
    260260#define FF_MOV_FLAG_SKIP_SIDX             (1 << 21)
     261#define FF_MOV_FLAG_PIXELDENSITY          (1 << 22)
    261262
    262263int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
    263264