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.

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