DV INFORMATION

Since Quicktime supports DV, the DV library was integrated. Originally the DV library had no front end so an abstraction to the DV library which uses Quicktime 4 Linux semantics was also written. The front end to the integrated DV support is in libdv.h

THE DV_T OBJECT

It allows you to

1) Decode and encode video data from a DV frame
2) Decode and encode audio data from a DV frame

DV stores audio and video in each frame. Function calls in libdv.h handle each separately.

DECODING

STEP 1:

#include "libdv.h" and create a new dv decoder.

dv_t *dv = dv_new();

STEP 2:

Read a video frame from a buffer containing one frame of DV.

dv_read_video(dv, output_rows, data, bytes, color_model);

dv is the dv decoding object.

output_rows is an array of pointers, one pointer to each row of an output frame. Each row must have enough memory allocated to store a row of the specified color model. If the colormodel is planar, the first three output_rows are the planes and the rest is ignored. The dimensions of the frame must be determined by whatever procedure grabs the data from the device.

data is the compressed data.

bytes is the size of the compressed data. This can be a #define from libdv.h.

color_model is the color model to generate. It can be almost anything from colormodels.h but not all the outputs have been tested.

STEP 3:

Read an audio frame. This procedure only works for 2 channel 16 bit encoding in the DV frame. Call dv_read_audio for each frame to extract the audio from.

dv_read_audio(dv, samples, data, size, channels, bits);

dv is the dv pointer.

samples is a preallocated buffer of 4096 bytes * channels * bytes per sample, an arbitrary fraction of which are going to be filled.

data is the compressed DV frame.

size is the number of bytes in the DV frame.

channels is the number of channels libdv should store in the samples buffer. The DV format allows up to 4 audio channels. If the DV frame itself has more channels than the user has allocated, they are ignored.

This function returns the number of 16 bit, twos complement, native byte order samples deposited in *samples.

STEP 4:

Delete the dv object when finished reading frames.

dv_delete(dv);

ENCODING

Creating and deleting the dv object is the same as in decoding. This involves dv_new and dv_delete.

ENCODING VIDEO

void dv_write_video(dv_t *dv,
		unsigned char *data,
		unsigned char **input_rows,
		int color_model,
		int norm);

Compresses the uncompressed frame in input_rows to the preallocated buffer pointed to by data. The size of the buffer is either DV_NTSC_SIZE or DV_PAL_SIZE depending on the norm.

The color_model can only be BC_YUV422 or BC_RGB888.

The norm can be DV_NTSC or DV_PAL. The norm determines the size of the frame that must be passed to input_rows. DV_NTSC requires a 720x480 frame. DV_PAL requires a 720x576 frame.

ENCODING AUDIO

After and only after encoding video into the frame, audio may be encoded.

int dv_write_audio(dv_t *dv,
		unsigned char *data,
		unsigned char *input_samples,
		int max_samples,
		int channels,
		int bits,
		int rate,
		int norm);

data is the same buffer previously used in the video encoding.

input_samples is interleaved, 16 bit, twos complement, native byte order, audio in the number of channels specified by channels.

max_samples is the number of samples in the input_samples buffer. There should be at least 4096 samples in the buffer.

channels specifies the number of channels in the interleaved buffer. This matches the number of channels encoded in the DV frame. The DV standard allows 2 to 4 channels, depending on bits and rate.

bits, rate specify the encoding of the audio in the DV frame.

The norm can be DV_NTSC or DV_PAL.

This function returns the number of samples actually encoded in the frame. This is usually less than the max_samples argument but is not constant. It is up to the user to reuse the remaining samples in the next frame.