FFmpeg
Loading...
Searching...
No Matches
hdsenc.c
Go to the documentation of this file.
1/*
2 * Live HDS fragmenter
3 * Copyright (c) 2013 Martin Storsjo
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "config.h"
23#if HAVE_UNISTD_H
24#include <unistd.h>
25#endif
26
27#include "avformat.h"
28#include "internal.h"
29#include "mux.h"
30#include "os_support.h"
31
33#include "libavutil/avstring.h"
34#include "libavutil/base64.h"
37#include "libavutil/mem.h"
38#include "libavutil/opt.h"
39
40typedef struct Fragment {
41 char file[1024];
43 int n;
44} Fragment;
45
46typedef struct OutputStream {
50 int ctx_inited;
51 uint8_t iobuf[32768];
52 char temp_filename[1024];
58
60
61 uint8_t *metadata;
63
64 uint8_t *extra_packets[2];
68
69typedef struct HDSContext {
70 const AVClass *class; /* Class for private options. */
75
79
80static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size)
81{
82 if (buf_size < 13)
84 if (memcmp(buf, "FLV", 3))
86 buf += 13;
87 buf_size -= 13;
88 while (buf_size >= 11 + 4) {
89 int type = buf[0];
90 int size = AV_RB24(&buf[1]) + 11 + 4;
91 if (size > buf_size)
93 if (type == 8 || type == 9) {
98 if (!os->extra_packets[os->nb_extra_packets])
99 return AVERROR(ENOMEM);
100 os->nb_extra_packets++;
101 } else if (type == 0x12) {
102 if (os->metadata)
103 return AVERROR_INVALIDDATA;
104 os->metadata_size = size - 11 - 4;
105 os->metadata = av_memdup(buf + 11, os->metadata_size);
106 if (!os->metadata)
107 return AVERROR(ENOMEM);
108 }
109 buf += size;
110 buf_size -= size;
111 }
112 if (!os->metadata)
113 return AVERROR_INVALIDDATA;
114 return 0;
115}
116
117static int hds_write(void *opaque, const uint8_t *buf, int buf_size)
118{
119 OutputStream *os = opaque;
120 if (os->out) {
121 avio_write(os->out, buf, buf_size);
122 } else {
123 if (!os->metadata_size) {
124 int ret;
125 // Assuming the IO buffer is large enough to fit the
126 // FLV header and all metadata and extradata packets
127 if ((ret = parse_header(os, buf, buf_size)) < 0)
128 return ret;
129 }
130 }
131 return buf_size;
132}
133
135{
136 HDSContext *c = s->priv_data;
137 int i, j;
138 if (!c->streams)
139 return;
140 for (i = 0; i < s->nb_streams; i++) {
141 OutputStream *os = &c->streams[i];
142 if (os->out)
143 ff_format_io_close(s, &os->out);
144 if (os->ctx && os->ctx_inited)
146 if (os->ctx)
147 avio_context_free(&os->ctx->pb);
149 av_freep(&os->metadata);
150 for (j = 0; j < os->nb_extra_packets; j++)
151 av_freep(&os->extra_packets[j]);
152 for (j = 0; j < os->nb_fragments; j++)
153 av_freep(&os->fragments[j]);
154 av_freep(&os->fragments);
155 }
156 av_freep(&c->streams);
157}
158
159static int write_manifest(AVFormatContext *s, int final)
160{
161 HDSContext *c = s->priv_data;
163 char filename[1024], temp_filename[1024];
164 int ret, i;
165 double duration = 0;
166
167 if (c->nb_streams > 0)
168 duration = c->streams[0].last_ts * av_q2d(s->streams[0]->time_base);
169
170 snprintf(filename, sizeof(filename), "%s/index.f4m", s->url);
171 snprintf(temp_filename, sizeof(temp_filename), "%s/index.f4m.tmp", s->url);
172 ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL);
173 if (ret < 0) {
174 av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
175 return ret;
176 }
177 avio_printf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
178 avio_printf(out, "<manifest xmlns=\"http://ns.adobe.com/f4m/1.0\">\n");
179 avio_printf(out, "\t<id>%s</id>\n", av_basename(s->url));
180 avio_printf(out, "\t<streamType>%s</streamType>\n",
181 final ? "recorded" : "live");
182 avio_printf(out, "\t<deliveryType>streaming</deliveryType>\n");
183 if (final)
184 avio_printf(out, "\t<duration>%f</duration>\n", duration);
185 for (i = 0; i < c->nb_streams; i++) {
186 OutputStream *os = &c->streams[i];
187 int b64_size = AV_BASE64_SIZE(os->metadata_size);
188 char *base64 = av_malloc(b64_size);
189 if (!base64) {
191 return AVERROR(ENOMEM);
192 }
193 av_base64_encode(base64, b64_size, os->metadata, os->metadata_size);
194
195 avio_printf(out, "\t<bootstrapInfo profile=\"named\" url=\"stream%d.abst\" id=\"bootstrap%d\" />\n", i, i);
196 avio_printf(out, "\t<media bitrate=\"%d\" url=\"stream%d\" bootstrapInfoId=\"bootstrap%d\">\n", os->bitrate/1000, i, i);
197 avio_printf(out, "\t\t<metadata>%s</metadata>\n", base64);
198 avio_printf(out, "\t</media>\n");
199 av_free(base64);
200 }
201 avio_printf(out, "</manifest>\n");
204 return ff_rename(temp_filename, filename, s);
205}
206
208{
209 int64_t end = avio_tell(out);
210 avio_seek(out, pos, SEEK_SET);
211 avio_wb32(out, end - pos);
212 avio_seek(out, end, SEEK_SET);
213}
214
215/* Note, the .abst files need to be served with the "binary/octet"
216 * mime type, otherwise at least the OSMF player can easily fail
217 * with "stream not found" when polling for the next fragment. */
218static int write_abst(AVFormatContext *s, OutputStream *os, int final)
219{
220 HDSContext *c = s->priv_data;
222 char filename[1024], temp_filename[1024];
223 int i, ret;
224 int64_t asrt_pos, afrt_pos;
225 int start = 0, fragments;
226 int index = s->streams[os->first_stream]->id;
227 int64_t cur_media_time = 0;
228 if (c->window_size)
229 start = FFMAX(os->nb_fragments - c->window_size, 0);
230 fragments = os->nb_fragments - start;
231 if (final)
232 cur_media_time = os->last_ts;
233 else if (os->nb_fragments)
234 cur_media_time = os->fragments[os->nb_fragments - 1]->start_time;
235
236 snprintf(filename, sizeof(filename),
237 "%s/stream%d.abst", s->url, index);
238 snprintf(temp_filename, sizeof(temp_filename),
239 "%s/stream%d.abst.tmp", s->url, index);
240 ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, NULL);
241 if (ret < 0) {
242 av_log(s, AV_LOG_ERROR, "Unable to open %s for writing\n", temp_filename);
243 return ret;
244 }
245 avio_wb32(out, 0); // abst size
246 avio_wl32(out, MKTAG('a','b','s','t'));
247 avio_wb32(out, 0); // version + flags
248 avio_wb32(out, os->fragment_index - 1); // BootstrapinfoVersion
249 avio_w8(out, final ? 0 : 0x20); // profile, live, update
250 avio_wb32(out, 1000); // timescale
251 avio_wb64(out, cur_media_time);
252 avio_wb64(out, 0); // SmpteTimeCodeOffset
253 avio_w8(out, 0); // MovieIdentifer (null string)
254 avio_w8(out, 0); // ServerEntryCount
255 avio_w8(out, 0); // QualityEntryCount
256 avio_w8(out, 0); // DrmData (null string)
257 avio_w8(out, 0); // MetaData (null string)
258 avio_w8(out, 1); // SegmentRunTableCount
259 asrt_pos = avio_tell(out);
260 avio_wb32(out, 0); // asrt size
261 avio_wl32(out, MKTAG('a','s','r','t'));
262 avio_wb32(out, 0); // version + flags
263 avio_w8(out, 0); // QualityEntryCount
264 avio_wb32(out, 1); // SegmentRunEntryCount
265 avio_wb32(out, 1); // FirstSegment
266 avio_wb32(out, final ? (os->fragment_index - 1) : 0xffffffff); // FragmentsPerSegment
267 update_size(out, asrt_pos);
268 avio_w8(out, 1); // FragmentRunTableCount
269 afrt_pos = avio_tell(out);
270 avio_wb32(out, 0); // afrt size
271 avio_wl32(out, MKTAG('a','f','r','t'));
272 avio_wb32(out, 0); // version + flags
273 avio_wb32(out, 1000); // timescale
274 avio_w8(out, 0); // QualityEntryCount
275 avio_wb32(out, fragments); // FragmentRunEntryCount
276 for (i = start; i < os->nb_fragments; i++) {
277 avio_wb32(out, os->fragments[i]->n);
280 }
281 update_size(out, afrt_pos);
282 update_size(out, 0);
284 return ff_rename(temp_filename, filename, s);
285}
286
287static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
288{
289 int ret, i;
290 ret = s->io_open(s, &os->out, os->temp_filename, AVIO_FLAG_WRITE, NULL);
291 if (ret < 0)
292 return ret;
293 avio_wb32(os->out, 0);
294 avio_wl32(os->out, MKTAG('m','d','a','t'));
295 for (i = 0; i < os->nb_extra_packets; i++) {
296 AV_WB24(os->extra_packets[i] + 4, start_ts);
297 os->extra_packets[i][7] = (start_ts >> 24) & 0x7f;
299 }
300 return 0;
301}
302
304{
305 int64_t pos = avio_tell(os->out);
306 avio_seek(os->out, 0, SEEK_SET);
307 avio_wb32(os->out, pos);
308 avio_flush(os->out);
309 ff_format_io_close(s, &os->out);
310}
311
313{
314 HDSContext *c = s->priv_data;
315 int ret = 0, i;
316
317 if (mkdir(s->url, 0777) == -1 && errno != EEXIST) {
318 av_log(s, AV_LOG_ERROR , "Failed to create directory %s\n", s->url);
319 return AVERROR(errno);
320 }
321
322
323 c->streams = av_calloc(s->nb_streams, sizeof(*c->streams));
324 if (!c->streams) {
325 return AVERROR(ENOMEM);
326 }
327
328 for (i = 0; i < s->nb_streams; i++) {
329 OutputStream *os = &c->streams[c->nb_streams];
331 AVStream *st = s->streams[i];
332
333 if (!st->codecpar->bit_rate) {
334 av_log(s, AV_LOG_ERROR, "No bit rate set for stream %d\n", i);
335 return AVERROR(EINVAL);
336 }
338 if (os->has_video) {
339 c->nb_streams++;
340 os++;
341 }
342 os->has_video = 1;
343 } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
344 if (os->has_audio) {
345 c->nb_streams++;
346 os++;
347 }
348 os->has_audio = 1;
349 } else {
350 av_log(s, AV_LOG_ERROR, "Unsupported stream type in stream %d\n", i);
351 return AVERROR(EINVAL);
352 }
353 os->bitrate += s->streams[i]->codecpar->bit_rate;
354
355 if (!os->ctx) {
356 os->first_stream = i;
358 if (!ctx) {
359 return AVERROR(ENOMEM);
360 }
361 os->ctx = ctx;
363 ctx->oformat = &ff_flv_muxer.p;
364 ctx->interrupt_callback = s->interrupt_callback;
365 ctx->flags = s->flags;
366
367 ctx->pb = avio_alloc_context(os->iobuf, sizeof(os->iobuf),
368 1, os,
370 if (!ctx->pb) {
371 return AVERROR(ENOMEM);
372 }
373 } else {
374 ctx = os->ctx;
375 }
376 s->streams[i]->id = c->nb_streams;
377
378 if (!(st = avformat_new_stream(ctx, NULL))) {
379 return AVERROR(ENOMEM);
380 }
381 avcodec_parameters_copy(st->codecpar, s->streams[i]->codecpar);
382 st->codecpar->codec_tag = 0;
383 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
384 st->time_base = s->streams[i]->time_base;
385 }
386 if (c->streams[c->nb_streams].ctx)
387 c->nb_streams++;
388
389 for (i = 0; i < c->nb_streams; i++) {
390 OutputStream *os = &c->streams[i];
391 int j;
392 if ((ret = avformat_write_header(os->ctx, NULL)) < 0) {
393 return ret;
394 }
395 os->ctx_inited = 1;
396 avio_flush(os->ctx->pb);
397 for (j = 0; j < os->ctx->nb_streams; j++)
398 s->streams[os->first_stream + j]->time_base = os->ctx->streams[j]->time_base;
399
400 snprintf(os->temp_filename, sizeof(os->temp_filename),
401 "%s/stream%d_temp", s->url, i);
402 ret = init_file(s, os, 0);
403 if (ret < 0)
404 return ret;
405
406 if (!os->has_video && c->min_frag_duration <= 0) {
408 "No video stream in output stream %d and no min frag duration set\n", i);
409 }
410 os->fragment_index = 1;
411 write_abst(s, os, 0);
412 }
413 ret = write_manifest(s, 0);
414
415 return ret;
416}
417
418static int add_fragment(OutputStream *os, const char *file,
420{
421 Fragment *frag;
422 if (duration == 0)
423 duration = 1;
424 if (os->nb_fragments >= os->fragments_size) {
425 int ret;
426 os->fragments_size = (os->fragments_size + 1) * 2;
427 if ((ret = av_reallocp_array(&os->fragments, os->fragments_size,
428 sizeof(*os->fragments))) < 0) {
429 os->fragments_size = 0;
430 os->nb_fragments = 0;
431 return ret;
432 }
433 }
434 frag = av_mallocz(sizeof(*frag));
435 if (!frag)
436 return AVERROR(ENOMEM);
437 av_strlcpy(frag->file, file, sizeof(frag->file));
438 frag->start_time = start_time;
439 frag->duration = duration;
440 frag->n = os->fragment_index;
441 os->fragments[os->nb_fragments++] = frag;
442 os->fragment_index++;
443 return 0;
444}
445
446static int hds_flush(AVFormatContext *s, OutputStream *os, int final,
447 int64_t end_ts)
448{
449 HDSContext *c = s->priv_data;
450 int i, ret = 0;
451 char target_filename[1024];
452 int index = s->streams[os->first_stream]->id;
453
454 if (!os->packets_written)
455 return 0;
456
457 avio_flush(os->ctx->pb);
458 os->packets_written = 0;
459 close_file(s, os);
460
461 snprintf(target_filename, sizeof(target_filename),
462 "%s/stream%dSeg1-Frag%d", s->url, index, os->fragment_index);
463 ret = ff_rename(os->temp_filename, target_filename, s);
464 if (ret < 0)
465 return ret;
466 add_fragment(os, target_filename, os->frag_start_ts, end_ts - os->frag_start_ts);
467
468 if (!final) {
469 ret = init_file(s, os, end_ts);
470 if (ret < 0)
471 return ret;
472 }
473
474 if (c->window_size || (final && c->remove_at_exit)) {
475 int remove = os->nb_fragments - c->window_size - c->extra_window_size;
476 if (final && c->remove_at_exit)
477 remove = os->nb_fragments;
478 if (remove > 0) {
479 for (i = 0; i < remove; i++) {
480 unlink(os->fragments[i]->file);
481 av_freep(&os->fragments[i]);
482 }
483 os->nb_fragments -= remove;
484 memmove(os->fragments, os->fragments + remove,
485 os->nb_fragments * sizeof(*os->fragments));
486 }
487 }
488
489 if (ret >= 0)
490 ret = write_abst(s, os, final);
491 return ret;
492}
493
495{
496 HDSContext *c = s->priv_data;
497 AVStream *st = s->streams[pkt->stream_index];
498 FFStream *const sti = ffstream(st);
499 OutputStream *os = &c->streams[s->streams[pkt->stream_index]->id];
500 int64_t end_dts = os->fragment_index * (int64_t)c->min_frag_duration;
501 int ret;
502
503 if (sti->first_dts == AV_NOPTS_VALUE)
504 sti->first_dts = pkt->dts;
505
506 if ((!os->has_video || st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) &&
507 av_compare_ts(pkt->dts - sti->first_dts, st->time_base,
508 end_dts, AV_TIME_BASE_Q) >= 0 &&
509 pkt->flags & AV_PKT_FLAG_KEY && os->packets_written) {
510
511 if ((ret = hds_flush(s, os, 0, pkt->dts)) < 0)
512 return ret;
513 }
514
515 // Note, these fragment start timestamps, that represent a whole
516 // OutputStream, assume all streams in it have the same time base.
517 if (!os->packets_written)
518 os->frag_start_ts = pkt->dts;
519 os->last_ts = pkt->dts;
520
521 os->packets_written++;
522 return ff_write_chained(os->ctx, pkt->stream_index - os->first_stream, pkt, s, 0);
523}
524
526{
527 HDSContext *c = s->priv_data;
528 int i;
529
530 for (i = 0; i < c->nb_streams; i++)
531 hds_flush(s, &c->streams[i], 1, c->streams[i].last_ts);
532 write_manifest(s, 1);
533
534 if (c->remove_at_exit) {
535 char filename[1024];
536 snprintf(filename, sizeof(filename), "%s/index.f4m", s->url);
537 unlink(filename);
538 for (i = 0; i < c->nb_streams; i++) {
539 snprintf(filename, sizeof(filename), "%s/stream%d.abst", s->url, i);
540 unlink(filename);
541 }
542 rmdir(s->url);
543 }
544
545 return 0;
546}
547
548#define OFFSET(x) offsetof(HDSContext, x)
549#define E AV_OPT_FLAG_ENCODING_PARAM
550static const AVOption options[] = {
551 { "window_size", "number of fragments kept in the manifest", OFFSET(window_size), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, E },
552 { "extra_window_size", "number of fragments kept outside of the manifest before removing from disk", OFFSET(extra_window_size), AV_OPT_TYPE_INT, { .i64 = 5 }, 0, INT_MAX, E },
553 { "min_frag_duration", "minimum fragment duration (in microseconds)", OFFSET(min_frag_duration), AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0, INT_MAX, E },
554 { "remove_at_exit", "remove all fragments when finished", OFFSET(remove_at_exit), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, E },
555 { NULL },
556};
557
558static const AVClass hds_class = {
559 .class_name = "HDS muxer",
560 .item_name = av_default_item_name,
561 .option = options,
562 .version = LIBAVUTIL_VERSION_INT,
563};
564
566 .p.name = "hds",
567 .p.long_name = NULL_IF_CONFIG_SMALL("HDS Muxer"),
568 .p.audio_codec = AV_CODEC_ID_AAC,
569 .p.video_codec = AV_CODEC_ID_H264,
570 .p.flags = AVFMT_GLOBALHEADER | AVFMT_NOFILE,
571 .p.priv_class = &hds_class,
572 .priv_data_size = sizeof(HDSContext),
576 .deinit = hds_free,
577};
const FFOutputFormat ff_hds_muxer
Definition hdsenc.c:565
const FFOutputFormat ff_flv_muxer
Definition flvenc.c:1540
#define EXTERN
#define E
Definition avdct.c:34
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
Definition avformat.c:961
Main libavformat public API header.
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition avformat.h:488
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition avformat.h:497
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap ffurl_move() and log if error happens.
Definition avio.c:929
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition aviobuf.c:236
void avio_wl32(AVIOContext *s, unsigned int val)
Definition aviobuf.c:360
void avio_w8(AVIOContext *s, int b)
Definition aviobuf.c:184
void avio_wb32(AVIOContext *s, unsigned int val)
Definition aviobuf.c:368
#define AVIO_FLAG_WRITE
write-only
Definition avio.h:618
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition avio.h:494
int avio_printf(AVIOContext *s, const char *fmt,...) av_printf_format(2
Writes a formatted string to the context.
void avio_wb64(AVIOContext *s, uint64_t val)
Definition aviobuf.c:434
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, const uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition aviobuf.c:109
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition aviobuf.c:206
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
Definition aviobuf.c:126
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition aviobuf.c:228
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
static void deinit(AVFormatContext *s)
Definition chromaprint.c:53
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
Definition codec_par.c:107
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt)
Definition ffmpeg_mux.c:204
static int64_t duration
Definition ffplay.c:330
static int64_t start_time
Definition ffplay.c:329
static void write_header(FFV1Context *f)
Definition ffv1enc.c:384
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition opt.h:262
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_AAC
Definition codec_id.h:455
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition options.c:165
void avformat_free_context(AVFormatContext *s)
Free an AVFormatContext and all its streams.
Definition avformat.c:150
av_warn_unused_result int avformat_write_header(AVFormatContext *s, AVDictionary **options)
Allocate the stream private data and write the stream header to an output media file.
Definition mux.c:467
int av_write_trailer(AVFormatContext *s)
Write the stream trailer to an output media file and free the file private data.
Definition mux.c:1238
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
Definition base64.c:147
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition base64.h:66
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:302
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition mem.c:225
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition avstring.c:85
const char * av_basename(const char *path)
Thread safe basename.
Definition avstring.c:253
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition avutil.h:263
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int index
Definition gxfenc.c:90
static void close_file(AVFormatContext *s, OutputStream *os)
Definition hdsenc.c:303
static int hds_write_header(AVFormatContext *s)
Definition hdsenc.c:312
static int hds_flush(AVFormatContext *s, OutputStream *os, int final, int64_t end_ts)
Definition hdsenc.c:446
static void update_size(AVIOContext *out, int64_t pos)
Definition hdsenc.c:207
static int add_fragment(OutputStream *os, const char *file, int64_t start_time, int64_t duration)
Definition hdsenc.c:418
static const AVClass hds_class
Definition hdsenc.c:558
static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size)
Definition hdsenc.c:80
#define OFFSET(x)
Definition hdsenc.c:548
static void hds_free(AVFormatContext *s)
Definition hdsenc.c:134
static int hds_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition hdsenc.c:494
static int write_abst(AVFormatContext *s, OutputStream *os, int final)
Definition hdsenc.c:218
static int hds_write(void *opaque, const uint8_t *buf, int buf_size)
Definition hdsenc.c:117
static int hds_write_trailer(AVFormatContext *s)
Definition hdsenc.c:525
static int write_manifest(AVFormatContext *s, int final)
Definition hdsenc.c:159
static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
Definition hdsenc.c:287
cl_device_type type
#define AV_WB24(p, d)
#define AV_RB24(x)
static av_always_inline FFStream * ffstream(AVStream *st)
Definition internal.h:365
int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt, AVFormatContext *src, int interleave)
Write a packet to another muxer than the one the user originally intended.
Definition mux.c:1337
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define FFMAX(a, b)
Definition macros.h:47
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
miscellaneous OS support macros and functions.
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition snprintf.h:34
unsigned int pos
Definition spdifenc.c:431
Describe the class of an AVClass context structure.
Definition log.h:76
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition codec_par.h:99
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
Format I/O context.
Definition avformat.h:1333
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition avformat.h:1389
AVIOContext * pb
I/O context.
Definition avformat.h:1375
AVStream ** streams
A list of all streams in the file.
Definition avformat.h:1401
Bytestream IO Context.
Definition avio.h:160
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition avformat.h:844
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avformat.h:805
int64_t first_dts
Timestamp corresponding to the last dts sync point.
Definition internal.h:359
int64_t duration
Definition hdsenc.c:42
int64_t start_time
Definition hdsenc.c:42
char file[1024]
Definition hdsenc.c:41
int n
Definition hdsenc.c:43
int window_size
Definition hdsenc.c:71
int nb_streams
Definition hdsenc.c:77
OutputStream * streams
Definition hdsenc.c:76
int remove_at_exit
Definition hdsenc.c:74
int min_frag_duration
Definition hdsenc.c:73
int extra_window_size
Definition hdsenc.c:72
int extra_packet_sizes[2]
Definition hdsenc.c:65
Fragment ** fragments
Definition hdsenc.c:57
int has_video
Definition hdsenc.c:59
atomic_uint_least64_t packets_written
Definition ffmpeg.h:672
int bitrate
Definition hdsenc.c:47
int64_t last_ts
Definition hdsenc.c:53
char temp_filename[1024]
Definition hdsenc.c:52
uint8_t iobuf[32768]
Definition hdsenc.c:51
int has_audio
Definition hdsenc.c:59
AVFormatContext * ctx
Definition dashenc.c:105
int first_stream
Definition hdsenc.c:48
uint8_t * extra_packets[2]
Definition hdsenc.c:64
AVIOContext * out
Definition dashenc.c:107
uint8_t * metadata
Definition hdsenc.c:61
int nb_fragments
Definition hdsenc.c:56
int fragments_size
Definition hdsenc.c:56
int nb_extra_packets
Definition hdsenc.c:66
int64_t frag_start_ts
Definition hdsenc.c:53
int metadata_size
Definition hdsenc.c:62
int fragment_index
Definition hdsenc.c:56
int ctx_inited
Definition dashenc.c:106
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
int size
static int write_trailer(AVFormatContext *s1)
Definition v4l2enc.c:101
static double c[64]