Re: How do I seek to seek to specific samples using libvorbis?
"Madison Link" <[email protected]> Tue, 19 May 2015 10:00:23 -0600
| Newsgroups | gmane.comp.multimedia.ogg.vorbis.general |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --===============1571508017== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0015_01D0921A.A0EA9EC0" This is a multi-part message in MIME format. ------=_NextPart_000_0015_01D0921A.A0EA9EC0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Right, but do I start from the beginning of the page? Do I start from the end of the previous page? Is there some way to reliably start at a packet immediately before the one I want (and to know which sample I'm starting at once I get sound out.) Here's my goal, setup, and the problems I'm having. I want to grab the audio and video out of a file in bite-sized chunks I'm calling "frames." If a file has video, one audio frame should be the audio that goes with one video frame. Otherwise, each audio frame is 1/25th of a second. I want to be able to seek into the middle of a file and return the Nth frame of audio and video. Specifically, If I grab the audio frames in a random order, I want to be able to assemble them into the correct and complete audio, so the start of each frame has to be exact. When opening the file, I read though the packets, getting their block sizes, translating that to samples (including the fact that I don't get any samples on the first packet, and that after that the samples returned seem to be the average of the packet size and the packet before it) and creating an index point every 1/10th of a second. The index contains the file position of the page the packet is on, the number of the packet on the page that contains the indexed sample, and the sample count up to the beginning of the packet. When I want to seek to a frame, I get the index point before it, reset the decoder, and read off packets, using the block size to calculate my way forward until I'm at packet that begins the frame. I store a few packets at a time so that I can decode the two packets prior to the frame before beginning the frame. In practice, though, sometimes I'll get "OV not audio" when I put in an audio packet that is in the middle of an audio page, or I'll put in a packet that was originally sized as 2048 floats and I'll get back information that its 256 floats. This throws off my calculations and I'll end up in the middle of a frame instead of at the beginning. I'm willing to believe that there's a bug in the way I'm grabbing packets, except for the fact that when I decode straight through, every thing works. Also, my code never misidentifies packets after I start decoding, only when I'm reading and bypassing. Other times, the "frame" I get out after seeking bears no relationship to the one I get when I make a straight-through decode. I've compared files created by reading straight through an ogg file vs. seeking every frame, and compared them with a hex editor. In some places, the pcm samples match perfectly, and are in the same position. In other places, the pcm samples match, but are offset, and in other places the pcm samples from the seek file simply don't match those from the read file. I've spent a couple of weeks now on this specific part of the problem, and would like some official, "here's how you do it." Quite frankly, I'm surprised that this aspect of vorbis decoding (seeking to a specific point in the file) is not explained anywhere in the xiph documentation. Maybe I missed it? Again, some help would be appreciated. Thanks, Madison _____ From: Sergei Steshenko [mailto:[email protected]] Sent: Monday, May 18, 2015 8:57 PM To: Madison Link; [email protected] Subject: Re: [Vorbis] How do I seek to seek to specific samples using libvorbis? I am no Vorbis developer, and I have never looked into the details of Ogg-Vorbis implementation, but since Ogg-Vorbis is a lossy format, there is no one to one correspondence of PCM samples and bytes in the stream. Ogg-Vorbis is also a variable bitrate format. I mean that first the stream has to be reconstituted into uncompressed PCM samples, and only then you can get to the desired sample. Regards, Sergei. _____ From: Madison Link <[email protected]> To: [email protected] Sent: Tuesday, May 19, 2015 3:38 AM Subject: [Vorbis] How do I seek to seek to specific samples using libvorbis? What is the best practice for seeking to a specific (arbitrary) PCM sample in an Ogg file that contains vorbis, using libvorbis? _______________________________________________ Vorbis mailing list [email protected] http://lists.xiph.org/mailman/listinfo/vorbis ------=_NextPart_000_0015_01D0921A.A0EA9EC0 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <html xmlns:v=3D"urn:schemas-microsoft-com:vml" = xmlns:o=3D"urn:schemas-microsoft-com:office:office" = xmlns:w=3D"urn:schemas-microsoft-com:office:word" = xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" = xmlns=3D"http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=3DContent-Type content=3D"text/html; = charset=3Dus-ascii"> <meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)"> <!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]--><o:SmartTagType namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags" = name=3D"City"/> <o:SmartTagType = namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags" name=3D"place"/> <o:SmartTagType = namespaceuri=3D"urn:schemas-microsoft-com:office:smarttags" name=3D"PersonName"/> <!--[if !mso]> <style> st1\:*{behavior:url(#default#ieooui) } </style> <![endif]--> <style> <!-- _filtered #yiv2438338505 {margin:1.0in 1.25in 1.0in 1.25in;} /* Font Definitions */ @font-face {font-family:Helvetica; panose-1:2 11 6 4 2 2 2 2 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:blue; text-decoration:underline;} p.yiv2438338505msonormal, li.yiv2438338505msonormal, = div.yiv2438338505msonormal {mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; font-size:12.0pt; font-family:"Times New Roman";} p.yiv2438338505msonormal1, li.yiv2438338505msonormal1, = div.yiv2438338505msonormal1 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} p.yiv2438338505msonormal2, li.yiv2438338505msonormal2, = div.yiv2438338505msonormal2 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} p.yiv2438338505msonormal3, li.yiv2438338505msonormal3, = div.yiv2438338505msonormal3 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} p.yiv2438338505msonormal4, li.yiv2438338505msonormal4, = div.yiv2438338505msonormal4 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} p.yiv2438338505msonormal5, li.yiv2438338505msonormal5, = div.yiv2438338505msonormal5 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} span.yiv2438338505msohyperlink1 {color:blue; text-decoration:underline;} p.yiv2438338505msonormal6, li.yiv2438338505msonormal6, = div.yiv2438338505msonormal6 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} span.yiv2438338505msohyperlink2 {color:blue; text-decoration:underline;} p.yiv2438338505msonormal7, li.yiv2438338505msonormal7, = div.yiv2438338505msonormal7 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} span.yiv2438338505msohyperlink3 {color:blue; text-decoration:underline;} span.yiv2438338505msohyperlinkfollowed1 {color:purple; text-decoration:underline;} p.yiv2438338505msonormal8, li.yiv2438338505msonormal8, = div.yiv2438338505msonormal8 {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} span.yiv2438338505msohyperlink4 {color:blue; text-decoration:underline;} span.yiv2438338505msohyperlinkfollowed2 {color:purple; text-decoration:underline;} span.yiv2438338505emailstyle171 {font-family:Arial; color:windowtext;} span.EmailStyle36 {mso-style-type:personal-reply; font-family:Arial; color:navy;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in;} div.Section1 {page:Section1;} --> </style> </head> <body lang=3DEN-US link=3Dblue vlink=3Dblue> <div class=3DSection1> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>Right, but do I start from the = beginning of the page? Do I start from the end of the previous page? = Is there some way to reliably start at a packet immediately before the one I want = (and to know which sample I'm starting at once I get sound = out.)<o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>Here's my goal, setup, and the = problems I'm having.<o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>I want to grab the audio and video = out of a file in bite-sized chunks I'm calling "frames." If a = file has video, one audio frame should be the audio that goes with one video frame. Otherwise, each audio frame is 1/25th of a second. I = want to be able to seek into the middle of a file and return the Nth frame of = audio and video. Specifically, If I grab the audio frames in a random order, = I want to be able to assemble them into the correct and complete audio, so the = start of each frame has to be exact.<o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>When opening the file, I read = though the packets, getting their block sizes, translating that to samples = (including the fact that I don't get any samples on the first packet, and that after = that the samples returned seem to be the average of the packet size and the = packet before it) and creating an index point every 1/10th of a second. = The index contains the file position of the page the packet is on, the = number of the packet on the page that contains the indexed sample, and the sample = count up to the beginning of the packet. When I want to seek to a frame, = I get the index point before it, reset the decoder, and read off packets, = using the block size to calculate my way forward until I'm at packet that begins = the frame. I store a few packets at a time so that I can decode the = two packets prior to the frame before beginning the = frame.<o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>In practice, though, sometimes I'll = get "OV not audio" when I put in an audio packet that is in the = middle of an audio page, or I'll put in a packet that was originally sized as 2048 = floats and I'll get back information that its 256 floats. This throws off = my calculations and I'll end up in the middle of a frame instead of at the = beginning. I'm willing to believe that there's a bug in the way I'm grabbing packets, = except for the fact that when I decode straight through, every thing = works. Also, my code never misidentifies packets after I start decoding, only = when I'm reading and bypassing.<o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>Other times, the "frame" = I get out after seeking bears no relationship to the one I get when I make a straight-through decode. I've compared files created by reading = straight through an ogg file vs. seeking every frame, and compared them with a = hex editor. In some places, the pcm samples match perfectly, and are = in the same position. In other places, the pcm samples match, but are = offset, and in other places the pcm samples from the seek file simply don't = match those from the read file. I've spent a couple of weeks now on this = specific part of the problem, and would like some official, "here's how you = do it." Quite frankly, I'm surprised that this aspect of vorbis decoding (seeking to a specific point in the file) is not explained = anywhere in the xiph documentation. Maybe I missed = it?<o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>Again, some help would be = appreciated.<o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'>Thanks, = <o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><st1:City w:st=3D"on"><st1:place w:st=3D"on"><font = size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:10.0pt;font-family:Arial; color:navy'>Madison</span></font></st1:place></st1:City><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size:10.0pt;font-family:Arial; color:navy'><o:p></o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <p class=3DMsoNormal><font size=3D2 color=3Dnavy face=3DArial><span = style=3D'font-size: 10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p> <div> <div class=3DMsoNormal align=3Dcenter style=3D'text-align:center'><font = size=3D3 face=3D"Times New Roman"><span style=3D'font-size:12.0pt'> <hr size=3D2 width=3D"100%" align=3Dcenter tabindex=3D-1> </span></font></div> <p class=3DMsoNormal><b><font size=3D2 face=3DTahoma><span = style=3D'font-size:10.0pt; font-family:Tahoma;font-weight:bold'>From:</span></font></b><font = size=3D2 face=3DTahoma><span style=3D'font-size:10.0pt;font-family:Tahoma'> = Sergei Steshenko [mailto:[email protected]] <br> <b><span style=3D'font-weight:bold'>Sent:</span></b> Monday, May 18, = 2015 8:57 PM<br> <b><span style=3D'font-weight:bold'>To:</span></b> Madison Link; = <st1:PersonName w:st=3D"on">[email protected]</st1:PersonName><br> <b><span style=3D'font-weight:bold'>Subject:</span></b> Re: [Vorbis] How = do I seek to seek to specific samples using = libvorbis?</span></font><o:p></o:p></p> </div> <p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span = style=3D'font-size: 12.0pt'><o:p> </o:p></span></font></p> <div> <div id=3D"yui_3_16_0_1_1432002768159_3394"> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'>I am no Vorbis developer, and I have never looked into the details of = Ogg-Vorbis implementation, but since Ogg-Vorbis is a lossy format, there is no one = to one correspondence of PCM samples and bytes in the stream. Ogg-Vorbis is = also a variable bitrate format.<br> <br> <o:p></o:p></span></font></p> </div> </span> <div id=3D"yui_3_16_0_1_1432002768159_3458"> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'><br> <br> <o:p></o:p></span></font></p> </div> <span id=3D"yui_3_16_0_1_1432002768159_3430"></span><span id=3D"yui_3_16_0_1_1432002768159_3430"> <div id=3D"yui_3_16_0_1_1432002768159_3512"> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'>I mean that first the stream has to be reconstituted into uncompressed PCM samples, and only then you can get to the desired = sample.</span><o:p></o:p></span></font></p> </div> <div id=3D"yui_3_16_0_1_1432002768159_3541"> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'><o:p> <= /o:p></span></font></p> </div> <div id=3D"yui_3_16_0_1_1432002768159_3542"> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'>Regards,<o:p= ></o:p></span></font></p> </div> <div id=3D"yui_3_16_0_1_1432002768159_3543"> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'> Sergei.<o:p></o:p></span></font></p> </div> <div> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'><o:p> <= /o:p></span></font></p> </div> <blockquote style=3D'border:none;border-left:solid #1010FF = 1.5pt;padding:0in 0in 0in 4.0pt; margin-left:3.75pt;margin-top:3.75pt;margin-bottom:5.0pt' id=3D"yui_3_16_0_1_1432002768159_3398"> <div id=3D"yui_3_16_0_1_1432002768159_3397"> <div id=3D"yui_3_16_0_1_1432002768159_3396"> <div id=3D"yui_3_16_0_1_1432002768159_3395"> <div class=3DMsoNormal align=3Dcenter = style=3D'text-align:center;background:white'><font size=3D3 color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family: Helvetica;color:black'> <hr size=3D1 width=3D"100%" align=3Dcenter = id=3D"yui_3_16_0_1_1432002768159_3399"> </span></font></div> <p class=3DMsoNormal style=3D'background:white'><b><font size=3D2 = color=3Dblack face=3DArial><span = style=3D'font-size:10.0pt;font-family:Arial;color:black; font-weight:bold'>From:</span></font></b><font size=3D2 color=3Dblack = face=3DArial><span style=3D'font-size:10.0pt;font-family:Arial;color:black'> Madison Link = <<st1:PersonName w:st=3D"on">[email protected]</st1:PersonName>><br> <b><span style=3D'font-weight:bold'>To:</span></b> <st1:PersonName = w:st=3D"on">[email protected]</st1:PersonName> <br> <b><span style=3D'font-weight:bold'>Sent:</span></b> Tuesday, May 19, = 2015 3:38 AM<br> <b><span style=3D'font-weight:bold'>Subject:</span></b> [Vorbis] How do = I seek to seek to specific samples using libvorbis?</span></font><font = color=3Dblack face=3DHelvetica><span = style=3D'font-family:Helvetica;color:black'><o:p></o:p></span></font></p>= </div> <div id=3D"yui_3_16_0_1_1432002768159_3431"> <p class=3DMsoNormal style=3D'background:white'><font size=3D3 = color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica;color:black'><o:p> <= /o:p></span></font></p> <div id=3Dyiv2438338505> <div> <div> <div> <p class=3DMsoNormal style=3D'background:white'><font size=3D2 = color=3Dblack face=3DArial><span = style=3D'font-size:10.0pt;font-family:Arial;color:black'>What is the best practice for seeking to a specific (arbitrary) PCM sample in an = Ogg file that contains vorbis, using libvorbis?</span></font><font = color=3Dblack face=3DHelvetica><span = style=3D'font-family:Helvetica;color:black'><o:p></o:p></span></font></p>= </div> </div> </div> </div> <p class=3DMsoNormal = style=3D'margin-bottom:12.0pt;background:white'><font size=3D3 color=3Dblack face=3DHelvetica><span = style=3D'font-size:12.0pt;font-family:Helvetica; color:black'><br> _______________________________________________<br> Vorbis mailing list<br> <a href=3D"mailto:[email protected]" = ymailto=3D"mailto:[email protected]">[email protected]</a><br> <a href=3D"http://lists.xiph.org/mailman/listinfo/vorbis" = target=3D"_blank" id=3D"yui_3_16_0_1_1432002768159_3558">http://lists.xiph.org/mailman/list= info/vorbis</a><br> <br> <o:p></o:p></span></font></p> </div> </div> </div> </blockquote> </div> </div> </body> </html> ------=_NextPart_000_0015_01D0921A.A0EA9EC0-- --===============1571508017== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Vorbis mailing list [email protected] http://lists.xiph.org/mailman/listinfo/vorbis --===============1571508017==--