2008-12-26

More on Sansa Fuze's video format

Sansa Fuze MP3 player only supports a very specific version of the AVI file format for it's video output. This format is not documented anywhere and can only be, as far as I know, produced with Sansa Media Converter (SMC) Windows program. I have spent some time familiarising myself with the video files produced by SMC. This blog post was written to document some of the aspects I have learnt so far.

I hope at least someone finds some interesting information here and perhaps we can come closer to a working video conversion. This is still very much a Work in Progress. I intend to update this entry if any new information pops up. I'm also happy to answer any questions I can in the comment section. See also my previous entry on this subject.

AVI files

AVI files consist of chunks. For a recent general discussion of AVI files, see this pdf file. If you use Python, AVI chunks can be read, for example, with Python's chunk module. See Python's reference page for a nice explanation of chunks in general.

AVI file is actually a RIFF file. A standard RIFF files have 3 types of chunks. First comes the "RIFF Form Header". Then there are normal chunks and list chunks.

A chunk has a 4 byte identifier, a 4 byte chunk size, followed by the actual data. A list chunk has identifier 'LIST', a 4 byte chunk size, a 4 byte list identifier, followed by data. RIFF Form header has identifier 'RIFF', a 4 byte file size, a 4 byte form identifier (in this case, 'AVI '), followed by the actual data, in this case the other chunks.

File Structure

Fuze's video format is, in essence, a standard AVI, but the requirements for a working file are specific. I analysed a very short example file generated with SMC. In this example file, the file structure was as follows:

  • 'RIFF' form header

  • 'hdrl' LIST chunk, header information

  • 'avih' chunk (56), avi file headers


    • 'strl' LIST chunk, which describes the video stream


      • 'strh' chunk, stream header

      • 'strf' chunk, further stream description

      • 'indx' chunk, odml stream indexing


    • 'strl' LIST chunk, which describes the audio stream


      • 'strh' chunk, stream header

      • 'strf' chunk, further stream description

      • 'indx' chunk, odml stream indexing

      • 'JUNK' chunk, which is just filler

    • 'odml' LIST chunk, OpenDML header list


      • 'dmlh' chunk (248), OpenDML header chunk


    • 'INFO' LIST chunk


      • In this case, this list chunk has just one subchunk called 'ISFT' (software), with the string 'InterVideo\x00\x00'.


    • 'movi' LIST chunk, containing the actual video and audio data as subchunks


      • In our example, this list chunk has just 4 subchunks called, ix00, ix01, 00dc, 01wb. The first two are odml index chunks, the third one is video, the last one is audio.


    • 'idx1' chunk. Legacy index chunk that is actually not required by Sansa Fuze.



Some observations

Here are a few random observations about Sansa Fuze's video files.

  • Wrong ulFlags in the avih header do not affect playback. It seems that the player just ignores this and in fact much of the headers.
  • idx1 chunk is not required. Apparently it is not even read before playback reaches the end.
  • Fuze uses OpenDML (AVI2) indexing. 'odml' chunk is absolutely required. So are 'indx' subchunks under 'strl' chunks, and ix## subchunks under movi chunk. Mencoder unfortunately only creates odml compatible files if file size is greater than 1 GB. I have tried modifying the sources so that odml index is created every time, but these files do not seem to work any better. It is probable that Fuze doesn't like Mencoder's method of starting a new RIFF chunk whenever odml index is used. Perhaps there is another encoder somewhere that can create the odml chunk every time. I understand that Windows program VirtualDubMod creates OpenDML compatible files, but I haven't had the time to find out how well it works.

Further information

A few sources of information about AVI files in general:

9 comments:

skelso said...

Thanks for blogging all this. I got my Fuze as a Christmas gift and have just discovered the hassle in converting video.

gotgenes said...

Same as skelso, I received one of these players as a Christmas gift and am seeking a way to convert videos on Linux. I was happy the player had OGG support but felt really disappointed when I realized I couldn't just use FFMpeg to convert videos to play on the Fuze. Thanks for documenting this information. Hopefully it will help make headway into getting video to work on this player.

Anonymous said...

hope you find something http://forum.slysoft.com/showthread.php?t=23766

Anonymous said...

In this case, this list chunk has just one subchunk called 'ISFT' (software), with the string 'InterVideo\x00\x00'.

InterVideo wrote SMC... now owned by Corel Corp.

Christian said...

Hi, thanks for all of your posts on this topic. I have been hacking on Avidemux on and off for the past few weeks trying to get this thing working. I have it writing ODML files no matter what the size but that doesn't do the trick. I'm doing a straight codec copy from a file converted with SMC, so only the container is changing.

The file that I am generating is almost the exact same thing as what comes out of the SMC. The indx (super index) chunks are smaller though, with less cruft. Also the data chunks in the movi list are a different size, but WinAVI does that too and the videos it generates play OK.

Anyhow, I'm going to keep at it I guess. My C++ skills are weak though. What I'd like to do is just write some utility in Python that converts an AVI v1 file to AVI v2. Something that you could stick together with ffmpeg or mencoder in a script.

Anyhow, thanks again for your posts with the info. I'll post back if I have any success.

spicifer said...

Christian,

It was indeed interesting to read about your work on this subject. I'm especially glad if you found something I wrote about this useful.

I'll say one thing about programming languages. I did some very elementary tests with parsing AVI files in Python and C last year. While Python might not be the most popular tool to handle binary data such as AVI files, I think it is good enough, anyway. For example, if you want to write out a "Junk Chunk" the same way SMC does, you can do it with just

a='JUNK'+pack('L',2)+'\x00\x00'
f.write(a)

(after opening file f for writing) and be done with it. Since I don't have that much experience with C/C++, I at least was way more productive in Python.

Good luck!

noookaaa said...
This comment has been removed by the author.
noookaaa said...

Sansa Fuze's video is is not documented anywhere but not only be produced with Sansa Media Converter, as far as I know, Nidesoft DVD to Sansa Converter can produce specific video format of Sansa Fuze. You may free download it here to see it:
http://www.nidesoft.com/dvd-to-sansa-converter.html

ssorgatem said...

http://forums.sandisk.com/sansa/board/message?board.id=sansafuse&thread.id=30653&view=by_date_ascending&page=1

Video conversion success using mencoder and avi-mux GUI. Ewelot found all necessary specifications and software to do it and created a sh script to automate it. I wrote a GUI in python. Although avi-mux GUI works well under wine, I'm trying to modify mencoder sources in order to make it output correct avi files... but my knowloedge on avi files (and binary data management, in general) i too poor. Any help would be greatly appreciated :)