DTSC2MP4 further

This commit is contained in:
Oswald de Bruin 2013-05-28 16:12:11 +02:00 committed by Erik Zandvliet
parent e315993abc
commit 3f97951954

View file

@ -13,6 +13,7 @@
#include <mist/json.h> #include <mist/json.h>
#include <mist/dtsc.h> //DTSC support #include <mist/dtsc.h> //DTSC support
#include <mist/mp4.h> //MP4 support #include <mist/mp4.h> //MP4 support
#include <mist/ts_packet.h> //TS support ff
#include <mist/config.h> #include <mist/config.h>
///\brief Holds everything unique to converters. ///\brief Holds everything unique to converters.
@ -22,10 +23,18 @@ namespace Converters {
///\return The return code for the converter. ///\return The return code for the converter.
int DTSC2MP4(Util::Config & conf){ int DTSC2MP4(Util::Config & conf){
DTSC::File input(conf.getString("filename")); DTSC::File input(conf.getString("filename"));
std::cerr << input.getMeta()["tracks"]["video0"].size() << std::endl;
//ftyp box //ftyp box
/// \todo fill ftyp with non hardcoded values from file
MP4::FTYP ftypBox; MP4::FTYP ftypBox;
ftypBox.setMajorBrand(0x69736f6d);
ftypBox.setMinorVersion(512);
ftypBox.setCompatibleBrands(0x69736f6d,0);
ftypBox.setCompatibleBrands(0x69736f32,1);
ftypBox.setCompatibleBrands(0x61766331,2);
ftypBox.setCompatibleBrands(0x6d703431,3);
std::cout << std::string(ftypBox.asBox(),ftypBox.boxedSize()); std::cout << std::string(ftypBox.asBox(),ftypBox.boxedSize());
//moov box //moov box
MP4::MOOV moovBox; MP4::MOOV moovBox;
MP4::MVHD mvhdBox; MP4::MVHD mvhdBox;
@ -33,10 +42,17 @@ namespace Converters {
//start arbitrary track addition //start arbitrary track addition
int boxOffset = 1; int boxOffset = 1;
input.getMeta()["tracks"]["audio0"] = input.getMeta()["audio"];
input.getMeta()["tracks"]["audio0"]["type"] = "audio";
input.getMeta()["tracks"]["audio0"]["trackid"] = 1;
input.getMeta()["tracks"]["video0"] = input.getMeta()["video"];
input.getMeta()["tracks"]["video0"]["keylen"] = input.getMeta()["keylen"];
input.getMeta()["tracks"]["video0"]["trackid"] = 2;
input.getMeta()["tracks"]["video0"]["type"] = "video";
for (JSON::ObjIter it = input.getMeta()["tracks"].ObjBegin(); it != input.getMeta()["tracks"].ObjEnd(); it++){ for (JSON::ObjIter it = input.getMeta()["tracks"].ObjBegin(); it != input.getMeta()["tracks"].ObjEnd(); it++){
MP4::TRAK trakBox; MP4::TRAK trakBox;
MP4::TKHD tkhdBox; MP4::TKHD tkhdBox;
std::cerr << it->second["trackid"].asInt() << std::endl; //std::cerr << it->second["trackid"].asInt() << std::endl;
tkhdBox.setTrackID(it->second["trackid"].asInt()); tkhdBox.setTrackID(it->second["trackid"].asInt());
if (it->second["type"].asString() == "video"){ if (it->second["type"].asString() == "video"){
@ -59,35 +75,61 @@ namespace Converters {
MP4::STBL stblBox; MP4::STBL stblBox;
MP4::STSD stsdBox; MP4::STSD stsdBox;
std::string tmpStr = it->second["type"].asString(); /*std::string tmpStr = it->second["type"].asString();
if (tmpStr == "video"){//boxname = codec if (tmpStr == "video"){//boxname = codec
MP4::VisualSampleEntry vse; MP4::VisualSampleEntry vse;
std::string tmpStr2 = it->second["codec"];
if (tmpStr2 == "H264"){
vse.setCodec("avc1");
}
vse.setWidth(it->second["width"].asInt());
vse.setHeight(it->second["height"].asInt());
stsdBox.setEntry(vse,0); stsdBox.setEntry(vse,0);
}else if(tmpStr == "audio"){//boxname = codec }else if(tmpStr == "audio"){//boxname = codec
MP4::AudioSampleEntry ase; MP4::AudioSampleEntry ase;
std::string tmpStr2 = it->second["codec"];
if (tmpStr2 == "AAC"){
ase.setCodec("aac ");
}
ase.setSampleRate(it->second["rate"].asInt());
ase.setChannelCount(it->second["channels"].asInt());
ase.setSampleSize(it->second["length"].asInt());
stsdBox.setEntry(ase,0); stsdBox.setEntry(ase,0);
} }*/
stblBox.setContent(stsdBox,0); stblBox.setContent(stsdBox,0);
MP4::STTS sttsBox; MP4::STTS sttsBox;
for (int i = 0; i < it->second["frags"].size(); i++){ for (int i = 0; i < it->second["keylen"].size(); i++){
MP4::STTSEntry newEntry; MP4::STTSEntry newEntry;
newEntry.sampleCount = it->second["frags"][i]["len"].asInt(); newEntry.sampleCount = 1;
newEntry.sampleDelta = it->second["frags"][i]["dur"].asInt() / newEntry.sampleCount; newEntry.sampleDelta = it->second["keylen"][i].asInt();
sttsBox.setSTTSEntry(newEntry, i); sttsBox.setSTTSEntry(newEntry, i);
} }
stblBox.setContent(sttsBox,1); stblBox.setContent(sttsBox,1);
MP4::STSC stscBox; MP4::STSC stscBox;
for (int i = 0; i < it->second["keylen"].size(); i++){
MP4::STSCEntry newEntry;
newEntry.firstChunk = i;
newEntry.samplesPerChunk = 1;
newEntry.sampleDescriptionIndex = i;
stscBox.setSTSCEntry(newEntry, i);
}
stblBox.setContent(stscBox,2); stblBox.setContent(stscBox,2);
MP4::STSZ stszBox; MP4::STSZ stszBox;
/// \todo calculate byte position of DTSCkeyframes in MP4Sample
stszBox.setSampleSize(0);
for (int i = 0; i < it->second["keylen"].size(); i++){ for (int i = 0; i < it->second["keylen"].size(); i++){
stszBox.setEntrySize(it->second["keylen"][i].asInt(), i); stszBox.setEntrySize(0, i);
} }
stblBox.setContent(stszBox,3); stblBox.setContent(stszBox,3);
MP4::STCO stcoBox; MP4::STCO stcoBox;
for (int i = 0; i < it->second["keylen"].size(); i++){
stcoBox.setChunkOffset(0, i);
}
stblBox.setContent(stcoBox,4); stblBox.setContent(stcoBox,4);
minfBox.setContent(stblBox,1); minfBox.setContent(stblBox,1);
mdiaBox.setContent(minfBox, 2); mdiaBox.setContent(minfBox, 2);
@ -96,9 +138,25 @@ namespace Converters {
boxOffset++; boxOffset++;
} }
//end arbitrary //end arbitrary
//std::cout << input.getMeta()["audio"].toPrettyString() << std::endl;
std::cout << std::string(moovBox.asBox(),moovBox.boxedSize()); std::cout << std::string(moovBox.asBox(),moovBox.boxedSize());
//mdat box alot //mdat box alot
//video
//while()
//for(input.seekNext(); input.getJSON(); input.seekNext())
//cout << input.getJSON["data"].asString()
//audio
// ToPack.append(TS::GetAudioHeader(Strm.lastData().size(), Strm.metadata["audio"]["init"].asString()));
// ToPack.append(Strm.lastData());
printf("%c%c%c%cmdat", 0x00,0x00,0x01,0x00);
//std::cout << "\200\000\000\010mdat";
for(input.seekNext(); input.getJSON(); input.seekNext()){
if(input.getJSON()["datatype"] == "video" /*|| input.getJSON()["datatype"] == "audio"*/){
std::cout << input.getJSON()["data"].asString();
}
}
return 0; return 0;
} //DTSC2MP4 } //DTSC2MP4