AVbin Needs Help

314 views
Skip to first unread message

Nathan

unread,
Sep 27, 2013, 7:26:22 PM9/27/13
to pyglet...@googlegroups.com
I am going to go ahead and start a new thread in response to this statement:

On Thu, Sep 26, 2013 at 10:39 AM, John Duprey <john....@gmail.com> wrote:

Likewise, there are issues with avbin (that pyglet depends on) that seem to be long standing.


Yep, and I'm stumped.  I've spent over 100 hours looking into it and attempting to code a fix.  I learned a ton about Libav and about C and ended up refactoring a lot of the fundamentals of AVbin (in experimental branches) in an attempt to fix the underlying cause of all the problems (as I understand it) and ended up with...very similar buggy behavior as I started with and no more ideas as to why.

I'd be happy to discuss the problems with anyone who would be willing to jump in and help with the C code.  I believe I need to commit my latest branches of refactoring attempts, though.

I picked up maintainership of AVbin 1) to learn, 2) for fun, 3) to ensure it would keep working with new versions of everything else, and most importantly 4) because no one else would.

#1 has been accomplished.  #2 is over.  It's no longer fun for me and I'm not willing to invest any more weeks trying to bang my head against it.  I've spent a couple years trying to fix AVbin and Pyglet so that I could code what I want with them instead of coding what I want with them.  I'm done with that.

Either someone (or some people) pitch in and help get past this hurdle, or AVbin is simply going to sit and remain in it's partially functional state until the OS's pass it by completely.  I'm not going to take the couple hours to writeup all my findings unless someone is willing to actually do something with them.

At this point I'd be fine transferring control of the project back to Richard Jones if that would help anything.

I'm willing to continue to do standard maintenance, updates, and providing binary packages if no one else will take it (I'm pretty good at that stuff).  But I can't pretend I currently have sufficient skill in C and Libav to fix the outstanding issues.

~ Nathan

Paul Colomiets

unread,
Sep 27, 2013, 7:59:10 PM9/27/13
to pyglet...@googlegroups.com
Hi Nathan,
I can't spend too much time on this, but probably I can help you with
some C code. Since avbin is about five hundred lines of code is
shouldn't be a problem.

BTW, can avbin be a source of but of randomly stopping sounds on OS X?

--
Paul

Nathan

unread,
Sep 27, 2013, 11:44:11 PM9/27/13
to pyglet...@googlegroups.com
Ya, it can be.

~ Nathan



--
Paul

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyglet-users...@googlegroups.com.
To post to this group, send email to pyglet...@googlegroups.com.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Nathan

unread,
Sep 27, 2013, 11:58:49 PM9/27/13
to pyglet...@googlegroups.com
If you want to see my refactoring attempt see:

- branch "refactoring_attempt" branch from AVbin: https://github.com/AVbin/AVbin
- branch "avbin_refactoring_attempt" branch from my experimental fork of pyglet: https://github.com/agileperception/pyglet

Instead of try to do an extensive writeup, I'll just say that I figured that the root of the problem was that AVbin was only grabbing the raw data buffer and the size from the AVframe, and constructing a new AVframe with all default values except the data buffer and size attribute.  Everything else centered around that assumption.

~ Nathan

"Juan J. Martínez"

unread,
Sep 28, 2013, 2:47:02 AM9/28/13
to pyglet...@googlegroups.com
On 28/09/13 00:59, Paul Colomiets wrote:
> [...]
>
> I can't spend too much time on this, but probably I can help you with
> some C code. Since avbin is about five hundred lines of code is
> shouldn't be a problem.

I'm in the same position. I'm mainly a C guy struggling to write some
Python code, so I'd be happy to help.

I'm already trying to help with Pyglet, I don't know if getting too
involved with ABvin would be too much :(

I can help, but I don't think I can take over. Also I can't help in Mac,
but I'm OK with any of the other two platforms.

Btw, as pyglet user I own you a lot. Thanks a lot for you awesome work!

Regards,

Juan

--
jjm's home: http://www.usebox.net/jjm/
blackshell: http://blackshell.usebox.net/

Paul Colomiets

unread,
Sep 28, 2013, 12:56:32 PM9/28/13
to pyglet...@googlegroups.com
Hi Nathan,

On Sat, Sep 28, 2013 at 6:58 AM, Nathan <nathan...@gmail.com> wrote:
> If you want to see my refactoring attempt see:
>
> - branch "refactoring_attempt" branch from AVbin:
> https://github.com/AVbin/AVbin
> - branch "avbin_refactoring_attempt" branch from my experimental fork of
> pyglet: https://github.com/agileperception/pyglet
>
> Instead of try to do an extensive writeup, I'll just say that I figured that
> the root of the problem was that AVbin was only grabbing the raw data buffer
> and the size from the AVframe, and constructing a new AVframe with all
> default values except the data buffer and size attribute. Everything else
> centered around that assumption.

Sounds too simple to be true :)

Can you point on issue or a test case for that? Is it #41 on github?

--
Paul

Nathan

unread,
Sep 28, 2013, 2:02:40 PM9/28/13
to pyglet...@googlegroups.com
I created a new issue (#54) for it: https://github.com/AVbin/AVbin/issues/54

In the issue I put a link to the three files that I have personally used to see the bad behavior and test my fix attempts.  All three of these files were given to me by actual users who were frustrated that they were not decoding and playing correctly.

~ Nathan



--
Paul

Paul Colomiets

unread,
Sep 28, 2013, 6:01:41 PM9/28/13
to pyglet...@googlegroups.com
Hi Nathan,

On Sat, Sep 28, 2013 at 9:02 PM, Nathan <nathan...@gmail.com> wrote:
> I created a new issue (#54) for it: https://github.com/AVbin/AVbin/issues/54
>
> In the issue I put a link to the three files that I have personally used to
> see the bad behavior and test my fix attempts. All three of these files
> were given to me by actual users who were frustrated that they were not
> decoding and playing correctly.

Although, AVPacket usage in avbin is wrong, and there are other memory
management errors. The actual cause of bad playback is skipping
packets. The following patch fixes the issues with both videos (not
sure why audio fails yet):

diff -r 056abb79c86b pyglet/media/avbin.py
--- a/pyglet/media/avbin.py Thu Aug 15 23:58:18 2013 +0300
+++ b/pyglet/media/avbin.py Sun Sep 29 00:51:14 2013 +0300
@@ -374,12 +374,13 @@

if self._packet.stream_index == self._video_stream_index:
if self._packet.timestamp < 0:
+ print("TIMESTAMP", self._packet.timestamp)
# XXX TODO
# AVbin needs hack to decode timestamp for B frames in
# some containers (OGG?). See
# http://www.dranger.com/ffmpeg/tutorial05.html
# For now we just drop these frames.
- return None, None
+ # return None, None

video_packet = VideoPacket(self._packet)

I may investigate more later. Just keeping you informed.


--
Paul

Nathan

unread,
Sep 28, 2013, 6:37:35 PM9/28/13
to pyglet...@googlegroups.com
That change has absolutely no effect on my testing on OS 10.8, 64-bit.  Odd.

I'm looking at jwpIntro.mov, specifically.  The sound plays normally, but the video starts with a green screen, resolves to a mostly normal picture less than a second later, and plays sort of correctish, just behind the audio and some glitches here and there.

~ Nathan




--
Paul

Paul Colomiets

unread,
Sep 28, 2013, 6:46:13 PM9/28/13
to pyglet...@googlegroups.com
Hm, I'm testing on Linux, bug was like you've described, and fixed
with this change.

Sounds on OS X work badly (same app that in runs smoothly on linux),
so may be OS X have it's own issues because of different memory
management or something else. Will test on OS X later.
--
Paul

Paul Colomiets

unread,
Sep 30, 2013, 5:17:38 AM9/30/13
to pyglet...@googlegroups.com
Hi Nathan,

On Sun, Sep 29, 2013 at 1:37 AM, Nathan <nathan...@gmail.com> wrote:
> That change has absolutely no effect on my testing on OS 10.8, 64-bit. Odd.
>
> I'm looking at jwpIntro.mov, specifically. The sound plays normally, but
> the video starts with a green screen, resolves to a mostly normal picture
> less than a second later, and plays sort of correctish, just behind the
> audio and some glitches here and there.

Just tested on OS X. It works like a charm. May be patch was garbled
in email or you haven't appropriately reinstalled the pyglet? The
point is to remove skipping packets by timestamp at line 376. Try the
attached patch.


--
Paul
ts.patch

Paul Colomiets

unread,
Sep 30, 2013, 6:44:04 AM9/30/13
to pyglet...@googlegroups.com
Hi Nathan,
BTW, I'm playing the movie with "examples/media_player.py". May be you
use another player?

--
Paul

"Juan J. Martínez"

unread,
Sep 30, 2013, 12:51:52 PM9/30/13
to pyglet...@googlegroups.com
I've tried the patch and the mp3 plays fine (I couldn't detect any
glitch before the patch) and the video plays perfect with the patch (it
actually fixes the glitch).

I'm using media_player.py for the tests.

Paul Colomiets

unread,
Sep 30, 2013, 2:33:56 PM9/30/13
to pyglet...@googlegroups.com
Hi,

On Mon, Sep 30, 2013 at 7:51 PM, "Juan J. Martínez" <j...@usebox.net> wrote:
> I've tried the patch and the mp3 plays fine

For me it plays fine on some version of AVbin (don't remember which
one), on another it crashes and on git master there is no sound but it
doesn't crash.

> (I couldn't detect any
> glitch before the patch) and the video plays perfect with the patch (it
> actually fixes the glitch).
>

Nathan, any comments?

--
Paul

"Juan J. Martínez"

unread,
Sep 30, 2013, 2:49:27 PM9/30/13
to pyglet...@googlegroups.com
On 30/09/13 19:33, Paul Colomiets wrote:
> Hi,
>
> On Mon, Sep 30, 2013 at 7:51 PM, "Juan J. Mart�nez" <j...@usebox.net> wrote:
>> I've tried the patch and the mp3 plays fine
>
> For me it plays fine on some version of AVbin (don't remember which
> one), on another it crashes and on git master there is no sound but it
> doesn't crash.

In case it helps: I'm running AVbin 11 alpha 4 in Linux 32-bit.

Nathan

unread,
Sep 30, 2013, 5:47:15 PM9/30/13
to pyglet...@googlegroups.com
I'll check it out tonight after work (6 hours or so from now).

~ Nathan 

Nathan

unread,
Oct 1, 2013, 2:02:29 PM10/1/13
to pyglet...@googlegroups.com
Sorry I didn't make it to testing this last night -- real life intervened.

I didn't realize you were using the vanilla pyglet and avbin (before my refactoring attempt, I mean).  So I added your patch to my pre-refactoring-attempt pyglet fork, backed AVbin up to the last change before the big refactoring attempt, and the video plays smoothly on jwpIntro.mov!  Unfortunately, the audio is out of sync.  :-(  That seems to be the theme.  The (silent) video porosity.mp4 now plays correctly, but the problem MP3 tetris.mp3 (it has album art) doesn't play at all.

Any ideas about the sound issues?

~ Nathan




--
Paul

Paul Colomiets

unread,
Oct 2, 2013, 5:45:09 AM10/2/13
to pyglet...@googlegroups.com
Hi Nathan,

On Tue, Oct 1, 2013 at 9:02 PM, Nathan <nathan...@gmail.com> wrote:
> Unfortunately, the audio is out of sync. :-(

Yeah, probably that negative timestamp is sign of some other issue.

> That seems to
> be the theme. The (silent) video porosity.mp4 now plays correctly, but the
> problem MP3 tetris.mp3 (it has album art) doesn't play at all.
>
> Any ideas about the sound issues?

I think we need to fix memory management issues, and that goes away,
along with negative timestamp. What we think about API/ABI
compatibility? You branch changes API in quite subtle way, so that
pyglet can probably crash using wrong version of AVbin. But still API
change is needed to fix issues. How would we do that? Add new function
calls that only new pyglet can take advantage of?

--
Paul

Nathan

unread,
Oct 2, 2013, 12:15:32 PM10/2/13
to pyglet...@googlegroups.com
I'm not opposed to breaking the API/ABI compatibility if it can solve the problems in a stable way going forward.  There's no point in having a completely stable API/ABI to a library with showstopper bugs.  Alex's goal of not changing the API has succeeded for about 7 years, which is pretty amazing given some of the changes that have occurred.

I can't speak to specific implementation of a fix until I understand the problem.  Do you see what's wrong, specifically?  Don't be afraid to fork AVbin on GitHub and try different things.

~ Nathan



--
Paul

Reply all
Reply to author
Forward
0 new messages