Viability of Writing Uncompressed Video to an FLV File

215 Views Asked by At

There is a very good chance that I am going down a pointless path on this, so I apologize if this is a waste of time. I have been trying to write uncompressed video to an FLV file, and I am not sure whether it is possible.

According to Wikipedia, a valid video encoding option is 0, which indicates an "RGB" video encoding: https://en.wikipedia.org/wiki/Flash_Video#Packets. However, I don't see any mention of this Codec ID option in Adobe's documentation; neither "Video File Format Specification Version 10" nor "Adobe Flash Video File Format Specification Version 10.1".

I proceeded under the assumption that a 0/RGB Codec ID is allowed. I hard-coded an array of unsigned char in C and used fwrite to write the following Double/Number metadata to a new, binary FLV file (which admittedly, I am assuming I wrote correctly):

  • duration: 4 (seconds)
  • width: 16 (pixels)
  • height: 16 (pixels)
  • videodatarate: 6 (Kbps)
  • framerate: 1 (fps)
  • videocodecid: 0
  • filesize: 3323 (bytes)

I then added 4 VIDEODATA tags, 1 for each RGB frame I was hoping to write. Their timestamps are 0, 1000, 2000, and 3000 (milliseconds). All four of them have a 769-byte payload: the first byte to specify it is a keyframe with a Codec ID of 0, and the remaining 768 are to represent a 16x16x3 (RGB) image. I wrote 255/0xFF for all values in hopes of seeing a small, white screen appear for 4 seconds.

When that did not play correctly in VLC Media Player, as I feared, I tried using RGBA colors for each frame. I also changed the videodatarate and filesize metadata to Number values 8 (Kbps) and 4347 (bytes) respectively.

Unfortunately, this did not play in VLC Media Player either. I was wondering if anyone knew for certain whether uncompressed video in an FLV file is possible? If so, I was curious what format the video data should be in (RGB, RGBA, multiple VIDEODATA tags, just one VIDEODATA tag, etc.)?

My C code is mostly one, giant array of unsigned char, but if anyone would like to see it, I can try adding it. Any advice is greatly appreciated.

Thank you,

Mitchell A

2

There are 2 best solutions below

0
On BEST ANSWER

As per SirDarius, "the video encoding types listed in the Wikipedia page do not come from an official source. I would not recommend relying on those." This makes sense given that the FLV Format documentation from Adobe itself makes no mention of an uncompressed, RGB option for video encoding.

I was holding out hope that Wikipedia editors and other people knew of some undocumented easter egg in the FLV format, but I'm now convinced that's not the case.

0
On

"...The FLV Format documentation from Adobe itself makes no mention of an uncompressed,
RGB option for video encoding."

For RGB (raw bitmap data) you must use theScreen 1 codec (id=3).

Strangely, it's hidden in the SWF Format documentation (not the FLV Format docs).
See Chapter 14 (page 204) which is the Video section...

  • You want specifically page 208 for the Screen Video codec to be explained.

  • Check this example code (AS3) of encoding RGB into Screen Video.

Apply the logic, especially function videoData(), which could be adjusted to read pixels uints (via some getPixel type call) or just read from an Array.

Example:

for (var x2:int = 0; x2 < xLimit; x2++) 
{
    var px:int = (x1 * blockWidth) + x2;
    var py:int = frameHeight - ((y1 * blockHeight) + y2); // (flv's save image from bottom to top)

    var p:uint = YOUR_INPUT_BITMAP.getPixel(px, py); // sample a pixel's RGB (3-bytes unsigned int) 

    //# IF reading from Pixel's uint value
    block.writeByte( p & 0xff );        // blue 
    block.writeByte( p >> 8 & 0xff );   // green
    block.writeByte( p >> 16 );         // red

    //# ELSE IF reading from Array of R-G-B values(FLV writes in BGR format)
    block.writeByte( myRGB_Array[x+2] );        // blue 
    block.writeByte( myRGB_Array[x+1] );    // green
    block.writeByte( myRGB_Array[x] );  // red

}