Extra commit MP4 working

This commit is contained in:
Oswald Auguste de Bruin 2013-08-21 10:03:41 +02:00 committed by Erik Zandvliet
parent ac286e799a
commit 1096297941

View file

@ -30,15 +30,6 @@ namespace Converters {
bool keyPartSort(keyPart i, keyPart j){ bool keyPartSort(keyPart i, keyPart j){
return (i.time < j.time); return (i.time < j.time);
} }
struct mdatBuffer{
long long int trackID;
long long int curLength;
std::string buffer;
};
///\brief Converts DTSC from file to MP4 on stdout. ///\brief Converts DTSC from file to MP4 on stdout.
///\return The return code for the converter. ///\return The return code for the converter.
int DTSC2MP4(Util::Config & conf){ int DTSC2MP4(Util::Config & conf){
@ -50,9 +41,8 @@ namespace Converters {
ftypBox.setMinorVersion(0); ftypBox.setMinorVersion(0);
ftypBox.setCompatibleBrands(0x6D703431,0); ftypBox.setCompatibleBrands(0x6D703431,0);
std::cout << std::string(ftypBox.asBox(),ftypBox.boxedSize()); std::cout << std::string(ftypBox.asBox(),ftypBox.boxedSize());
uint64_t mdatSize = 0;
//moov box //moov box
MP4::MOOV moovBox; MP4::MOOV moovBox;
MP4::MVHD mvhdBox; MP4::MVHD mvhdBox;
@ -135,9 +125,9 @@ namespace Converters {
mdhdBox.setCreationTime(0); mdhdBox.setCreationTime(0);
mdhdBox.setModificationTime(0); mdhdBox.setModificationTime(0);
if(it->second["type"].asString() == "video"){ if(it->second["type"].asString() == "video"){
timescale = 11988; timescale = it->second["fpks"].asInt()/10;
}else{ }else{
timescale = 48000; timescale = it->second["rate"].asInt();
} }
mdhdBox.setTimeScale(timescale); mdhdBox.setTimeScale(timescale);
mdhdBox.setDuration(((it->second["lastms"].asInt() + it->second["firsms"].asInt()) * ((double)timescale / 1000))); mdhdBox.setDuration(((it->second["lastms"].asInt() + it->second["firsms"].asInt()) * ((double)timescale / 1000)));
@ -195,8 +185,7 @@ namespace Converters {
ase.setDataReferenceIndex(1); ase.setDataReferenceIndex(1);
} }
ase.setSampleRate(it->second["rate"].asInt()); ase.setSampleRate(it->second["rate"].asInt());
//ase.setChannelCount(it->second["channels"].asInt()); ase.setChannelCount(it->second["channels"].asInt());
ase.setChannelCount(2);
ase.setSampleSize(it->second["size"].asInt()); ase.setSampleSize(it->second["size"].asInt());
MP4::ESDS esdsBox; MP4::ESDS esdsBox;
esdsBox.setESDescriptorTypeLength(32+it->second["init"].asString().size()); esdsBox.setESDescriptorTypeLength(32+it->second["init"].asString().size());
@ -277,12 +266,6 @@ namespace Converters {
uint64_t totalByteOffset = 0; uint64_t totalByteOffset = 0;
//Inserting wrong values on purpose here, will be fixed later. //Inserting wrong values on purpose here, will be fixed later.
//Current values are actual byte offset without header-sized offset //Current values are actual byte offset without header-sized offset
/*for (unsigned int i = 0; i < it->second["keys"].size(); i++){
for (unsigned int o = 0; o < it->second["keys"][i]["parts"].size(); o++){
stcoBox.setChunkOffset(it->second["keys"][i]["parts"][o].asInt(), total);
total++;
}
}*/
for (unsigned int i = 0; i < keyParts.size(); i++){//for all keypart size for (unsigned int i = 0; i < keyParts.size(); i++){//for all keypart size
if(keyParts[i].trackID == it->second["trackid"].asInt()){//if keypart is of current trackID if(keyParts[i].trackID == it->second["trackid"].asInt()){//if keypart is of current trackID
for (unsigned int o = 0; o < keyParts[i].parts.size(); o++){//add all parts to STCO for (unsigned int o = 0; o < keyParts[i].parts.size(); o++){//add all parts to STCO
@ -294,6 +277,7 @@ namespace Converters {
totalByteOffset += keyParts[i].size; totalByteOffset += keyParts[i].size;
} }
} }
mdatSize = totalByteOffset;
stblBox.setContent(stcoBox,4 + offset); stblBox.setContent(stcoBox,4 + offset);
minfBox.setContent(stblBox,2); minfBox.setContent(stblBox,2);
@ -347,54 +331,62 @@ namespace Converters {
} }
} }
/*std::cerr << "Ik ben hier" << std::endl;
for (std::map<int, MP4::STCO&>::iterator i = STCOFix.begin(); i != STCOFix.end(); i++){
std::cerr << "Hier wil ik heen: " << i->first << ", " << i->second.getEntryCount() << std::endl;
std::cerr << (i->second).boxedSize() << std::endl;
for (unsigned int o = 0; o < i->second.getEntryCount(); o++){
//std::cerr << " " << o ;
uint64_t temp;
temp = i->second.getChunkOffset(o);
i->second.setChunkOffset(byteOffset, o);
byteOffset += temp;
}
}*/
std::cout << std::string(moovBox.asBox(),moovBox.boxedSize()); std::cout << std::string(moovBox.asBox(),moovBox.boxedSize());
std::cerr << "Header Written" << std::endl;
//end of header //end of header
//mdat box a lot
//video //mdat box making it interleaved
//while() printf("%c%c%c%cmdat", (mdatSize>>24) & 0x000000FF,(mdatSize>>16) & 0x000000FF,(mdatSize>>8) & 0x000000FF,mdatSize & 0x000000FF);
//for(input.seekNext(); input.getJSON(); input.seekNext()) std::map <long long unsigned int, std::deque<JSON::Value> > trackBuffer;
//cout << input.getJSON["data"].asString() long long unsigned int curKey = 0;//the key chunk we are currently searching for in keyParts
long long unsigned int curPart = 0;//current part in current key
//initialising JSON input
std::set<int> selector; std::set<int> selector;
for (JSON::ObjIter trackIt = input.getMeta()["tracks"].ObjBegin(); trackIt != input.getMeta()["tracks"].ObjEnd(); trackIt++){ for (JSON::ObjIter trackIt = input.getMeta()["tracks"].ObjBegin(); trackIt != input.getMeta()["tracks"].ObjEnd(); trackIt++){
selector.insert(trackIt->second["trackid"].asInt()); selector.insert(trackIt->second["trackid"].asInt());
} }
input.selectTracks(selector); input.selectTracks(selector);
input.seek_time(0); input.seek_time(0);
input.seekNext(); input.seekNext();
std::vector<std::string> dataParts;
while (input.getJSON()){ while (input.getJSON()){
//if not in vector, create; //std::cerr << "DataSize: " << input.getJSON()["data"].asString().size() << std::endl;
if (dataParts.size() < input.getJSON()["trackid"].asInt()){ //mdat output here
dataParts.resize(input.getJSON()["trackid"].asInt()); //output cleanout buffer first
//while there are requested packets in the trackBuffer:...
while (!trackBuffer[keyParts[curKey].trackID].empty()){
//output requested packages
if(keyParts[curKey].parts[curPart].asInt() != trackBuffer[keyParts[curKey].trackID].front()["data"].asString().size()){
std::cerr << "Size discrepancy in buffer packet. Size: " << input.getJSON()["data"].asString().size() << " Expected:" << keyParts[curKey].parts[curPart].asInt() << std::endl;
}
std::cout << trackBuffer[keyParts[curKey].trackID].front()["data"].asString();
trackBuffer[keyParts[curKey].trackID].pop_front();
curPart++;
if(curPart >= keyParts[curKey].parts.size()){
curPart = 0;
curKey++;
}
}
//after that, try to put out the JSON data directly
if(keyParts[curKey].trackID == input.getJSON()["trackid"].asInt()){
//output JSON packet
if(keyParts[curKey].parts[curPart].asInt() != input.getJSON()["data"].asString().size()){
std::cerr << "Size discrepancy in JSON packet. Size: " << input.getJSON()["data"].asString().size() << " Expected:" << keyParts[curKey].parts[curPart].asInt() << std::endl;
}
std::cout << input.getJSON()["data"].asString();
curPart++;
if(curPart >= keyParts[curKey].parts.size()){
curPart = 0;
curKey++;
}
}else{
//buffer for later
trackBuffer[input.getJSON()["trackid"].asInt()].push_back(input.getJSON());
} }
//putting everything in its place
dataParts[input.getJSON()["trackid"].asInt()-1] += input.getJSON()["data"].asString();
input.seekNext(); input.seekNext();
} }
uint32_t mdatSize = 0; //output remaining buffer
for (unsigned int x = 0; x < dataParts.size(); x++){
mdatSize += dataParts[x].size();
}
//std::cerr << "Total Data size: " << mdatSize << std::endl;
printf("%c%c%c%cmdat", (mdatSize>>24) & 0x000000FF,(mdatSize>>16) & 0x000000FF,(mdatSize>>8) & 0x000000FF,mdatSize & 0x000000FF);
for (unsigned int x = 0; x < dataParts.size(); x++){
std::cout << dataParts[x];
}*/
return 0; return 0;
} //DTSC2MP4 } //DTSC2MP4