Thursday, October 11, 2012

Roku BIF files

Your Roku supports pretty cool way to do trick modes - the bif files. I think this is Roku specific mode because I have not seen anyone else doing this. The bif file is essentially archive of the frames in jpeg format with an index at the beginning of the archive. Each frame is taken periodically, every 10 or so seconds. Roku SDK contains a biftool utility for Linux and Windows and also a document describing internal format of the bif file. This document is very basic but it gives an initial understanding. I think a Python script would be more useful and more portable since it would run on any system and would provide the source code to fix any bugs.
To create bif file you need to extract frames from your video and save them in to jpeg files. Each file is named as a number starting from zero, i.e. 00000000.jpg, 00000001.jpg, etc. The number in the name signifies the position in the index of the bif file. The position is multiplied by the interval that you provide when generating the frames and when creating the bif file. For example if your interval is 10 seconds and your file name is 00000023.jpg the frame would be located at 230 seconds in to the video. When you navigate in your video, Roku would show frames from the bif file corresponding to current position in the video. The effect is pretty neat but it has problems. The first problem is that it is hard to achieve a good precision in this manner. The generated frames do not correspond to the key frames and when you start your video it is usually a few seconds off the displayed frame, I would say within 10 seconds. The second problem is that the process to generate bif file takes time and I am not sure if it is worth the effort.

The process

The process itself is pretty simple but may involve getting Roku SDK. You  would need to register with Roku and download Roku SDK that contains biftool.exe utility. There is also bif file generation tools that sold online but I have not tried them. You would also need to download ffmpeg but most of people who stream to Roku from PC would already have ffmpeg.
There is also a Python tool that generates bif file. Search for makebif.py and you will find this tool. It works just as well as the tool from Roku but you loose some control if you do not know how to program Python.
The first step is to generate frames from the video file over the regular intervals. Lets assume 10 second interval for this example but you can adjust your interval to what you feel is appropriate. Create a directory to contain you images and run the following command:
ffmpeg.exe -i video.mp4 -f image2 -r 1/10 -s 240x180 directory/%08d.jpg
I encountered a problem with the later version of ffmpeg - the first few images are generated at a very short interval. This causes all remaining images to be off by a few seconds. To remedy this problem first few images should be removed and the rest should be renamed accordingly. Shell script would do the job.
Next step is to run the biftool.exe to generate the bif file:
biftool.exe -t 10000 directory 
The -t parameter indicates interval between images in milliseconds. There are other parameters that can be passed to the biftool but they do not seem to work. This will create a file named direcotry.bif which is the resulting bif file. You need to rename this file in to a video.bif to match the name of your mp4 file. Now load up your video in MyMedia player or your other favorite player and enjoy. During the fast forward operation the images would be displayed instead of a simple progress bar.

The conclusion

I am not sure if the process is worth the effort if you want to watch a video just one time. It may be worth the effort for your kids videos or something that you want to keep and will watch over and over again. I also think that the biftool from the Roku SDK is pretty poor and the python version is much better, especially if you can modify it. The python version can be made to automatically delete first few images and can be fixed if any problems are found. At the end the process and the result was fun to try. If you are in to organizing your video collection this maybe something that would be useful to you.

2 comments:

Popmedic said...

I made an OS X application that has gui for this, also there is a php version and ruby version up there (look though my repos). Sorry for sloppy code.
HTTPS://github.com/popmedic/BifBuilderGUI

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