Re: Webm files written without duration in header

Sytze Visser <[email protected]> Thu, 2 May 2019 13:14:30 +0200
Newsgroups gmane.comp.audio.icecast.devel
Message-ID <[email protected]>
--===============7908283351341419840==
Content-Type: multipart/alternative;
	boundary="_6A2D929C-89AC-4100-8FDF-B8FDB68EE953_"

--_6A2D929C-89AC-4100-8FDF-B8FDB68EE953_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"

Hey Roger and everyone else commenting =E2=80=93 I appreciate all the advic=
e and=20
questions.

I now have more work than before =F0=9F=98=8A!

Greetings from sunny South Africa!

Sent from Mail for Windows 10

From: Roger H=C3=A5gensen
Sent: Thursday, May 2, 2019 12:12 PM
To: [email protected]
Subject: Re: [Icecast-dev] Webm files written without duration in header

On 2019-05-01 11:58, Sytze Visser wrote:> I am streaming live with webm=20
with ffmpeg to icecast 2.4.2. After the
 > stream ends, I am unable to determine the duration of the file using
 > ffprobe or mediainfo. Not sure but it seems that this has to do with
 > headers?
 >
 > Should icecast be writing the duration into the header or should this
 > somehow be passed from ffmpeg?
Do you mean the stream you sent to icecast or the stream listeners get=20
from icecast?

If it's the user stream then no, as a listener may drop packets and any=20
length would be incorrect, in this case it is the listeners player that=20
should track duration played (received) and add this to the file header=20
if the player allows archiving of live streams. For livestreams I think=20
Icecast sets a length of -1 (but it could be 0, or no length at all).

If you use a stream capture tool then I'm sure there exists one that=20
will write the duration header to a file. Have you tried using ffmpeg to=20
capture the stream? Look at the manual, you should be able to make it=20
write a duration to the header (if possible/supported by the file format)

 > The requirement is really to determine the duration of the streamed
 > event (i.e. not radio).
If you are using ffmpeg as the stream encoder then you should log the=20
duration either prior to ffmpeg getting the audio or after ffmpeg=20
encoding. There is no way for ffmpeg to magically add a length=20
(duration) to the header (which may have been streamed an hour ago).

If you only want to track duration before streaming it "out", then=20
encode and store the stream locally, then when it ends run a script to=20
add/fix the header to have a duration then stream the file to icecast,=20
this would mean the liveness of the stream would be delayed by the=20
duration of it.

But I doubt you want to do this (why stream live otherwise right?)

I can't recall if you can get ffmpeg to trigger a script or executable=20
when it quits or not, but you could (be it Windows or Linux) easily make=20
a script that you call instead of ffmpeg directly, in the script you log=20
the time before calling ffmepg and again after ffmpeg quits.
If you log as a datestamp you can simply subtract the start value from=20
the end value to get duration. Do note that this may not match the=20
actual duration of the archived stream (even if you archive it straight=20
from ffmpeg), it could be off by a second for example.

You should also consider how to handle things in case ffmpeg crashes or=20
looses the connection to icecast (something sure to happen if using=20
public networks instead of a local LAN).

If a script you can "easily" restart ffmpeg and you can log the start=20
and end time (you could maybe even detect a ffmpeg crash or quit and log=20
a message).

I note you said "streamed event", are you using some form of broadcast=20
software? In that case that should have it's own log for events, or you=20
can set it to trigger a script at the start and end of events.


Regards,
Roger.

--=20
Unless specified otherwise, anything I write publicly is considered=20
Public Domain (CC0). My opinions are my own unless specified otherwise.
Roger H=C3=A5gensen,
Freelancer, Norway.
_______________________________________________
Icecast-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/icecast-dev


--_6A2D929C-89AC-4100-8FDF-B8FDB68EE953_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="utf-8"

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sc=
hemas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/of=
fice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta ht=
tp-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta name=
=3DGenerator content=3D"Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style></head><body lang=3DEN-US link=3Dblue vlink=3D"#954F72"><div cla=
ss=3DWordSection1><p class=3DMsoNormal>Hey Roger and everyone else commenti=
ng =E2=80=93 I appreciate all the advice and </p><p class=3DMsoNormal>quest=
ions.</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>I n=
ow have more work than before <span style=3D'font-family:"Segoe UI Emoji",s=
ans-serif'>&#128522;</span>!</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><=
p class=3DMsoNormal>Greetings from sunny South Africa!</p><p class=3DMsoNor=
mal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>Sent from <a href=3D"https://=
go.microsoft.com/fwlink/?LinkId=3D550986">Mail</a> for Windows 10</p><p cla=
ss=3DMsoNormal><o:p>&nbsp;</o:p></p><div style=3D'mso-element:para-border-d=
iv;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p=
 class=3DMsoNormal style=3D'border:none;padding:0cm'><b>From: </b><a href=
=3D"mailto:[email protected]">Roger H=C3=A5gensen</a><br><b>Sent: </b=
>Thursday, May 2, 2019 12:12 PM<br><b>To: </b><a href=3D"mailto:icecast-dev=
@xiph.org">[email protected]</a><br><b>Subject: </b>Re: [Icecast-dev] We=
bm files written without duration in header</p></div><p class=3DMsoNormal><=
o:p>&nbsp;</o:p></p><p class=3DMsoNormal>On 2019-05-01 11:58, Sytze Visser =
wrote:&gt; I am streaming live with webm </p><p class=3DMsoNormal>with ffmp=
eg to icecast 2.4.2. After the</p><p class=3DMsoNormal> &gt; stream ends, I=
 am unable to determine the duration of the file using</p><p class=3DMsoNor=
mal> &gt; ffprobe or mediainfo. Not sure but it seems that this has to do w=
ith</p><p class=3DMsoNormal> &gt; headers?</p><p class=3DMsoNormal> &gt;</p=
><p class=3DMsoNormal> &gt; Should icecast be writing the duration into the=
 header or should this</p><p class=3DMsoNormal> &gt; somehow be passed from=
 ffmpeg?</p><p class=3DMsoNormal>Do you mean the stream you sent to icecast=
 or the stream listeners get </p><p class=3DMsoNormal>from icecast?</p><p c=
lass=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>If it's the user=
 stream then no, as a listener may drop packets and any </p><p class=3DMsoN=
ormal>length would be incorrect, in this case it is the listeners player th=
at </p><p class=3DMsoNormal>should track duration played (received) and add=
 this to the file header </p><p class=3DMsoNormal>if the player allows arch=
iving of live streams. For livestreams I think </p><p class=3DMsoNormal>Ice=
cast sets a length of -1 (but it could be 0, or no length at all).</p><p cl=
ass=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>If you use a stre=
am capture tool then I'm sure there exists one that </p><p class=3DMsoNorma=
l>will write the duration header to a file. Have you tried using ffmpeg to =
</p><p class=3DMsoNormal>capture the stream? Look at the manual, you should=
 be able to make it </p><p class=3DMsoNormal>write a duration to the header=
 (if possible/supported by the file format)</p><p class=3DMsoNormal><o:p>&n=
bsp;</o:p></p><p class=3DMsoNormal> &gt; The requirement is really to deter=
mine the duration of the streamed</p><p class=3DMsoNormal> &gt; event (i.e.=
 not radio).</p><p class=3DMsoNormal>If you are using ffmpeg as the stream =
encoder then you should log the </p><p class=3DMsoNormal>duration either pr=
ior to ffmpeg getting the audio or after ffmpeg </p><p class=3DMsoNormal>en=
coding. There is no way for ffmpeg to magically add a length </p><p class=
=3DMsoNormal>(duration) to the header (which may have been streamed an hour=
 ago).</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>If=
 you only want to track duration before streaming it &quot;out&quot;, then =
</p><p class=3DMsoNormal>encode and store the stream locally, then when it =
ends run a script to </p><p class=3DMsoNormal>add/fix the header to have a =
duration then stream the file to icecast, </p><p class=3DMsoNormal>this wou=
ld mean the liveness of the stream would be delayed by the </p><p class=3DM=
soNormal>duration of it.</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p cl=
ass=3DMsoNormal>But I doubt you want to do this (why stream live otherwise =
right?)</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>I=
 can't recall if you can get ffmpeg to trigger a script or executable </p><=
p class=3DMsoNormal>when it quits or not, but you could (be it Windows or L=
inux) easily make </p><p class=3DMsoNormal>a script that you call instead o=
f ffmpeg directly, in the script you log </p><p class=3DMsoNormal>the time =
before calling ffmepg and again after ffmpeg quits.</p><p class=3DMsoNormal=
>If you log as a datestamp you can simply subtract the start value from </p=
><p class=3DMsoNormal>the end value to get duration. Do note that this may =
not match the </p><p class=3DMsoNormal>actual duration of the archived stre=
am (even if you archive it straight </p><p class=3DMsoNormal>from ffmpeg), =
it could be off by a second for example.</p><p class=3DMsoNormal><o:p>&nbsp=
;</o:p></p><p class=3DMsoNormal>You should also consider how to handle thin=
gs in case ffmpeg crashes or </p><p class=3DMsoNormal>looses the connection=
 to icecast (something sure to happen if using </p><p class=3DMsoNormal>pub=
lic networks instead of a local LAN).</p><p class=3DMsoNormal><o:p>&nbsp;</=
o:p></p><p class=3DMsoNormal>If a script you can &quot;easily&quot; restart=
 ffmpeg and you can log the start </p><p class=3DMsoNormal>and end time (yo=
u could maybe even detect a ffmpeg crash or quit and log </p><p class=3DMso=
Normal>a message).</p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3D=
MsoNormal>I note you said &quot;streamed event&quot;, are you using some fo=
rm of broadcast </p><p class=3DMsoNormal>software? In that case that should=
 have it's own log for events, or you </p><p class=3DMsoNormal>can set it t=
o trigger a script at the start and end of events.</p><p class=3DMsoNormal>=
<o:p>&nbsp;</o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DM=
soNormal>Regards,</p><p class=3DMsoNormal>Roger.</p><p class=3DMsoNormal><o=
:p>&nbsp;</o:p></p><p class=3DMsoNormal>-- </p><p class=3DMsoNormal>Unless =
specified otherwise, anything I write publicly is considered </p><p class=
=3DMsoNormal>Public Domain (CC0). My opinions are my own unless specified o=
therwise.</p><p class=3DMsoNormal>Roger H=C3=A5gensen,</p><p class=3DMsoNor=
mal>Freelancer, Norway.</p><p class=3DMsoNormal>___________________________=
____________________</p><p class=3DMsoNormal>Icecast-dev mailing list</p><p=
 class=3DMsoNormal>[email protected]</p><p class=3DMsoNormal>http://list=
s.xiph.org/mailman/listinfo/icecast-dev</p><p class=3DMsoNormal><o:p>&nbsp;=
</o:p></p></div></body></html>=

--_6A2D929C-89AC-4100-8FDF-B8FDB68EE953_--


--===============7908283351341419840==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSWNlY2FzdC1k
ZXYgbWFpbGluZyBsaXN0CkljZWNhc3QtZGV2QHhpcGgub3JnCmh0dHA6Ly9saXN0cy54aXBoLm9y
Zy9tYWlsbWFuL2xpc3RpbmZvL2ljZWNhc3QtZGV2Cg==

--===============7908283351341419840==--