working on AVI
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "structs.h"
|
||||
#include <iostream>
|
||||
|
||||
// https://docs.microsoft.com/en-us/previous-versions//ms779636(v=vs.85)?redirectedfrom=MSDN
|
||||
namespace AVI {
|
||||
@@ -12,8 +13,7 @@ namespace AVI {
|
||||
bool valid = true;
|
||||
AVITypeHeader riff;
|
||||
AVITypeHeader hdrl;
|
||||
AVICommonHeader avih;
|
||||
AVIMainHeader main_hdr;
|
||||
AVIMainHeader avih;
|
||||
|
||||
struct State {
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace AVI {
|
||||
|
||||
struct Video {
|
||||
uint32_t streamID;
|
||||
BitMapInfoHeader fmt;
|
||||
BitMapInfo fmt;
|
||||
} video;
|
||||
|
||||
struct Audio {
|
||||
@@ -49,14 +49,13 @@ namespace AVI {
|
||||
|
||||
read(avih);
|
||||
if (memcmp(avih.fourcc, "avih", 4) != 0) {valid = false; return;}
|
||||
if (avih.length != sizeof(main_hdr)) {valid = false; return;}
|
||||
if (avih.cb != 56) {valid = false; return;}
|
||||
|
||||
read(main_hdr);
|
||||
|
||||
uint32_t posOfStreamStart = pos;
|
||||
|
||||
for (uint32_t i = 0; i < main_hdr.streams; ++i) {
|
||||
for (uint32_t i = 0; i < avih.streams; ++i) {
|
||||
|
||||
uint32_t posOfStreamStart = pos;
|
||||
bool curStreamIsVideo = false;
|
||||
|
||||
AVITypeHeader strl;
|
||||
@@ -64,32 +63,30 @@ namespace AVI {
|
||||
if (memcmp(strl.fourcc, "LIST", 4) != 0) {valid = false; return;}
|
||||
if (memcmp(strl.type, "strl", 4) != 0) {valid = false; return;}
|
||||
|
||||
AVICommonHeader strh;
|
||||
AVIStreamHeader strh;
|
||||
read(strh);
|
||||
if (memcmp(strh.fourcc, "strh", 4) != 0) {valid = false; return;}
|
||||
|
||||
AVIStreamHeader stream_hdr;
|
||||
read(stream_hdr);
|
||||
if (memcmp(stream_hdr.type, "vids", 4) == 0) {
|
||||
if (memcmp(strh.type, "vids", 4) == 0) {
|
||||
state.video.streamID = i;
|
||||
state.streamHeaders[i] = stream_hdr;
|
||||
state.streamHeaders[i] = strh;
|
||||
curStreamIsVideo = true;
|
||||
} else if (memcmp(stream_hdr.type, "auds", 4) == 0) {
|
||||
} else if (memcmp(strh.type, "auds", 4) == 0) {
|
||||
state.audio.streamID = i;
|
||||
state.streamHeaders[i] = stream_hdr;
|
||||
state.streamHeaders[i] = strh;
|
||||
} else {
|
||||
valid = false; return;
|
||||
}
|
||||
|
||||
AVICommonHeader strf;
|
||||
read(strf);
|
||||
// ????
|
||||
uint8_t xx[8];
|
||||
read(xx);
|
||||
|
||||
// strf, depends on type (audio/video)
|
||||
if (curStreamIsVideo) {
|
||||
BitMapInfoHeader bmih;
|
||||
read(bmih);
|
||||
state.video.fmt = bmih;
|
||||
read(state.video.fmt); // BitmapInfoHeader
|
||||
} else {
|
||||
WaveFormat wf;
|
||||
read(state.audio.fmt);
|
||||
read(state.audio.fmt); // WaveFormatEx
|
||||
}
|
||||
|
||||
// seek to the next stream
|
||||
@@ -97,6 +94,13 @@ namespace AVI {
|
||||
|
||||
}
|
||||
|
||||
dumpState();
|
||||
|
||||
uint8_t tmp[128];
|
||||
read(tmp);
|
||||
|
||||
seek(pos-4);
|
||||
|
||||
AVITypeHeader movi;
|
||||
state.moviInfo.offset = pos;
|
||||
read(movi);
|
||||
@@ -124,10 +128,9 @@ namespace AVI {
|
||||
|
||||
|
||||
//seek(state.streamHeaders[state.video.streamID].start);
|
||||
AVICommonHeader chead;
|
||||
read(chead);
|
||||
//AVICommonHeader chead;
|
||||
//read(chead);
|
||||
|
||||
printf("nn");
|
||||
|
||||
}
|
||||
|
||||
@@ -153,6 +156,15 @@ namespace AVI {
|
||||
pos += size;
|
||||
}
|
||||
|
||||
|
||||
void dumpState() {
|
||||
|
||||
std::cout << "video @" << state.video.streamID << ": " << state.video.fmt.bmi_header.biWidth << "x" << state.video.fmt.bmi_header.biHeight << std::endl;
|
||||
std::cout << "audio @" << state.audio.streamID << ": " << state.audio.fmt.channels << " channels @ " << state.audio.fmt.samples_per_sec << " Hz" << std::endl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
typedef uint8_t FOURCC[4];
|
||||
|
||||
struct AVICommonHeader {
|
||||
FOURCC fourcc;
|
||||
uint32_t length;
|
||||
};
|
||||
//struct AVICommonHeader {
|
||||
// FOURCC fourcc;
|
||||
// uint32_t length;
|
||||
//};
|
||||
|
||||
struct AVITypeHeader {
|
||||
FOURCC fourcc;
|
||||
@@ -14,6 +14,8 @@ struct AVITypeHeader {
|
||||
};
|
||||
|
||||
struct AVIMainHeader {
|
||||
FOURCC fourcc;
|
||||
uint32_t cb;
|
||||
uint32_t ms_per_frame;
|
||||
uint32_t max_bytes_per_sec;
|
||||
uint32_t padding_granularity;
|
||||
@@ -27,9 +29,16 @@ struct AVIMainHeader {
|
||||
uint32_t reserved[4];
|
||||
};
|
||||
|
||||
struct AVIRect {
|
||||
uint16_t left;
|
||||
uint16_t top;
|
||||
uint16_t right;
|
||||
uint16_t bottom;
|
||||
};
|
||||
|
||||
struct AVIStreamHeader {
|
||||
//FOURCC fourcc;
|
||||
//uint32_t length;
|
||||
FOURCC fourcc;
|
||||
uint32_t cb;
|
||||
FOURCC type;
|
||||
FOURCC fcc_handler;
|
||||
uint32_t flags;
|
||||
@@ -43,12 +52,7 @@ struct AVIStreamHeader {
|
||||
uint32_t suggested_buffer_size;
|
||||
uint32_t quality;
|
||||
uint32_t sample_size;
|
||||
struct {
|
||||
uint16_t left;
|
||||
uint16_t top;
|
||||
uint16_t right;
|
||||
uint16_t bottom;
|
||||
} rcFrame;
|
||||
AVIRect rcFrame;
|
||||
};
|
||||
|
||||
struct BitMapInfoHeader {
|
||||
|
||||
Reference in New Issue
Block a user