Multiple videos in one file

View previous topic View next topic Go down

Multiple videos in one file

Post by qwertymodo on Mon 28 Nov 2016 - 16:24

I just thought I'd post this here in case anybody else was considering something similar.

People have asked whether or not it's possible to have more than one video in your game, and it's actually quite simple to do (I have 10 videos for Chrono Trigger).  Basically, you just need some way to know where each video starts and ends.  There are a couple of ways you could do this.  One way you could do it is to put a single data byte at the beginning of each frame to use as a flag of whether or not the video is done, but I found this a bit wasteful, and since my videos were only 15fps, it was easier to just use a frame counter (at 15fps, a 16-bit frame counter lasts about ~70 minutes).

So, after converting all 10 of my files into the format that my video player uses, I just merged them into a single file, starting with a header.  The header format is 4 bytes 'M' 'S' 'U' '1' so that I can check whether the data file exists or whether it's just an empty data file, in which case, the video code would just exit and the game would continue.  Then, I simply have an offset table listing the start address of each video file.  I basically just start by filling this with 4*number_of_videos of empty bytes.  In my case, 10 videos, so 40 bytes.  This meant that my first video starts at byte 44 (0x2C), so I go back to my header at byte 4 and fill in 2C 00 00 00 (little-endian).  Now, at byte 2C, I write 2 bytes, little-endian, containing the frame count for the video, and then I simply paste the entire first video's data.  Now I seek to the end of the file to get the next address where the second video will start, and write that value into the header at byte 8.  Frame count->video data->update header->repeat.

For the more visually inclined among you:


To make things simple, my video .pcm's start at track 100, so video #0 = audio #100, video #1 = audio #101, etc.

To read this file, the pseudocode looks like this:
Code:
Save regs to the stack
Seek MSU-1 data ROM to 0
Wait for busy flag to clear
Read first 4 bytes, should be 'M' 'S' 'U' '1'.  If not, restore regs and exit.
Seek ROM to video_index*4 (asl; asl)
Wait for busy flag to clear
$2001 -> $2000
$2001 -> $2001
$2001 -> $2002
$2001 -> $2003
Wait for busy flag to clear
Start audio track
Read 2 bytes into a 16-bit frame_count variable
While frame_count > 0:
  Display Frame
  frame_count--

Restore regs
Exit
avatar
qwertymodo
                   
                   

Since : 2014-10-21

Back to top Go down

Re: Multiple videos in one file

Post by Conn on Mon 28 Nov 2016 - 16:47

Interesting method.  I made also thoughts on this and came to this theoretical solution: Ikari player, which I use gets an x register value out of the *.msu file length, which is counted down. If you know the specific x-value where to stop and resume, it should be rather simple to recode the video player to play a specific part implementing a ram flag. Problematic is that the complete vram is overwritten. Game-specific, you need to find and call every dma transferring routine, specific to the current progress.
This should be quite hard.

Anyways, did you have time to create the new Conner themes with erock new takes already? Very Happy
avatar
Conn
                        
                        

Since : 2013-06-30

Back to top Go down

Re: Multiple videos in one file

Post by qwertymodo on Mon 28 Nov 2016 - 17:07

Conn wrote:Interesting method.  I made also thoughts on this and came to this theoretical solution: Ikari player, which I use gets an x register value out of the *.msu file length, which is counted down.

Wait, how do you get the file size?   Disgust   That shouldn't be possible from the SNES, since as far as the SNES knows, there's just 4GB of ROM, regardless of if there is data or not, there's no "file size" from that perspective.

Problematic is that the complete vram is overwritten. Game-specific, you need to find and call every dma transferring routine, specific to the current progress.
This should be quite hard.
Yup.  It's tough.  Depending on the game, though, you can put the video inbetween screen transitions so that the game code re-fills VRAM on its own.  In Chrono Trigger, I got lucky because of the "Special Dialog" command, which is used for things like character rename screens or for shops, which take up the entire screen.  I was able to add a fake "shop" which was unused in the game (shop #12), and then hook into the code that loads the shop menu so that if it's trying to load #12 it just exits immediately.  The end result is that the screen fades out to black and then back again, reloading all of the graphics in the process.  Since my videos all end in black, you don't see the fade out, you just see it fade back in and everything is back where it belongs Smile

Anyways, did you have time to create the new Conner themes with erock new takes already? Very Happy
Not yet, I was out of town for the weekend, I'll try to get on them tonight.
avatar
qwertymodo
                   
                   

Since : 2014-10-21

Back to top Go down

Re: Multiple videos in one file

Post by Conn on Mon 28 Nov 2016 - 17:34

I do not know... you need to ask Ikari how that works. Here's a short trace:

Code:
c1f451 stz $0020     [800020] A:0001 X:2001
c1f454 lda $2001     [802001] A:0001 X:2001
c1f457 sta $0006     [800006] A:0066 X:2001
c1f45a lda $2001     [802001] A:0066 X:2001
c1f45d sta $0007     [800007] A:002a X:2001
c1f460 lda $2001     [802001] A:002a X:2001
c1f463 sta $0004     [800004] A:0002 X:2001
c1f466 sta $0021     [800021] A:0002 X:2001
c1f469 lda $2001     [802001] A:0002 X:2001
c1f46c sta $0002     [800002] A:0002 X:2001
c1f46f lda $2001     [802001] A:0002 X:2001
c1f472 sta $0003     [800003] A:0001 X:2001
c1f475 lda #$01               A:0001 X:2001
c1f477 sta $0005     [800005] A:0001 X:2001
c1f47a ldx $0006     [800006] A:0001 X:2001
c1f47d dex                    A:0001 X:2a66
c1f47e lda $0012     [800012] A:0001 X:2a65

So X gets the msu file length somehow from register $2001 and the length is #$2a66 of the AST msu video file (maybe this is the amount of frames?). It is counted down to #$0000, and when it reached, the video is over.


Edit:
Oh no, seems it won't help. I manipulated the x to start at e.g. #$1000 and it still starts at the beginning of the video and not in the middle, it just ends earlier.  Sorry Sad
But it still might be a good advice to ask Ikari, whether he sees a chance to make it easy? Somehow the msu1-registers need to know at which frame you currently are...

Not yet, I was out of town for the weekend, I'll try to get on them tonight.
Oh wow, It really would feel like a relieve if I can finish this chapter and thus conker once and for all Embarassed
Much luck with that Smile
avatar
Conn
                        
                        

Since : 2013-06-30

Back to top Go down

Re: Multiple videos in one file

Post by qwertymodo on Mon 28 Nov 2016 - 18:29

$2001 is the data read register.  It's not getting the file size, it's reading a value stored in the file itself.  So, basically the same as what I'm doing (the yellow value). Well, maybe it is the file size, but if it is, it's still just a value stored inside the file somewhere.
avatar
qwertymodo
                   
                   

Since : 2014-10-21

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum