📄 qt.c
字号:
@Parameters ::
Bytestream *stream :: The QT Atom byte stream
Uint16 Width :: Track width
Uint16 Height :: Track Height
Uint32 dataformat :: Data Format
Uint32 TemporalQuality :: Temporal Quality
Uint32 SpatialQuality :: Spatial Quality
Uint32 Hres :: Horizontal resolution in pixels/inch
Uint32 Vres :: Vertical resolution in pixels/inch
Uint16 FramePerSample :: Number of frames per sample
Uint16 ColorDepth :: Color Depth
Uint8 FieldCount :: Number of fields
Uint8 FieldOrdering :: Field Ordering
@Return ::
NONE
\-----------------------------------------------------------------------------*/
void TrackMediaVideoSampleDescriptionAtom(Bytestream *stream,
Uint16 Width, Uint16 Height, Uint32 dataformat,
Uint32 TemporalQuality, Uint32 SpatialQuality, Uint32 Hres,
Uint32 Vres, Uint16 FramePerSample, Uint16 ColorDepth,
Uint8 FieldCount, Uint8 FieldOrdering,
Uint32 chunk_offset, Uint8 *esds_atom_info
) {
Uint32 count_stsd, count_dataformat, count_end;
count_stsd = stream->ptr8;
stream->ptr8 += 4;
put_bytes(stream, 4, ('s'<<24)+('t'<<16)+('s'<<8)+'d'); /* Sample Description type */
put_bytes(stream, 4, 0); /* version+flags */
put_bytes(stream, 4, 1); /* number of entries */
count_dataformat = stream->ptr8;
stream->ptr8 += 4;
put_bytes(stream, 4, dataformat );
put_bytes(stream, 4, 0); /* reserved 4 bytes */
put_bytes(stream, 4, 0x0001); /* reserved 2 byets + data reference index */
put_bytes(stream, 4, 0x0); /* Version + revision level */
put_bytes(stream, 4, 0x0); /* Vendor */
put_bytes(stream, 4, TemporalQuality); /* temporal quality */
put_bytes(stream, 4, SpatialQuality); /* Spatial quality */
put_bytes(stream, 4, (Width<<16)+Height); /* Width + height */
put_bytes(stream, 4, Hres<<16); /* Horizontal resolution */
put_bytes(stream, 4, Vres<<16); /* Vertical resolution */
put_bytes(stream, 4, 0); /* Data size */
put_bytes(stream, 2, FramePerSample << 16 ); /* Frame count+ 2bytes Compressor name */
put_bytes(stream, 2, 0); /* Frame count+ 2bytes Compressor name */
put_bytes(stream, 4, 0);
put_bytes(stream, 4, 0); /* compressor name */
put_bytes(stream, 4, 0); /* compressor name */
put_bytes(stream, 4, 0); /* compressor name */
put_bytes(stream, 4, 0); /* compressor name */
put_bytes(stream, 4, 0); /* compressor name */
put_bytes(stream, 4, 0); /* compressor name */
put_bytes(stream, 4, ColorDepth); /* 2bytes CN + Color depth */
put_bytes(stream, 2, 0xffff); /* Color table ID */
if( dataformat == QT_MJPEGA_FORMAT ) {
put_bytes(stream, 4, ( 0x000a << 16 ) + ('f'<<8) + 'i' ); /* Color table ID */ /* fiel */
put_bytes(stream, 4, ('e'<<24)+('l'<<16)+(FieldCount<<8) + FieldOrdering); /* Color table ID */
put_bytes(stream, 4, 0x00000000); /* Color table ID */
count_end = stream->ptr8;
} else
if( dataformat == QT_H263_FORMAT ) {
count_end = stream->ptr8;
} else
if( dataformat == QT_MP4_FORMAT ) {
Uint32 count_esds;
count_esds = stream->ptr8;
stream->ptr8 += 4;
put_bytes(stream, 4, MAKE_TAG('e','s','d','s'));
put_bytes(stream, 4, 0x0 );
put_bytes(stream, 4, 0x03370000 );
put_bytes(stream, 4, 0x1F042F20 );
put_bytes(stream, 4, 0x11001000 );
put_bytes(stream, 4, 0x00001000 );
put_bytes(stream, 4, 0x00001000 );
put_bytes(stream, 1, 0x05);
put_bytes(stream, 1, chunk_offset);
{
int i;
for(i=0; i<chunk_offset; i++)
put_bytes(stream, 1, esds_atom_info[i] );
}
put_bytes(stream, 3, 0x060102 );
count_end = stream->ptr8;
stream->ptr8 = count_esds;
put_bytes( stream, 4, (count_end-count_esds) );
stream->ptr8 = count_end;
}
stream->ptr8 = count_dataformat;
put_bytes( stream, 4, (count_end-count_dataformat) );
stream->ptr8 = count_stsd;
put_bytes( stream, 4, (count_end-count_stsd) );
stream->ptr8 = count_end;
}
/*-----------------------------------------------------------------------------\
@RoutineName :: TrackMediaTimetoSampleAtom
@Description ::
Constructs a Track Media Time to Sample Atom
@Parameters ::
Bytestream *stream :: The QT Atom byte stream
Uint32 Scount :: Number of samples
Uint32 Sduration :: Sample Duration
@Return ::
NONE
\-----------------------------------------------------------------------------*/
void TrackMediaTimetoSampleAtom(Bytestream *stream, Uint32 Scount, Uint32 Sduration) {
put_bytes(stream, 4, 0x0018); /* Atom Size */
put_bytes(stream, 4, ('s'<<24)+('t'<<16)+('t'<<8)+'s'); /* stts */
put_bytes(stream, 4, 0); /* version + flags */
put_bytes(stream, 4, 1); /* number of entries */
put_bytes(stream, 4, Scount); /* Sample count */
put_bytes(stream, 4, Sduration); /* Sample duration */
}
/*-----------------------------------------------------------------------------\
@RoutineName :: TrackMediaSampleSizeAtom
@Description ::
Constructs a Track Media Sample Size Atom
@Parameters ::
Bytestream *stream :: The QT Atom byte stream
int sample_size :: if sample_size == 0 then size of each sample is constant, otherwise size of
each sample given in Ssize array
Uint32 Scount :: Number of samples
Uint32 *Ssize :: Sample size array
@Return ::
NONE
\-----------------------------------------------------------------------------*/
void TrackMediaSampleSizeAtom(Bytestream *stream, int sample_size, Uint32 Scount, Uint32 *Ssize) {
Uint32 i;
if (!sample_size)
put_bytes(stream, 4, 20+Scount*4); /* Atom Size */
else
put_bytes(stream, 4, 20); /* Atom Size */
put_bytes(stream, 4, ('s'<<24)+('t'<<16)+('s'<<8)+'z'); /* stsz */
put_bytes(stream, 4, 0); /* version + flags */
put_bytes(stream, 4, sample_size); /* Sample Size */
put_bytes(stream, 4, Scount); /* number of entries */
if (!sample_size)
for (i=0; i<Scount; i++) /* Sample size table */
put_bytes(stream, 4, Ssize[i]);
}
/*-----------------------------------------------------------------------------\
@RoutineName :: TrackMediaSampletoChunkAtom
@Description ::
Constructs a Track Media Sample to Chunk Atom
@Parameters ::
Bytestream *stream :: The QT Atom byte stream
Uint32 Scount :: Number of samples
@Return ::
NONE
\-----------------------------------------------------------------------------*/
void TrackMediaSampletoChunkAtom(Bytestream *stream, Uint32 Scount) {
put_bytes(stream, 4, 0x001c); /* Atom Size */
put_bytes(stream, 4, ('s'<<24)+('t'<<16)+('s'<<8)+'c'); /* stsc */
put_bytes(stream, 4, 0); /* version + flags */
put_bytes(stream, 4, 1); /* number of entries */
put_bytes(stream, 4, 1);
put_bytes(stream, 4, Scount);
put_bytes(stream, 4, 1);
}
/*-----------------------------------------------------------------------------\
@RoutineName :: TrackMediaChunkOffsetAtom
@Description ::
Constructs a Track Media Chunk Offset Atom
@Parameters ::
Bytestream *stream :: The QT Atom byte stream
Uint32 Scount :: Number of samples
Uint32 Coffset :: Chunk offset
Uint32 *Ssize :: Sample size array
@Return ::
NONE
\-----------------------------------------------------------------------------*/
void TrackMediaChunkOffsetAtom(Bytestream *stream, Uint32 Scount, Uint32 Coffset, Uint32 *Ssize) {
Uint32 i;
put_bytes(stream, 4, 0x0010 + 4*Scount); /* Atom Size */
put_bytes(stream, 4, ('s'<<24)+('t'<<16)+('c'<<8)+'o'); /* Type */
put_bytes(stream, 4, 0); /* version + flags */
put_bytes(stream, 4, Scount); /* number of entries */
put_bytes(stream, 4, Coffset);
for (i=0; i<Scount - 1; i++) {
Coffset +=Ssize[i];
put_bytes(stream, 4, Coffset);
}
}
void TrackMediaSampleSyncAtom( Bytestream *stream, Uint32 frame_count, Uint32 data_format, Uint16 key_frame_interval ) {
Uint32 nEntries;
Uint32 i;
Uint32 val;
if( data_format == QT_MJPEGA_FORMAT || key_frame_interval <= 1 )
return;
nEntries = frame_count/key_frame_interval;
if( frame_count % key_frame_interval != 0 )
nEntries++;
put_bytes( stream, 4, nEntries + 16 );
put_bytes(stream, 4, ('s'<<24)+('t'<<16)+('s'<<8)+'s'); /* Type */
put_bytes(stream, 4, 0); /* version + flags */
put_bytes(stream, 4, nEntries ); /* number of entries */
for( i=0, val=1; i<nEntries; i++, val+=key_frame_interval )
put_bytes(stream, 4, val ); /* number of entries */
}
void TrackMediaSoundMediaInfoHeaderAtom(Bytestream *stream) {
put_bytes(stream, 4, 0x0010);
put_bytes(stream, 4, ('s'<<24)+('m'<<16)+('h'<<8)+'d'); /* Type */
put_bytes(stream, 4, 0x0000); /* Version + flags */
put_bytes(stream, 4, 0x0000); /* Balance + Reserved */
}
void TrackMediaSoundSampleDescriptionAtom(Bytestream *stream,
int NumChannels, int sample_size, long sample_rate)
{
put_bytes(stream, 4, 0x0034); /* Atom Size */
put_bytes(stream, 4, ('s'<<24)+('t'<<16)+('s'<<8)+'d'); /* Sample Description type */
put_bytes(stream, 4, 0); /* version+flags */
put_bytes(stream, 4, 1); /* number of entries */
put_bytes(stream, 4, 0x0024); /* sample description size */
put_bytes(stream, 4, ('u'<<24)+('l'<<16)+('a'<<8)+'w'); /* data format */
put_bytes(stream, 4, 0); /* reserved 4 bytes */
put_bytes(stream, 4, 0x0001); /* reserved 2 byets + data reference index */
put_bytes(stream, 4, 0x0000); /* Version + revision level */
put_bytes(stream, 4, ('a'<<24)+('p'<<16)+('p'<<8)+'l'); /* Vendor */
put_bytes(stream, 4, (NumChannels<<16) + sample_size);
/* Number of channels + sample size */
put_bytes(stream, 4, 0); /* compression ID + packet size */
put_bytes(stream, 4, sample_rate); /* Width + height */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -