1
- From 5a2b6b0c5c700a56ea37c62aaebb57ffe2ad8d1f Mon Sep 17 00:00:00 2001
1
+ From 4609c8356bfbb063a6111aac4c7fa090099aa05b Mon Sep 17 00:00:00 2001
2
2
From: Ingo Oppermann <
[email protected] >
3
- Date: Fri, 26 Jul 2024 16:59:08 +0200
4
- Subject: [PATCH v6] HLS extensions (ffmpeg 7 .0)
3
+ Date: Wed, 16 Oct 2024 14:47:06 +0200
4
+ Subject: [PATCH v1] hls (7.1 .0)
5
5
6
6
---
7
- README.HLS.md | 48 ++++++++++++++++++++++++
8
- libavformat/hlsenc.c | 87 +++++++++++++++++++++++++++++++++++++++++---
9
- 2 files changed, 130 insertions(+), 5 deletions(- )
7
+ README.HLS.md | 48 ++++++++++++++++++++++++++++++++++
8
+ libavformat/hlsenc.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
9
+ 2 files changed, 110 insertions(+)
10
10
create mode 100644 README.HLS.md
11
11
12
12
diff --git a/README.HLS.md b/README.HLS.md
@@ -64,18 +64,18 @@ index 00000000..5462338b
64
64
+
65
65
+ In the command, the `-var_stream_map` option had the value `v:0,a:0 v:1,a:1`.
66
66
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
67
- index 2202ce64..1660cace 100644
67
+ index 1e932b7b..7b76a227 100644
68
68
--- a/libavformat/hlsenc.c
69
69
+++ b/libavformat/hlsenc.c
70
- @@ -123 ,6 +123 ,7 @@ typedef struct VariantStream {
70
+ @@ -125 ,6 +125 ,7 @@ typedef struct VariantStream {
71
71
AVIOContext *out;
72
72
AVIOContext *out_single_file;
73
73
int packets_written;
74
74
+ uint64_t bytes_written;
75
75
int init_range_length;
76
76
uint8_t *temp_buffer;
77
77
uint8_t *init_buffer;
78
- @@ -137 ,6 +138 ,8 @@ typedef struct VariantStream {
78
+ @@ -139 ,6 +140 ,8 @@ typedef struct VariantStream {
79
79
double dpp; // duration per packet
80
80
int64_t start_pts;
81
81
int64_t end_pts;
@@ -84,56 +84,24 @@ index 2202ce64..1660cace 100644
84
84
int64_t video_lastpos;
85
85
int64_t video_keyframe_pos;
86
86
int64_t video_keyframe_size;
87
- @@ -1374,7 +1377,7 @@ static int create_master_playlist(AVFormatContext *s,
88
- AVStream *vid_st, *aud_st;
89
- AVDictionary *options = NULL;
90
- unsigned int i, j;
91
- - int ret, bandwidth;
92
- + int ret, bandwidth, st_bandwidth, est_bandwidth;
93
- const char *m3u8_rel_name = NULL;
94
- const char *vtt_m3u8_rel_name = NULL;
95
- const char *ccgroup;
96
- @@ -1486,10 +1489,35 @@ static int create_master_playlist(AVFormatContext *s,
97
- }
98
-
99
- bandwidth = 0;
100
- - if (vid_st)
101
- - bandwidth += get_stream_bit_rate(vid_st);
102
- - if (aud_st)
103
- - bandwidth += get_stream_bit_rate(aud_st);
104
- + est_bandwidth = 0;
105
- +
106
- + if (vid_st) {
107
- + st_bandwidth = get_stream_bit_rate(vid_st);
108
- + if (st_bandwidth == 0) {
109
- + est_bandwidth = 1;
110
- + } else {
111
- + bandwidth += st_bandwidth;
87
+ @@ -1507,6 +1510,16 @@ static int create_master_playlist(AVFormatContext *s,
88
+ bandwidth += get_stream_bit_rate(vid_st);
89
+ if (aud_st)
90
+ bandwidth += get_stream_bit_rate(aud_st);
91
+ +
92
+ + if (bandwidth == 0) {
93
+ + // Estimate bandwidth
94
+ + bandwidth = (int)round((double)vs->bytes_written / (av_q2d(AV_TIME_BASE_Q) * (vs->scaled_cur_pts - vs->scaled_start_pts)) * 8);
95
+ +
96
+ + // Reset counters
97
+ + vs->bytes_written = 0;
98
+ + vs->scaled_start_pts = vs->scaled_cur_pts;
112
99
+ }
113
- + }
114
- + if (aud_st) {
115
- + st_bandwidth = get_stream_bit_rate(aud_st);
116
- + if (st_bandwidth == 0) {
117
- + est_bandwidth = 1;
118
- + } else {
119
- + bandwidth += st_bandwidth;
120
- + }
121
- + }
122
100
+
123
- + if (est_bandwidth != 0) {
124
- + // Estimate bandwidth
125
- + bandwidth = (int)round((double)vs->bytes_written / (av_q2d(AV_TIME_BASE_Q) * (vs->scaled_cur_pts - vs->scaled_start_pts)) * 8);
126
- +
127
- + // Reset counters
128
- + vs->bytes_written = 0;
129
- + vs->scaled_start_pts = vs->scaled_cur_pts;
130
- + }
131
- +
132
- + // Add 10% of the bandwidth to itself
133
- bandwidth += bandwidth / 10;
101
+ bandwidth += bandwidth / 10;
102
+ }
134
103
135
- ccgroup = NULL;
136
- @@ -2461,6 +2489,19 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
104
+ @@ -2475,6 +2488,19 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
137
105
return AVERROR(ENOMEM);
138
106
}
139
107
@@ -153,15 +121,15 @@ index 2202ce64..1660cace 100644
153
121
end_pts = hls->recording_time * vs->number;
154
122
155
123
if (vs->sequence - vs->nb_entries > hls->start_sequence && hls->init_time > 0) {
156
- @@ -2681 ,6 +2722 ,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
124
+ @@ -2700 ,6 +2726 ,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
157
125
}
158
126
159
127
vs->packets_written++;
160
128
+ vs->bytes_written += (uint64_t)pkt->size;
161
129
if (oc->pb) {
162
130
ret = ff_write_chained(oc, stream_index, pkt, s, 0);
163
131
vs->video_keyframe_size += pkt->size;
164
- @@ -2868 ,6 +2910 ,36 @@ failed:
132
+ @@ -2888 ,6 +2915 ,36 @@ failed:
165
133
return 0;
166
134
}
167
135
@@ -198,7 +166,7 @@ index 2202ce64..1660cace 100644
198
166
199
167
static int hls_init(AVFormatContext *s)
200
168
{
201
- @@ -2975 ,6 +3047 ,8 @@ static int hls_init(AVFormatContext *s)
169
+ @@ -2995 ,6 +3052 ,8 @@ static int hls_init(AVFormatContext *s)
202
170
vs->sequence = hls->start_sequence;
203
171
vs->start_pts = AV_NOPTS_VALUE;
204
172
vs->end_pts = AV_NOPTS_VALUE;
@@ -207,7 +175,7 @@ index 2202ce64..1660cace 100644
207
175
vs->current_segment_final_filename_fmt[0] = '\0';
208
176
vs->initial_prog_date_time = initial_program_date_time;
209
177
210
- @@ -3117 ,6 +3191 ,9 @@ static int hls_init(AVFormatContext *s)
178
+ @@ -3137 ,6 +3196 ,9 @@ static int hls_init(AVFormatContext *s)
211
179
vs->number++;
212
180
}
213
181
@@ -218,7 +186,7 @@ index 2202ce64..1660cace 100644
218
186
}
219
187
220
188
221
- base-commit: 9f0f680f9ab1ca72edd94de42aef12209c11a6b2
189
+ base-commit: e1601d14100f6c7d088eba676d9555118ca94931
222
190
- -
223
- 2.39.3 (Apple Git-146 )
191
+ 2.39.5 (Apple Git-154 )
224
192
0 commit comments