working on AVI

This commit is contained in:
2021-02-24 07:10:30 +01:00
parent 2b35a340f9
commit 851631e79d
3 changed files with 53 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "structs.h" #include "structs.h"
#include <iostream>
// https://docs.microsoft.com/en-us/previous-versions//ms779636(v=vs.85)?redirectedfrom=MSDN // https://docs.microsoft.com/en-us/previous-versions//ms779636(v=vs.85)?redirectedfrom=MSDN
namespace AVI { namespace AVI {
@@ -12,8 +13,7 @@ namespace AVI {
bool valid = true; bool valid = true;
AVITypeHeader riff; AVITypeHeader riff;
AVITypeHeader hdrl; AVITypeHeader hdrl;
AVICommonHeader avih; AVIMainHeader avih;
AVIMainHeader main_hdr;
struct State { struct State {
@@ -21,7 +21,7 @@ namespace AVI {
struct Video { struct Video {
uint32_t streamID; uint32_t streamID;
BitMapInfoHeader fmt; BitMapInfo fmt;
} video; } video;
struct Audio { struct Audio {
@@ -49,14 +49,13 @@ namespace AVI {
read(avih); read(avih);
if (memcmp(avih.fourcc, "avih", 4) != 0) {valid = false; return;} 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);
for (uint32_t i = 0; i < avih.streams; ++i) {
uint32_t posOfStreamStart = pos; uint32_t posOfStreamStart = pos;
for (uint32_t i = 0; i < main_hdr.streams; ++i) {
bool curStreamIsVideo = false; bool curStreamIsVideo = false;
AVITypeHeader strl; AVITypeHeader strl;
@@ -64,32 +63,30 @@ namespace AVI {
if (memcmp(strl.fourcc, "LIST", 4) != 0) {valid = false; return;} if (memcmp(strl.fourcc, "LIST", 4) != 0) {valid = false; return;}
if (memcmp(strl.type, "strl", 4) != 0) {valid = false; return;} if (memcmp(strl.type, "strl", 4) != 0) {valid = false; return;}
AVICommonHeader strh; AVIStreamHeader strh;
read(strh); read(strh);
if (memcmp(strh.fourcc, "strh", 4) != 0) {valid = false; return;} if (memcmp(strh.fourcc, "strh", 4) != 0) {valid = false; return;}
AVIStreamHeader stream_hdr; if (memcmp(strh.type, "vids", 4) == 0) {
read(stream_hdr);
if (memcmp(stream_hdr.type, "vids", 4) == 0) {
state.video.streamID = i; state.video.streamID = i;
state.streamHeaders[i] = stream_hdr; state.streamHeaders[i] = strh;
curStreamIsVideo = true; curStreamIsVideo = true;
} else if (memcmp(stream_hdr.type, "auds", 4) == 0) { } else if (memcmp(strh.type, "auds", 4) == 0) {
state.audio.streamID = i; state.audio.streamID = i;
state.streamHeaders[i] = stream_hdr; state.streamHeaders[i] = strh;
} else { } else {
valid = false; return; valid = false; return;
} }
AVICommonHeader strf; // ????
read(strf); uint8_t xx[8];
read(xx);
// strf, depends on type (audio/video)
if (curStreamIsVideo) { if (curStreamIsVideo) {
BitMapInfoHeader bmih; read(state.video.fmt); // BitmapInfoHeader
read(bmih);
state.video.fmt = bmih;
} else { } else {
WaveFormat wf; read(state.audio.fmt); // WaveFormatEx
read(state.audio.fmt);
} }
// seek to the next stream // seek to the next stream
@@ -97,6 +94,13 @@ namespace AVI {
} }
dumpState();
uint8_t tmp[128];
read(tmp);
seek(pos-4);
AVITypeHeader movi; AVITypeHeader movi;
state.moviInfo.offset = pos; state.moviInfo.offset = pos;
read(movi); read(movi);
@@ -124,10 +128,9 @@ namespace AVI {
//seek(state.streamHeaders[state.video.streamID].start); //seek(state.streamHeaders[state.video.streamID].start);
AVICommonHeader chead; //AVICommonHeader chead;
read(chead); //read(chead);
printf("nn");
} }
@@ -153,6 +156,15 @@ namespace AVI {
pos += size; 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;
}
}; };
} }

View File

@@ -2,10 +2,10 @@
typedef uint8_t FOURCC[4]; typedef uint8_t FOURCC[4];
struct AVICommonHeader { //struct AVICommonHeader {
FOURCC fourcc; // FOURCC fourcc;
uint32_t length; // uint32_t length;
}; //};
struct AVITypeHeader { struct AVITypeHeader {
FOURCC fourcc; FOURCC fourcc;
@@ -14,6 +14,8 @@ struct AVITypeHeader {
}; };
struct AVIMainHeader { struct AVIMainHeader {
FOURCC fourcc;
uint32_t cb;
uint32_t ms_per_frame; uint32_t ms_per_frame;
uint32_t max_bytes_per_sec; uint32_t max_bytes_per_sec;
uint32_t padding_granularity; uint32_t padding_granularity;
@@ -27,9 +29,16 @@ struct AVIMainHeader {
uint32_t reserved[4]; uint32_t reserved[4];
}; };
struct AVIRect {
uint16_t left;
uint16_t top;
uint16_t right;
uint16_t bottom;
};
struct AVIStreamHeader { struct AVIStreamHeader {
//FOURCC fourcc; FOURCC fourcc;
//uint32_t length; uint32_t cb;
FOURCC type; FOURCC type;
FOURCC fcc_handler; FOURCC fcc_handler;
uint32_t flags; uint32_t flags;
@@ -43,12 +52,7 @@ struct AVIStreamHeader {
uint32_t suggested_buffer_size; uint32_t suggested_buffer_size;
uint32_t quality; uint32_t quality;
uint32_t sample_size; uint32_t sample_size;
struct { AVIRect rcFrame;
uint16_t left;
uint16_t top;
uint16_t right;
uint16_t bottom;
} rcFrame;
}; };
struct BitMapInfoHeader { struct BitMapInfoHeader {

View File

@@ -94,7 +94,7 @@ int main(int argc, char** argv) {
AVI::Demuxer demux(ah); AVI::Demuxer demux(ah);
bool valid = demux.isValid(); bool valid = demux.isValid();
std::cout << valid << std::endl; std::cout << "valid: " << valid << std::endl;
return 0; return 0;