1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Streambaby - new streaming application

Discussion in 'TiVo Home Media Features & TiVoToGo' started by kearygriffin, Jan 20, 2009.

  1. Jan 22, 2009 #101 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    This is a problem I have seen before with a couple of MP4 files. I actually have one that causes this issue, and plan on trying to decipher what causes it, but it may take some time-- I spent a while on it already and didn't really get anywhere yet. Sorry.

    I think I know what this probably is. If I'm right, the next version should take care of it.
     
  2. Jan 23, 2009 #102 of 3415
    Yoav

    Yoav New Member

    1,048
    0
    Jan 12, 2007
    Hmm.. Interesting. When I build the code myself, it loads the dynamic libraries fine.

    When I use the precompiled distribution you have, it doesn't.

    I guess for now I'll just manually build releases as they come.. I'm really not that java-clueful. The good news is it's working now. So uploading a new beta of pyTivoX.
    :)
     
  3. Jan 23, 2009 #103 of 3415
    cahoon

    cahoon New Member

    19
    0
    Nov 1, 2007
    I've run into this problem on a couple of mp4 files. Looks like there's an off-by-one error in trak_write_index method. I changed the code at line 1248 to use end - 1 and at line 1252 to end - 2.

    Code:
    			for (s = start; s != end - 1; ++s) {
    				long sample_count = 1;
    				long sample_duration = trak.samples_[(int) (s + 1)].pts_
    						- trak.samples_[(int) s].pts_;
    				while (s != end - 2) {
    
    
    There is a similar issue in the loop at line 1303 and 1306.
    Code:
    				for (s = start; s != end - 1; ++s) {
    					long sample_count = 1;
    					long sample_offset = trak.samples_[(int) s].cto_;
    					while (s != end - 2) {
    
    
    After those changes, it worked for me. I need to think about this a little to be 100% sure that it's the correct fix. I think the problem occurs when the sample count of the last stts or ctts entry is 1.

    BTW, this is a fantastic app - great job!
     
  4. Jan 23, 2009 #104 of 3415
    westside_guy

    westside_guy Annoyingly ephemeral

    464
    1
    Mar 13, 2005
    The soggy...
    Hey,

    I was watching a .m4v file (h.264 mp4 w/ ac3 passthrough - 2500kbps framerate) that I'd ripped from DVD, and noticed that the sound was out of synch with the characters lip movements to varying degrees. I didn't think this had happened with tivostream, so I stopped streambaby, ran qt-faststart on the m4v file and then watched it via tivostream - no synch issues. Then, since this technically wasn't the same file as I'd first watched (cuz of qt-faststart), I went back to streambaby and watched it - again, there were synch issues for a good bit of the show.

    I watched a second video with streambaby, and again noticed synch issues - sometimes things were in synch, but most of the time they were off by at least a small amount (and in places it was quite bad).

    Any ideas?
     
  5. Jan 23, 2009 #105 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    Thanks Cahoon! I made the changes and tried some of my problematic MP4's and they seem to work great. I'll do some more testing, but I expect that I won't find any issues and will include this in the next release.

    It's really nice to go to sleep worrying about trying to debug an issue, and wake up to find it solved!
     
  6. Jan 23, 2009 #106 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    That really is strange (I think...) I really can't imagine why building a java app one the mac (or your machine in particular) as opposed to a linux build of a java app would make any difference for something like this. Are you still using the standard ant build.xml to build streambaby, or are you compiling it through some other environment and putting it together yourself?

    One question-- In some of your earlier posts you were printing stack traces & debug information that it looks like you put into the code yourself, and you were still having an issue. I am assuming those builds were builds you made on your machine. Is there any difference between those test builds that didn't work and the new builds that seem to work?
     
  7. Jan 23, 2009 #107 of 3415
    cahoon

    cahoon New Member

    19
    0
    Nov 1, 2007
    Hmm, I'm wondering if adding mp4module.interleave=false to the config file will help.

    I think that streambaby performs some processing on the mp4 file even when playing from the start. As part of the processing, streambaby re-interleaves the movie data. So, the file sent to Tivo from streambaby could be different than the file sent from tivostream. I'm guessing that after disabling the interleaving, the file sent by streambaby is the same as the original (and the same as the one sent by tivostream) when starting the movie from the beginning.
     
  8. Jan 23, 2009 #108 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    Were the sync issues there both when watching from the beginning of the video and when you jump/start from a position somewhere inside the video?

    I don't have any ideas off the top of my head, but it could be the pseudo-streaming MP4 code (the movies get run through it even when starting from the beginning)

    One thing that may be useful to try is to process the MP4 through the pseudo-streaming code and then try it in tivostream. This should tell us whether or not the pseudo-streaming code is responsible for the synch issues. You can run a movie through the pseudo-streaming code with the following command:
    streambaby --test mp4copy src.mp4 dst.mp4 startposition

    Where src.mp4 is the original mp4, dst.mp4 will be the video after it has been processed through the pseudo-streaming code, and startposition is a time in milliseconds to start the copy from. (so seconds*1000. 3000000 would be 50 minutes into the video for example)

    If you then try to stream dst.mp4 through tivostream I'd be interested in the results.

    EDIT: Just saw cahoon's message about the reinterleaving and thats definitely a possibility. Also note the mp4copy command from above always uses reinterleaving (so acts like mp4module.interleave=true, regardless of what it is set to) and doesn't adhere to the streambaby.ini interleave setting.

    And just to give an explanation for why the reinterleaving is there, for some reason a lot of my MP4's were interleaved OK in the beginning of the file, but would drift as you got further into the movie. So after positioning to say 50 minutes into the movie, the first video sample might be right at the beginning of the file, but the first audio sample might be 45 megabytes after that. Tivo really didn't like this. (It was OK if you started from the beginning, I am assuming because it would have enough buffered to handle the 45 megabyte difference)
     
  9. Jan 23, 2009 #109 of 3415
    Yoav

    Yoav New Member

    1,048
    0
    Jan 12, 2007
    I build using ant, I did have to make one 'tiny' change to the custom-build.xml file that you had in ffmpeg-java (add
    Code:
                                   <pathelement location="build/classes"/>
                                    <pathelement location="lib/jna.jar"/>
                                    <pathelement location="../lib/bcel-5.2.jar"/>
    
    
    to the classpath javac target (otherwise it wouldn't find a bunch of the classes it needed to build). No other changes from your source code.

    Yes earlier I did make changes to the source code to print a bunch of debugging info (that was to the .17 code), which helped me track down a problem with the actual shared libraries I was using. But then I downloaded the clean source tree, rebuilt it, and watched it work. Yes I also found it strange.. but just in case I did something wrong, here's what I did:

    1) download the .zip file you have. Open it up, edit streambaby.ini and simplelog.properties. Run streambaby -- wouldn't load the shared libs.
    2) build it from the source (using ant in the toplevel). Copy the zip file that is generated in dist/, open it up, do the same edits to streambaby.ini and simplelog.properties. Run streambaby -- loaded the shared libs...

    So yeah, seems odd to me too. for what it's worth, when I use dtrace to track what files it is trying to open, your version isn't even trying ANY file with libavutil in the name. it's almost like it's ignoring the preferences in streambaby.ini .. I dunno.. but I have a workaround, so for now don't worry about this behavior/bug...

    Thanks for the program btw!
     
  10. Jan 23, 2009 #110 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    No problem, and thanks for the all of the Mac work. It's really nice to have someone making builds available for Mac users-- I've actually tried to get the last open source darwin dist that Apple released going over the last couple of days so I could try to help out, but wasn't able to get it running under Virtualbox or qemu so eventually gave up.

    As far as the builds go, it's possible I had some kind of problem in my build process. When you mentioned you had an issue with ffmpeg-java it occured to me that at some point in the last couple of days I had the same issue about the javac classpath, and it seemed a little strange to me since it started occuring all of a sudden for me without changing custom-build.xml. It's possible I had some kind of issue in my build process at some point, so if you don't mind trying one more time with my build next go-around (next version), that would be great. (Then I'll try to stop worrying about it... I can be a bit obsessive when it comes to unexplainable behavior, always afraid that even if it seems inconsequential it's masking some larger earth shattering problem ;-)
     
  11. Jan 23, 2009 #111 of 3415
    Yoav

    Yoav New Member

    1,048
    0
    Jan 12, 2007
    Sure.. glad to help... Just post when it's ready (or put up your code in svn or something ...)
     
  12. Jan 23, 2009 #112 of 3415
    westside_guy

    westside_guy Annoyingly ephemeral

    464
    1
    Mar 13, 2005
    The soggy...
    I haven't done any jumping around, just watched from the start to the end - these were ~ 30 minute TV shows I'd ripped from one of my DVDs. I'll try out what you've said + cahoon's idea as soon as I get a chance.
     
  13. Jan 23, 2009 #113 of 3415
    cahoon

    cahoon New Member

    19
    0
    Nov 1, 2007
    Well, unfortunately, the change isn't correct :(. It is going to take a little more effort to fix properly. I'll take another crack at it tonight.

    There are two issues, I think. (1) dealing with the end condition, and (2) incrementing the sample count, which is incremented too often as is.

    The problem is with the stts atom only. The old code for the ctts atom is correct.
     
  14. Jan 23, 2009 #114 of 3415
    cahoon

    cahoon New Member

    19
    0
    Nov 1, 2007
    Interesting - I was wondering why the reinterleaving was performed. Thanks for the explanation.
     
  15. Jan 23, 2009 #115 of 3415
    westside_guy

    westside_guy Annoyingly ephemeral

    464
    1
    Mar 13, 2005
    The soggy...
    Okay, when I did this and played the resulting file through tivostream, I got both green blocks during the first 10 seconds of video AND saw audio/video synch problems as the show progressed. Neither one is usually an issue with tivostream.

    Funny thing - this didn't solve the audio/video sync problem; but it did solve the "green blocky video during the first 10 seconds of the show" issue I've been having with streambaby. :D
     
  16. Jan 23, 2009 #116 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    Thanks cahoon-- I think I found a relatively straight forward way to solve this (instead of calculating the sample_duration in the stts loop, I store the sample_duration in the samples_ array itself and use the stored value in the loop. I added code in trak_build_index to store the duration in the same loop that was calculating the pts_). However it looks to me like the sample count was getting calculated correctly, it was just the end case that was problematic.

    Before I release a new version, I was wondering what your thought process was on why the sample count might be getting calculated incorrectly.

    EDIT: I uploaded my latest src code bundle with the changes above to the streambaby web site, streambaby-0.19-src.zip. It should be available on the download tab, I did not move it to the front page yet (and also didn't upload a non-src build of it). I need to get SVN going at some point...
     
  17. Jan 23, 2009 #117 of 3415
    cahoon

    cahoon New Member

    19
    0
    Nov 1, 2007
    Great! I think that's the best way the fix this problem. Without adding that duration, it's a pain to fix the end case.

    It is really the 's' variable that gets incremented too often, so the new stts atom may contain fewer entries than it should. Sorry for the confusion.

    The way the code was structured, every time an stts entry is written the 's' variable is incremented due to the outer loop. But, it's also incremented in the inner while loop (which is where the variable should be incremented). For example, when s=1 and control enters the inner while loop, the 'if' condition is always true the first time the while loop executes. That causes 's' to be incremented (s=2). On the next iteration of the while loop, let's say the break is executed. Then, the entry is written, and 's' is incremented again (s=3) for the outer for-loop. So, a sample is skipped potentially.

    If there is only 1 entry in the stts, then it's not a problem.

    EDIT: kearygriffin - your new code doesn't have the same problem because you use 's + 1' in the inner while loop as your if condition. In this case, the while loop may break immediately, so 's' won't be incremented.
     
  18. Jan 23, 2009 #118 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    I'm actually pretty sure that is OK. The inner loop is actually trying to reduce the number of entries in the table. All consecutive stts entries that have the same duration are "condensed" into a single entry in the table.

    Really only one way to find out (well, not really, but..). I'm going push out V0.19 and see what happens.
     
  19. Jan 24, 2009 #119 of 3415
    kearygriffin

    kearygriffin New Member

    346
    0
    Jan 31, 2008
    Just uploaded new streambaby V0.19

    ===V0.19===
    * Added MKV to default list of extensions to scan
    * Catch NumberFormatExceptions and return default values while trying to parse ffmpeg output
    * cahoon/KG: Fix off-by-one issue (causing ArrayIndexOutOfbounds) in MP4 psuedo-streaming
    * Changed preview cache cleanup code to work faster/use less memory & deal with recursive symlinks
    * Added additional debugging for loading of native ffmpeg libraries
    * Fixed bug where saved bookmark position ended up negative (caused Play/Replay screen to not have correct text positioning)
    * TiVo doesn't seem to report correct duration for MP4's (always seems to report ~8secs less).
    - Added code to work-around by using my own calculated duration if I receive RSRC_EVENT_COMPLETE from tivo and its duration is shorter than expected
    - Still some weirdness around end of MP4s-- Shuttle bar will stop moving around 8 seconds before end...
    * Fixed centering of shuttlebar -- Also made it wider while I was at it.

    I think that should solve most of the problems reported so far-- The only exceptions being:
    -- Audio sync issues w/MP4 videos
    -- Possibly issues with green/random blocks at the beginning of MP4 videos

    My guess is I am going to have to get my hands on one of the MP4's that exhibit these issues. I haven't seen any of these problems with the MP4's that I have.
     
  20. Jan 24, 2009 #120 of 3415
    cahoon

    cahoon New Member

    19
    0
    Nov 1, 2007
    I added an EDIT to my previous post while you posted this message. I just wanted to clarify.

    I think your new code is correct, and increments the 's' variable correctly. In fact, it worked on a couple examples for me.

    The inner loop is trying to condense the stts entries. The problem with the old code is that inner loop would always be executed at least once - the 'if' would be true on the first iteration, and then 's' and 'sample_count' would be incremented. In your new code, the 'if' in the inner loop correctly checks the next entry and can 'break', so that 's' and 'sample_count' would not be incremented. This is in the case where the sample_count for the entry is 1.
     

Share This Page