You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

589 lines
20KB

  1. /*
  2. * Copyright (c) 2011, Luca Barbato
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file generic segmenter
  22. * M3U8 specification can be find here:
  23. * @url{http://tools.ietf.org/id/draft-pantos-http-live-streaming-08.txt}
  24. */
  25. #include <float.h>
  26. #include "avformat.h"
  27. #include "internal.h"
  28. #include "libavutil/avassert.h"
  29. #include "libavutil/log.h"
  30. #include "libavutil/opt.h"
  31. #include "libavutil/avstring.h"
  32. #include "libavutil/parseutils.h"
  33. #include "libavutil/mathematics.h"
  34. typedef enum {
  35. LIST_TYPE_UNDEFINED = -1,
  36. LIST_TYPE_FLAT = 0,
  37. LIST_TYPE_CSV,
  38. LIST_TYPE_M3U8,
  39. LIST_TYPE_EXT, ///< deprecated
  40. LIST_TYPE_NB,
  41. } ListType;
  42. #define SEGMENT_LIST_FLAG_CACHE 1
  43. #define SEGMENT_LIST_FLAG_LIVE 2
  44. typedef struct {
  45. const AVClass *class; /**< Class for private options. */
  46. int segment_idx; ///< index of the segment file to write, starting from 0
  47. int segment_idx_wrap; ///< number after which the index wraps
  48. int segment_count; ///< number of segment files already written
  49. AVOutputFormat *oformat;
  50. AVFormatContext *avf;
  51. char *format; ///< format to use for output segment files
  52. char *list; ///< filename for the segment list file
  53. int list_count; ///< list counter
  54. int list_flags; ///< flags affecting list generation
  55. int list_size; ///< number of entries for the segment list file
  56. double list_max_segment_time; ///< max segment time in the current list
  57. ListType list_type; ///< set the list type
  58. AVIOContext *list_pb; ///< list file put-byte context
  59. char *time_str; ///< segment duration specification string
  60. int64_t time; ///< segment duration
  61. char *times_str; ///< segment times specification string
  62. int64_t *times; ///< list of segment interval specification
  63. int nb_times; ///< number of elments in the times array
  64. char *time_delta_str; ///< approximation value duration used for the segment times
  65. int64_t time_delta;
  66. int individual_header_trailer; /**< Set by a private option. */
  67. int write_header_trailer; /**< Set by a private option. */
  68. int has_video;
  69. double start_time, end_time;
  70. } SegmentContext;
  71. static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
  72. {
  73. int needs_quoting = !!str[strcspn(str, "\",\n\r")];
  74. if (needs_quoting)
  75. avio_w8(ctx, '"');
  76. for (; *str; str++) {
  77. if (*str == '"')
  78. avio_w8(ctx, '"');
  79. avio_w8(ctx, *str);
  80. }
  81. if (needs_quoting)
  82. avio_w8(ctx, '"');
  83. }
  84. static int segment_mux_init(AVFormatContext *s)
  85. {
  86. SegmentContext *seg = s->priv_data;
  87. AVFormatContext *oc;
  88. int i;
  89. seg->avf = oc = avformat_alloc_context();
  90. if (!oc)
  91. return AVERROR(ENOMEM);
  92. oc->oformat = seg->oformat;
  93. oc->interrupt_callback = s->interrupt_callback;
  94. for (i = 0; i < s->nb_streams; i++) {
  95. AVStream *st;
  96. AVCodecContext *icodec, *ocodec;
  97. if (!(st = avformat_new_stream(oc, NULL)))
  98. return AVERROR(ENOMEM);
  99. icodec = s->streams[i]->codec;
  100. ocodec = st->codec;
  101. avcodec_copy_context(ocodec, icodec);
  102. if (!oc->oformat->codec_tag ||
  103. av_codec_get_id (oc->oformat->codec_tag, icodec->codec_tag) == ocodec->codec_id ||
  104. av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0) {
  105. ocodec->codec_tag = icodec->codec_tag;
  106. } else {
  107. ocodec->codec_tag = 0;
  108. }
  109. st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
  110. }
  111. return 0;
  112. }
  113. static int segment_start(AVFormatContext *s, int write_header)
  114. {
  115. SegmentContext *seg = s->priv_data;
  116. AVFormatContext *oc = seg->avf;
  117. int err = 0;
  118. if (write_header) {
  119. avformat_free_context(oc);
  120. seg->avf = NULL;
  121. if ((err = segment_mux_init(s)) < 0)
  122. return err;
  123. oc = seg->avf;
  124. }
  125. seg->segment_idx++;
  126. if (seg->segment_idx_wrap)
  127. seg->segment_idx %= seg->segment_idx_wrap;
  128. if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
  129. s->filename, seg->segment_idx) < 0) {
  130. av_log(oc, AV_LOG_ERROR, "Invalid segment filename template '%s'\n", s->filename);
  131. return AVERROR(EINVAL);
  132. }
  133. seg->segment_count++;
  134. if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
  135. &s->interrupt_callback, NULL)) < 0)
  136. return err;
  137. if (oc->oformat->priv_class && oc->priv_data)
  138. av_opt_set(oc->priv_data, "resend_headers", "1", 0); /* mpegts specific */
  139. if (write_header) {
  140. if ((err = avformat_write_header(oc, NULL)) < 0)
  141. return err;
  142. }
  143. return 0;
  144. }
  145. static int segment_list_open(AVFormatContext *s)
  146. {
  147. SegmentContext *seg = s->priv_data;
  148. int ret;
  149. ret = avio_open2(&seg->list_pb, seg->list, AVIO_FLAG_WRITE,
  150. &s->interrupt_callback, NULL);
  151. if (ret < 0)
  152. return ret;
  153. seg->list_max_segment_time = 0;
  154. if (seg->list_type == LIST_TYPE_M3U8) {
  155. avio_printf(seg->list_pb, "#EXTM3U\n");
  156. avio_printf(seg->list_pb, "#EXT-X-VERSION:3\n");
  157. avio_printf(seg->list_pb, "#EXT-X-MEDIA-SEQUENCE:%d\n", seg->list_count);
  158. avio_printf(seg->list_pb, "#EXT-X-ALLOWCACHE:%d\n",
  159. !!(seg->list_flags & SEGMENT_LIST_FLAG_CACHE));
  160. if (seg->list_flags & SEGMENT_LIST_FLAG_LIVE)
  161. avio_printf(seg->list_pb,
  162. "#EXT-X-TARGETDURATION:%"PRId64"\n", seg->time / 1000000);
  163. }
  164. return ret;
  165. }
  166. static void segment_list_close(AVFormatContext *s)
  167. {
  168. SegmentContext *seg = s->priv_data;
  169. if (seg->list_type == LIST_TYPE_M3U8) {
  170. if (!(seg->list_flags & SEGMENT_LIST_FLAG_LIVE))
  171. avio_printf(seg->list_pb, "#EXT-X-TARGETDURATION:%d\n",
  172. (int)ceil(seg->list_max_segment_time));
  173. avio_printf(seg->list_pb, "#EXT-X-ENDLIST\n");
  174. }
  175. seg->list_count++;
  176. avio_close(seg->list_pb);
  177. }
  178. static int segment_end(AVFormatContext *s, int write_trailer)
  179. {
  180. SegmentContext *seg = s->priv_data;
  181. AVFormatContext *oc = seg->avf;
  182. int ret = 0;
  183. av_write_frame(oc, NULL); /* Flush any buffered data (fragmented mp4) */
  184. if (write_trailer)
  185. ret = av_write_trailer(oc);
  186. if (ret < 0)
  187. av_log(s, AV_LOG_ERROR, "Failure occurred when ending segment '%s'\n",
  188. oc->filename);
  189. if (seg->list) {
  190. if (seg->list_size && !(seg->segment_count % seg->list_size)) {
  191. segment_list_close(s);
  192. if ((ret = segment_list_open(s)) < 0)
  193. goto end;
  194. }
  195. if (seg->list_type == LIST_TYPE_FLAT) {
  196. avio_printf(seg->list_pb, "%s\n", oc->filename);
  197. } else if (seg->list_type == LIST_TYPE_CSV || seg->list_type == LIST_TYPE_EXT) {
  198. print_csv_escaped_str(seg->list_pb, oc->filename);
  199. avio_printf(seg->list_pb, ",%f,%f\n", seg->start_time, seg->end_time);
  200. } else if (seg->list_type == LIST_TYPE_M3U8) {
  201. avio_printf(seg->list_pb, "#EXTINF:%f,\n%s\n",
  202. seg->end_time - seg->start_time, oc->filename);
  203. }
  204. seg->list_max_segment_time = FFMAX(seg->end_time - seg->start_time, seg->list_max_segment_time);
  205. avio_flush(seg->list_pb);
  206. }
  207. end:
  208. avio_close(oc->pb);
  209. return ret;
  210. }
  211. static int parse_times(void *log_ctx, int64_t **times, int *nb_times,
  212. const char *times_str)
  213. {
  214. char *p;
  215. int i, ret = 0;
  216. char *times_str1 = av_strdup(times_str);
  217. char *saveptr = NULL;
  218. if (!times_str1)
  219. return AVERROR(ENOMEM);
  220. #define FAIL(err) ret = err; goto end
  221. *nb_times = 1;
  222. for (p = times_str1; *p; p++)
  223. if (*p == ',')
  224. (*nb_times)++;
  225. *times = av_malloc(sizeof(**times) * *nb_times);
  226. if (!*times) {
  227. av_log(log_ctx, AV_LOG_ERROR, "Could not allocate forced times array\n");
  228. FAIL(AVERROR(ENOMEM));
  229. }
  230. p = times_str1;
  231. for (i = 0; i < *nb_times; i++) {
  232. int64_t t;
  233. char *tstr = av_strtok(p, ",", &saveptr);
  234. av_assert0(tstr);
  235. p = NULL;
  236. ret = av_parse_time(&t, tstr, 1);
  237. if (ret < 0) {
  238. av_log(log_ctx, AV_LOG_ERROR,
  239. "Invalid time duration specification in %s\n", p);
  240. FAIL(AVERROR(EINVAL));
  241. }
  242. (*times)[i] = t;
  243. /* check on monotonicity */
  244. if (i && (*times)[i-1] > (*times)[i]) {
  245. av_log(log_ctx, AV_LOG_ERROR,
  246. "Specified time %f is greater than the following time %f\n",
  247. (float)((*times)[i])/1000000, (float)((*times)[i-1])/1000000);
  248. FAIL(AVERROR(EINVAL));
  249. }
  250. }
  251. end:
  252. av_free(times_str1);
  253. return ret;
  254. }
  255. static int open_null_ctx(AVIOContext **ctx)
  256. {
  257. int buf_size = 32768;
  258. uint8_t *buf = av_malloc(buf_size);
  259. if (!buf)
  260. return AVERROR(ENOMEM);
  261. *ctx = avio_alloc_context(buf, buf_size, AVIO_FLAG_WRITE, NULL, NULL, NULL, NULL);
  262. if (!*ctx) {
  263. av_free(buf);
  264. return AVERROR(ENOMEM);
  265. }
  266. return 0;
  267. }
  268. static void close_null_ctx(AVIOContext *pb)
  269. {
  270. av_free(pb->buffer);
  271. av_free(pb);
  272. }
  273. static int seg_write_header(AVFormatContext *s)
  274. {
  275. SegmentContext *seg = s->priv_data;
  276. AVFormatContext *oc = NULL;
  277. int ret, i;
  278. seg->segment_count = 0;
  279. if (!seg->write_header_trailer)
  280. seg->individual_header_trailer = 0;
  281. if (seg->time_str && seg->times_str) {
  282. av_log(s, AV_LOG_ERROR,
  283. "segment_time and segment_times options are mutually exclusive, select just one of them\n");
  284. return AVERROR(EINVAL);
  285. }
  286. if ((seg->list_flags & SEGMENT_LIST_FLAG_LIVE) && seg->times_str) {
  287. av_log(s, AV_LOG_ERROR,
  288. "segment_flags +live and segment_times options are mutually exclusive:"
  289. "specify -segment_time if you want a live-friendly list\n");
  290. return AVERROR(EINVAL);
  291. }
  292. if (seg->times_str) {
  293. if ((ret = parse_times(s, &seg->times, &seg->nb_times, seg->times_str)) < 0)
  294. return ret;
  295. } else {
  296. /* set default value if not specified */
  297. if (!seg->time_str)
  298. seg->time_str = av_strdup("2");
  299. if ((ret = av_parse_time(&seg->time, seg->time_str, 1)) < 0) {
  300. av_log(s, AV_LOG_ERROR,
  301. "Invalid time duration specification '%s' for segment_time option\n",
  302. seg->time_str);
  303. return ret;
  304. }
  305. }
  306. if (seg->time_delta_str) {
  307. if ((ret = av_parse_time(&seg->time_delta, seg->time_delta_str, 1)) < 0) {
  308. av_log(s, AV_LOG_ERROR,
  309. "Invalid time duration specification '%s' for delta option\n",
  310. seg->time_delta_str);
  311. return ret;
  312. }
  313. }
  314. if (seg->list) {
  315. if (seg->list_type == LIST_TYPE_UNDEFINED) {
  316. if (av_match_ext(seg->list, "csv" )) seg->list_type = LIST_TYPE_CSV;
  317. else if (av_match_ext(seg->list, "ext" )) seg->list_type = LIST_TYPE_EXT;
  318. else if (av_match_ext(seg->list, "m3u8")) seg->list_type = LIST_TYPE_M3U8;
  319. else seg->list_type = LIST_TYPE_FLAT;
  320. }
  321. if ((ret = segment_list_open(s)) < 0)
  322. goto fail;
  323. }
  324. if (seg->list_type == LIST_TYPE_EXT)
  325. av_log(s, AV_LOG_WARNING, "'ext' list type option is deprecated in favor of 'csv'\n");
  326. for (i = 0; i < s->nb_streams; i++)
  327. seg->has_video +=
  328. (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO);
  329. if (seg->has_video > 1)
  330. av_log(s, AV_LOG_WARNING,
  331. "More than a single video stream present, "
  332. "expect issues decoding it.\n");
  333. seg->oformat = av_guess_format(seg->format, s->filename, NULL);
  334. if (!seg->oformat) {
  335. ret = AVERROR_MUXER_NOT_FOUND;
  336. goto fail;
  337. }
  338. if (seg->oformat->flags & AVFMT_NOFILE) {
  339. av_log(s, AV_LOG_ERROR, "format %s not supported.\n",
  340. seg->oformat->name);
  341. ret = AVERROR(EINVAL);
  342. goto fail;
  343. }
  344. if ((ret = segment_mux_init(s)) < 0)
  345. goto fail;
  346. oc = seg->avf;
  347. if (av_get_frame_filename(oc->filename, sizeof(oc->filename),
  348. s->filename, seg->segment_idx) < 0) {
  349. ret = AVERROR(EINVAL);
  350. goto fail;
  351. }
  352. seg->segment_count++;
  353. if (seg->write_header_trailer) {
  354. if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
  355. &s->interrupt_callback, NULL)) < 0)
  356. goto fail;
  357. } else {
  358. if ((ret = open_null_ctx(&oc->pb)) < 0)
  359. goto fail;
  360. }
  361. if ((ret = avformat_write_header(oc, NULL)) < 0) {
  362. avio_close(oc->pb);
  363. goto fail;
  364. }
  365. if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
  366. s->avoid_negative_ts = 1;
  367. if (!seg->write_header_trailer) {
  368. close_null_ctx(oc->pb);
  369. if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
  370. &s->interrupt_callback, NULL)) < 0)
  371. goto fail;
  372. }
  373. fail:
  374. if (ret) {
  375. if (seg->list)
  376. segment_list_close(s);
  377. if (seg->avf)
  378. avformat_free_context(seg->avf);
  379. }
  380. return ret;
  381. }
  382. static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
  383. {
  384. SegmentContext *seg = s->priv_data;
  385. AVFormatContext *oc = seg->avf;
  386. AVStream *st = s->streams[pkt->stream_index];
  387. int64_t end_pts;
  388. int ret;
  389. if (seg->times) {
  390. end_pts = seg->segment_count <= seg->nb_times ?
  391. seg->times[seg->segment_count-1] : INT64_MAX;
  392. } else {
  393. end_pts = seg->time * seg->segment_count;
  394. }
  395. /* if the segment has video, start a new segment *only* with a key video frame */
  396. if ((st->codec->codec_type == AVMEDIA_TYPE_VIDEO || !seg->has_video) &&
  397. av_compare_ts(pkt->pts, st->time_base,
  398. end_pts-seg->time_delta, AV_TIME_BASE_Q) >= 0 &&
  399. pkt->flags & AV_PKT_FLAG_KEY) {
  400. av_log(s, AV_LOG_DEBUG, "Next segment starts with packet stream:%d pts:%"PRId64" pts_time:%f\n",
  401. pkt->stream_index, pkt->pts, pkt->pts * av_q2d(st->time_base));
  402. ret = segment_end(s, seg->individual_header_trailer);
  403. if (!ret)
  404. ret = segment_start(s, seg->individual_header_trailer);
  405. if (ret)
  406. goto fail;
  407. oc = seg->avf;
  408. seg->start_time = (double)pkt->pts * av_q2d(st->time_base);
  409. } else if (pkt->pts != AV_NOPTS_VALUE) {
  410. seg->end_time = FFMAX(seg->end_time,
  411. (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
  412. }
  413. ret = ff_write_chained(oc, pkt->stream_index, pkt, s);
  414. fail:
  415. if (ret < 0) {
  416. if (seg->list)
  417. avio_close(seg->list_pb);
  418. avformat_free_context(oc);
  419. }
  420. return ret;
  421. }
  422. static int seg_write_trailer(struct AVFormatContext *s)
  423. {
  424. SegmentContext *seg = s->priv_data;
  425. AVFormatContext *oc = seg->avf;
  426. int ret;
  427. if (!seg->write_header_trailer) {
  428. if ((ret = segment_end(s, 0)) < 0)
  429. goto fail;
  430. open_null_ctx(&oc->pb);
  431. ret = av_write_trailer(oc);
  432. close_null_ctx(oc->pb);
  433. } else {
  434. ret = segment_end(s, 1);
  435. }
  436. fail:
  437. if (seg->list)
  438. segment_list_close(s);
  439. av_opt_free(seg);
  440. av_freep(&seg->times);
  441. avformat_free_context(oc);
  442. return ret;
  443. }
  444. #define OFFSET(x) offsetof(SegmentContext, x)
  445. #define E AV_OPT_FLAG_ENCODING_PARAM
  446. static const AVOption options[] = {
  447. { "segment_format", "set container format used for the segments", OFFSET(format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
  448. { "segment_list", "set the segment list filename", OFFSET(list), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
  449. { "segment_list_flags","set flags affecting segment list generation", OFFSET(list_flags), AV_OPT_TYPE_FLAGS, {.i64 = SEGMENT_LIST_FLAG_CACHE }, 0, UINT_MAX, E, "list_flags"},
  450. { "cache", "allow list caching", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_LIST_FLAG_CACHE }, INT_MIN, INT_MAX, E, "list_flags"},
  451. { "live", "enable live-friendly list generation (useful for HLS)", 0, AV_OPT_TYPE_CONST, {.i64 = SEGMENT_LIST_FLAG_LIVE }, INT_MIN, INT_MAX, E, "list_flags"},
  452. { "segment_list_size", "set the maximum number of playlist entries", OFFSET(list_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
  453. { "segment_list_type", "set the segment list type", OFFSET(list_type), AV_OPT_TYPE_INT, {.i64 = LIST_TYPE_UNDEFINED}, -1, LIST_TYPE_NB-1, E, "list_type" },
  454. { "flat", "flat format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_FLAT }, INT_MIN, INT_MAX, 0, "list_type" },
  455. { "csv", "csv format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_CSV }, INT_MIN, INT_MAX, 0, "list_type" },
  456. { "ext", "extended format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_EXT }, INT_MIN, INT_MAX, 0, "list_type" },
  457. { "m3u8", "M3U8 format", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, 0, "list_type" },
  458. { "hls", "Apple HTTP Live Streaming compatible", 0, AV_OPT_TYPE_CONST, {.i64=LIST_TYPE_M3U8 }, INT_MIN, INT_MAX, 0, "list_type" },
  459. { "segment_time", "set segment duration", OFFSET(time_str),AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E },
  460. { "segment_time_delta","set approximation value used for the segment times", OFFSET(time_delta_str), AV_OPT_TYPE_STRING, {.str = "0"}, 0, 0, E },
  461. { "segment_times", "set segment split time points", OFFSET(times_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E },
  462. { "segment_wrap", "set number after which the index wraps", OFFSET(segment_idx_wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
  463. { "individual_header_trailer", "write header/trailer to each segment", OFFSET(individual_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
  464. { "write_header_trailer", "write a header to the first segment and a trailer to the last one", OFFSET(write_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
  465. { NULL },
  466. };
  467. static const AVClass seg_class = {
  468. .class_name = "segment muxer",
  469. .item_name = av_default_item_name,
  470. .option = options,
  471. .version = LIBAVUTIL_VERSION_INT,
  472. };
  473. AVOutputFormat ff_segment_muxer = {
  474. .name = "segment",
  475. .long_name = NULL_IF_CONFIG_SMALL("segment"),
  476. .priv_data_size = sizeof(SegmentContext),
  477. .flags = AVFMT_NOFILE|AVFMT_GLOBALHEADER,
  478. .write_header = seg_write_header,
  479. .write_packet = seg_write_packet,
  480. .write_trailer = seg_write_trailer,
  481. .priv_class = &seg_class,
  482. };
  483. static const AVClass sseg_class = {
  484. .class_name = "stream_segment muxer",
  485. .item_name = av_default_item_name,
  486. .option = options,
  487. .version = LIBAVUTIL_VERSION_INT,
  488. };
  489. AVOutputFormat ff_stream_segment_muxer = {
  490. .name = "stream_segment,ssegment",
  491. .long_name = NULL_IF_CONFIG_SMALL("streaming segment muxer"),
  492. .priv_data_size = sizeof(SegmentContext),
  493. .flags = AVFMT_NOFILE,
  494. .write_header = seg_write_header,
  495. .write_packet = seg_write_packet,
  496. .write_trailer = seg_write_trailer,
  497. .priv_class = &sseg_class,
  498. };