On Fri, 27 Jan 2017, Peter Große wrote:
On Fri, 27 Jan 2017 16:02:23 +0200 (EET)
Martin Storsjö <[email protected]> wrote:
On Fri, 27 Jan 2017, Peter Große wrote:
av_dict_set(&opts, "movflags", "frag_custom+dash+delay_moov", 0);
- if ((ret = avformat_write_header(ctx, &opts)) < 0) {
- goto fail;
- }
+ if ((ret = avformat_write_header(ctx, &opts)) < 0)
+ goto fail;
+
+ if ((ret = flush_dynbuf(os, &range_length)) < 0)
+ goto fail;
+
+ if (!c->single_file)
+ ff_format_io_close(s, &os->out);
+
+ os->pos = os->init_range_length = range_length;
This isn't correct. See c5e7ea13d2d4da0c5da91973a547afff6fe9e011. We
intentionally defer writing the init segment until we have passed the
first segment of packets into the muxer, to handle the cases where the
init segments depend on knowledge from the actual first few packets.
(Proper edit lists for handling b-frame delay needs to know the timestamp
of the first packet, and for AC3, the moov box takes a copy of the full
first packet.)
For using the webm muxer, you probably might need to have this behaviour
conditional on the kind of muxer.
So how do you avoid spilling actual packets into the init segment?
Is it that av_write_frame only writes to the file, what was flushed before
using avio_flush?
This relies on the fact that in frag_custom mode, the muxer itself will
never spontaneously flush any output, it only does that when explicitly
flushed (with av_write_frame(NULL)). When you have the delay_moov flag
added, it won't write anything at all during av_write_header, and will
write the init segment during the first av_write_frame(NULL). So if
changing existing code, if you add delay_moov, you need to add one extra
flush to get the init segment. (If you flush earlier, the moov will be
based more on guesses and less on actual data.)
This code resulted from dealing with matroskaenc having his own idea when to
flush and start new clusters.
So my first idea would to the move the "writing out the init segment" code to a
function and call it conditionally depending on the muxer.
If webm, call it in write_header. Then in dash_flush call it, if
os->init_range_length is zero.
Yeah, that sounds sensible. Or rather invert the condition - instead of
if (webm), do if (!mp4), since it's specific to the mp4+delay_moov combo.
// Martin;
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel