How to concatenate webm segments?

567 views
Skip to first unread message

jianwen chen

unread,
May 19, 2011, 9:07:07 PM5/19/11
to WebM Discussion
I have 2 webm files on hand, I want to concatenate them by
concatenating the segments in each file.

According to the Matroska specification, I know a live stream is
designated by setting the “Segment” size to “unknown”. I manually set
the size of each segment to a very large value and setting the
duration of the segments to 100 hours. And I also delete the
“SeekHead” elements and “Cues” elements in 2 mkv files. I have no
cluster in the webm files. http://matroska.org/technical/streaming/index.html

But only the 1st segment in the final file can only played well by VLC
and web browser. I want to know what is the problem?


Thanks,
Jianwen

Matthew Heaney

unread,
May 20, 2011, 10:43:58 AM5/20/11
to WebM Discussion
On Thu, May 19, 2011 at 9:07 PM, jianwen chen
<jianwen.c...@gmail.com> wrote:
> I have 2 webm files on hand, I want to concatenate them by
> concatenating the segments in each file.

The new file would comprise a single segment synthesized from the
clusters in the segments of the original files.


> According to the Matroska specification, I know a live stream is
> designated by setting the “Segment” size to “unknown”.

Right, a value of -1 (you can use a single byte for this).

You can also set each cluster size to -1.


> I manually set
> the size of each segment to a very large value and setting the
> duration of the segments to 100 hours.

This might break parsers that compare the file size to the size
reported by the segment. If the segment size is larger than the file
size, a parser might assume that the file has been truncated and
refuse to parse it.

If you don't know the segment size a priori, and you are writing to an
output media that is non-seekable, then just set the segment size to
"unknown" (-1).


> And I also delete the
> “SeekHead” elements and “Cues” elements in 2 mkv files.

Right, they aren't needed.


> I have no
> cluster in the webm files.

I don't know what this means. You must have at least one cluster.


> But only the 1st segment in the final file can only played well by VLC
> and web browser. I want to know what is the problem?

You cannot simply concatenate the files. If you do that, the most
likely behavior is that a parser will render the first segment in the
file, and ignore the others.

It might be the case that some parsers are very liberal in what they
accept, and, noticing that an EBML header and Segment elements follow
the end of the first Segment (instead of reaching EOF, which is
canonical), and guess that this complex file is the concatenation of
simpler files, but you should not assume this.

I have a simple program that concatenates WebM files. I can include
it among the libwebm sources, if you like. If you're interested, file
a bug report requesting that a "webm concatenation program" be
included among the samples in the libwebm project, and assign the bug
report to me.

-Matt

Ryan Thompson

unread,
May 20, 2011, 11:12:07 AM5/20/11
to WebM Discussion
The behavior you are seeing is not surprising. When you do this you
have to keep a couple things in mind:
Header metadata for the vorbis audio may not be consistent through the
two streams. This would cause issue with playback when a stream is
different.

Also keep in mind that for this to work the streams in general should
be identical, audio sample rate, video resolution etc. Depending on
how the files were created other initialized metadata could cause you
issues.

Good luck.
Reply all
Reply to author
Forward
0 new messages