forked from datarhei/ffmpeg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0031-pass-dovi-sidedata-to-hlsenc-and-mpegtsenc.patch
137 lines (134 loc) · 5.87 KB
/
0031-pass-dovi-sidedata-to-hlsenc-and-mpegtsenc.patch
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
128
129
130
131
132
133
134
135
136
137
Index: FFmpeg/libavformat/hlsenc.c
===================================================================
--- FFmpeg.orig/libavformat/hlsenc.c
+++ FFmpeg/libavformat/hlsenc.c
@@ -850,7 +850,7 @@ static int hls_mux_init(AVFormatContext
AVFormatContext *vtt_oc = NULL;
int byterange_mode = (hls->flags & HLS_SINGLE_FILE) || (hls->max_seg_size > 0);
int remaining_options;
- int i, ret;
+ int i, j, ret;
ret = avformat_alloc_output_context2(&vs->avf, vs->oformat, NULL, NULL);
if (ret < 0)
@@ -896,6 +896,20 @@ static int hls_mux_init(AVFormatContext
st->codecpar->codec_tag = 0;
}
+ // copy side data
+ for (j = 0; j < vs->streams[i]->codecpar->nb_coded_side_data; j++) {
+ const AVPacketSideData *sd_src = &vs->streams[i]->codecpar->coded_side_data[j];
+ AVPacketSideData *sd_dst;
+
+ sd_dst = av_packet_side_data_new(&st->codecpar->coded_side_data,
+ &st->codecpar->nb_coded_side_data,
+ sd_src->type, sd_src->size, 0);
+ if (!sd_dst)
+ return AVERROR(ENOMEM);
+
+ memcpy(sd_dst->data, sd_src->data, sd_src->size);
+ }
+
st->sample_aspect_ratio = vs->streams[i]->sample_aspect_ratio;
st->time_base = vs->streams[i]->time_base;
av_dict_copy(&st->metadata, vs->streams[i]->metadata, 0);
Index: FFmpeg/libavformat/movenc.c
===================================================================
--- FFmpeg.orig/libavformat/movenc.c
+++ FFmpeg/libavformat/movenc.c
@@ -8124,6 +8124,7 @@ static const AVCodecTag codec_mp4_tags[]
{ AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1') },
{ AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1') },
{ AV_CODEC_ID_HEVC, MKTAG('d', 'v', 'h', '1') },
+ { AV_CODEC_ID_HEVC, MKTAG('d', 'v', 'h', 'e') },
{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'c', '1') },
{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'i', '1') },
{ AV_CODEC_ID_EVC, MKTAG('e', 'v', 'c', '1') },
@@ -8137,6 +8138,7 @@ static const AVCodecTag codec_mp4_tags[]
{ AV_CODEC_ID_TSCC2, MKTAG('m', 'p', '4', 'v') },
{ AV_CODEC_ID_VP9, MKTAG('v', 'p', '0', '9') },
{ AV_CODEC_ID_AV1, MKTAG('a', 'v', '0', '1') },
+ { AV_CODEC_ID_AV1, MKTAG('d', 'a', 'v', '1') },
{ AV_CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') },
{ AV_CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') },
{ AV_CODEC_ID_MP4ALS, MKTAG('m', 'p', '4', 'a') },
Index: FFmpeg/libavformat/mpegtsenc.c
===================================================================
--- FFmpeg.orig/libavformat/mpegtsenc.c
+++ FFmpeg/libavformat/mpegtsenc.c
@@ -23,6 +23,7 @@
#include "libavutil/bswap.h"
#include "libavutil/crc.h"
#include "libavutil/dict.h"
+#include "libavutil/dovi_meta.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
@@ -350,6 +351,52 @@ static void put_registration_descriptor(
*q_ptr = q;
}
+static int put_dovi_descriptor(AVFormatContext *s, uint8_t **q_ptr,
+ const AVDOVIDecoderConfigurationRecord *dovi)
+{
+ uint16_t val16;
+ uint8_t *q = *q_ptr;
+
+ if (!dovi)
+ return AVERROR(ENOMEM);
+
+ if (!dovi->bl_present_flag) {
+ av_log(s, AV_LOG_ERROR,
+ "EL only DOVI stream is not supported!\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ put_registration_descriptor(&q, MKTAG('D', 'O', 'V', 'I')); // format_identifier
+
+ /* DOVI Video Stream Descriptor Syntax */
+ *q++ = 0xb0; // descriptor_tag
+ *q++ = 0x05; // descriptor_length
+ *q++ = dovi->dv_version_major;
+ *q++ = dovi->dv_version_minor;
+
+ val16 = (dovi->dv_profile & 0x7f) << 9 | // 7 bits
+ (dovi->dv_level & 0x3f) << 3 | // 6 bits
+ (dovi->rpu_present_flag & 0x01) << 2 | // 1 bits
+ (dovi->el_present_flag & 0x01) << 1 | // 1 bits
+ (dovi->bl_present_flag & 0x01); // 1 bits
+ put16(&q, val16);
+
+#if 0
+ // TODO: support dependency_pid (EL only stream)
+ // descriptor_length: 0x05->0x07
+ if (!bl_present_flag) {
+ val16 = (dependency_pid & 0x1fff) << 3; // 13+3 bits
+ put16(&q, val16);
+ }
+#endif
+
+ *q++ = (dovi->dv_bl_signal_compatibility_id & 0x0f) << 4; // 4+4 bits
+
+ *q_ptr = q;
+
+ return 0;
+}
+
static int get_dvb_stream_type(AVFormatContext *s, AVStream *st)
{
MpegTSWrite *ts = s->priv_data;
@@ -803,7 +850,16 @@ static int mpegts_write_pmt(AVFormatCont
} else if (stream_type == STREAM_TYPE_VIDEO_VC1) {
put_registration_descriptor(&q, MKTAG('V', 'C', '-', '1'));
} else if (stream_type == STREAM_TYPE_VIDEO_HEVC && s->strict_std_compliance <= FF_COMPLIANCE_NORMAL) {
- put_registration_descriptor(&q, MKTAG('H', 'E', 'V', 'C'));
+ const AVPacketSideData *sd = av_packet_side_data_get(st->codecpar->coded_side_data,
+ st->codecpar->nb_coded_side_data, AV_PKT_DATA_DOVI_CONF);
+ const AVDOVIDecoderConfigurationRecord *dovi = sd ? (const AVDOVIDecoderConfigurationRecord *)sd->data : NULL;
+
+ if (dovi && dovi->bl_present_flag && s->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
+ if (put_dovi_descriptor(s, &q, dovi) < 0)
+ break;
+ } else {
+ put_registration_descriptor(&q, MKTAG('H', 'E', 'V', 'C'));
+ }
} else if (stream_type == STREAM_TYPE_VIDEO_CAVS || stream_type == STREAM_TYPE_VIDEO_AVS2 ||
stream_type == STREAM_TYPE_VIDEO_AVS3) {
put_registration_descriptor(&q, MKTAG('A', 'V', 'S', 'V'));