-
Notifications
You must be signed in to change notification settings - Fork 5
/
ffmpeg
127 lines (121 loc) · 5.72 KB
/
ffmpeg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
depends_on pkg-config ## otherwise can't find x265
depends_on nasm
depends_on x264
depends_on x265
depends_on libfdk-aac
depends_on libsdl2 ## needed for ffplay to work
[[ $OSTYPE == *linux* ]] && depends_on libasound ## for sound output on linux
depends_on libopus
depends_on libvpx
depends_on libsvtav1
depends_on libxml ## for dash
[[ $OSTYPE != *darwin* ]] && depends_on zlib ## osx provides the library
depends_on libsrt ## for srt subtitles
fetch_source https://ffmpeg.org/releases/ffmpeg-7.1.tar.xz 299e7790544f380d0472b406c9b5ce82efeb8f48
CONFFLAGS=(
--enable-gpl ## needed to use x264 and x265
--enable-nonfree ## needed to use libfdk-aac
--enable-libx264
--enable-libx265
--enable-libfdk-aac ## highest quality AAC encoder available in ffmpeg
--enable-sdl2 ## needed for ffplay
--enable-ffplay ## useful also for analyzing streams
--enable-shared ## reduces binary size to manageable levels
--enable-libopus
--enable-libvpx
--enable-libsvtav1
--enable-libxml2
--enable-demuxer=dash
--disable-lzma ## opportunistic linking
)
do_unpack
do_patch_inline -p0 << EOF
diff -urw libavformat/movenc.c libavformat/movenc.c
--- libavformat/movenc.c
+++ libavformat/movenc.c
@@ -109,6 +109,7 @@
{ "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, .unit = "movflags" },
{ "skip_trailer", "Skip writing the mfra/tfra/mfro trailer for fragmented files", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SKIP_TRAILER}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, .unit = "movflags" },
{ "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, .unit = "movflags" },
+ { "write_pixeldensity", "Write pixel density metdata for retina videos", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_PIXELDENSITY}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
{ "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, .unit = "movflags" },
{ "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, .unit = "movflags" },
{ "min_frag_duration", "Minimum fragment duration", offsetof(MOVMuxContext, min_fragment_duration), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
@@ -3853,6 +3854,56 @@
return 0;
}
+static int mov_write_pixeldensity_meta_tag(AVIOContext *pb, MOVMuxContext *mov, MOVTrack *track, AVFormatContext *s)
+{
+ int size = 0;
+ int64_t pos = avio_tell(pb);
+ avio_wb32(pb, 0); /* meta atom size */
+ ffio_wfourcc(pb, "meta");
+
+ /* Metadata atom information as described in
+ * https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW9
+ */
+ avio_wb32(pb, 33); /* hdlr atom size: size (4) + 'hdlr' (4) + version/flags (4) + predefined (4) + 'mdta' (4) +
+ reserved (3*4) + name (1) = 33 */
+ ffio_wfourcc(pb, "hdlr");
+ avio_wb32(pb, 0); /* version (1 Byte) and flags (3 Bytes), must be zero */
+ avio_wb32(pb, 0); /* "predefined", must be zero */
+ ffio_wfourcc(pb, "mdta");
+ avio_wb32(pb, 0); /* Reseverved, uint32_t[3] */
+ avio_wb32(pb, 0);
+ avio_wb32(pb, 0);
+ avio_w8(pb, 0); /* Empty name (NULL-terminated) */
+
+ avio_wb32(pb, 56); /* keys atom size: size (4) + 'keys' (4) + version/flasgs (4) + entry_count (4) +
+ keys (32+8) = 56 */
+ ffio_wfourcc(pb, "keys");
+ avio_wb32(pb, 0); /* version (1 Byte) and flags (3 Bytes), must be zero */
+ avio_wb32(pb, 1); /* entry count */
+ avio_wb32(pb, 32 + 8); /* key size: size (4) + 'mdta' (4) + strlen(key) */
+ ffio_wfourcc(pb, "mdta");
+ avio_write(pb, "com.apple.quicktime.pixeldensity", 32);
+
+ avio_wb32(pb, 48); /* ilst atom size: size (4) + 'ilst' (4) + value atom size (40) = 48 */
+ ffio_wfourcc(pb, "ilst");
+ avio_wb32(pb, 40); /* value atom size: size (4) + key (4) + data atom (32) = 40 */
+ avio_wb32(pb, 1); /* metadata key index */
+
+ avio_wb32(pb, 32); /* data atom size: size (4) + 'data' (4) + data_type (4) + locale (4) + value (4 * 4) = 32 */
+ ffio_wfourcc(pb, "data");
+ avio_wb32(pb, 0x1e); /* data type */
+ avio_wb32(pb, 0); /* locale */
+
+ /* actual data (value): consisting of 4 uint32_t: pixel width, pixel height, display width, display height */
+ avio_wb32(pb, track->par->width);
+ avio_wb32(pb, track->par->height);
+ avio_wb32(pb, track->par->width / 2);
+ avio_wb32(pb, track->par->height / 2);
+
+ size = update_size(pb, pos);
+ return size;
+}
+
static int mov_write_trak_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContext *mov,
MOVTrack *track, AVStream *st)
{
@@ -3397,6 +3448,9 @@
mov_write_tapt_tag(pb, track);
}
}
+ if (mov->flags & FF_MOV_FLAG_PIXELDENSITY) {
+ mov_write_pixeldensity_meta_tag(pb, mov, track, st);
+ }
mov_write_track_udta_tag(pb, mov, st);
track->entry = entry_backup;
track->chunkCount = chunk_backup;
diff -urw libavformat/movenc.h libavformat/movenc.h
--- libavformat/movenc.h
+++ libavformat/movenc.h
@@ -263,6 +263,7 @@
#define FF_MOV_FLAG_CMAF (1 << 22)
#define FF_MOV_FLAG_PREFER_ICC (1 << 23)
#define FF_MOV_FLAG_HYBRID_FRAGMENTED (1 << 24)
+#define FF_MOV_FLAG_PIXELDENSITY (1 << 25)
int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt);
EOF
do_compile "${CONFFLAGS[@]}"