Converting video for use in Opticks

Skip to end of sidebar Go to start of sidebar
Skip to end of metadata
Go to start of metadata

Basic gray scale video conversion

Opticks does not currently have a video import for avi, mpg, etc. although there is some preliminary work in COAN. If you'd like to import a video for now, you can use ffmpeg to convert the video to raw frames and import those. Here is a brief example.

ffmpeg -i input_file.mpg -f rawvideo -pix_fmt gray output_file.raw

In the output from ffmpeg you'll see some information about the frame size. For example:

The Stream #0.0: Video: mjpeg, yuvj422p, 640x480, 30 tbr, 30 tbn, 30 tbc part is the interesting line and indicates a 640x480 pixel frame size.

You'll also need the total number of frames which is available when the conversion completes in the line which looks like:

frame= 1832 fps= 39 q=0.0 Lsize= 549600kB time=61.07 bitrate=73728.7kbits/s dup=430 drop=0

This example has 1832 frames.

When the conversion is done, load Opticks and go to File->Import Data.... Choose the Generic Importer and select output_file.raw then hit the Options button.

In the File tab put the frame size in the Columns and Rows sections and the total number of frames in the Bands section. Bits Per Element is 8 and Interleav Format is BSQ - single file. You may also want to set the On Disk (Read-Only) Processing Location in the Data tab. Import the file and you'll have a gray scale image. You can create a new animation using View->Create Animation or using the video extension from COAN.

You may want to use File->Export to save the file as a compressed ICE in order to save disk space. Choose Options->Ice Exporter in the export dialog and select GZIP compression.

Color video conversion

If you want to convert all the color channels, you'll have to create separate files for each color channel. Instructions are below. When converting with ffmpeg, use a different -pix_fmt to select the appropriate color channel. You can also generate more bits per pixel if you need to extra dynamic range. If you change the bits per pixel, don't forget to adjust the Bits Per Element in the File tab when importing and also the Data Type in the Data tab. You can use -pix_fmt list to get a list of available formats.

pix_fmt channel element size
gray all colors converted to an unscaled gray channel 8bpp
gray16le same as gray but with 2 byte little endian pixels 16bpp
rgb24 red, green and blue channels which need to be split 8bpp
yuv422 YUV color space with 1 byte luminance and half byte color channels 8/4bpp

To split channels you need to use an external tool. An example python script follows. This is not a very efficient script but demonstrates the technique.

Import each of the three color channel files. Use one as the display layer but set the red, green, and blue color channels to the different raster elements. When animating, this will display as a color image.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.