On 10/16/11 10:13 PM, Anton Khirnov wrote:
+    if ((err = oc->oformat->write_header(oc))<  0) {
+        avio_close(oc->pb);
+        av_freep(&oc->priv_data);
+    }
+

This looks hacky, can't you use avformat_write_header() here?

I'd rather not, too many side effects.

Same here, why not av_write_trailer()?

Same issue as before, we could try that but I'm afraid it would have issues. I started av_write_* but it was causing issues.


+    return ret;
+}
+
+static int seg_write_header(AVFormatContext *s)
+{
+    SegmentContext *seg = s->priv_data;
+    AVFormatContext *oc;
+    int ret;
+
+    seg->number = 0;
+    seg->recording_time = seg->time*1000000;
+    seg->offset_time = 0;

Those two zeros are pointless, seg is malloczed.

You are right

+
+    if (!seg->path) {
+        char *t;
+        seg->path = strdup(s->filename);
+        t = rindex(seg->path, '.');

strrchr()?

Makes sense.

+    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO&&
+        av_compare_ts(pkt->pts, st->time_base,
+                  seg->recording_time*seg->number,
+                              (AVRational){1, 1000000})>= 0&&
+        pkt->flags&  AV_PKT_FLAG_KEY) {

Wait, you only split on video keyframes? What about files with no video?

Audio frames are all keyframes.

+#define OFFSET(x) offsetof(SegmentContext, x)
+#define E AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+    { "container_format", "container format used for the segments", OFFSET(format), 
FF_OPT_TYPE_STRING, {.str = "nut"},  0, 0, E },
+    { "segment_time",     "segment lenght in seconds",              
OFFSET(time),   FF_OPT_TYPE_FLOAT,  {.dbl = 2},      0, FLT_MAX, E },
+    { "segment_pattern",  "pattern to use in segment files",        
OFFSET(pattern),FF_OPT_TYPE_STRING, {.str = "%03d"}, 0, 0, E },
+    { "segment_basename", "basename to use in segment files",       
OFFSET(pattern),FF_OPT_TYPE_STRING, {.str = NULL},   0, 0, E },

FF_OPT_TYPE =>  AV_OPT_TYPE

Ok


+    { NULL },
+};
+
+static const AVClass seg_class = {
+    .class_name = "segment muxer",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+/* input
+#if CONFIG_IMAGE2_DEMUXER
+AVInputFormat ff_image2_demuxer = {
+    .name           = "image2",
+    .long_name      = NULL_IF_CONFIG_SMALL("image2 sequence"),
+    .priv_data_size = sizeof(VideoData),
+    .read_probe     = read_probe,
+    .read_header    = read_header,
+    .read_packet    = read_packet,
+    .flags          = AVFMT_NOFILE,
+    .priv_class     =&img2_class,
+};
+#endif

I suppose this shouldn't be here.

Correct.

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to