diff --git a/src/converters/dtsc2mp4.cpp b/src/converters/dtsc2mp4.cpp index 33734568..efcc70ca 100644 --- a/src/converters/dtsc2mp4.cpp +++ b/src/converters/dtsc2mp4.cpp @@ -13,6 +13,7 @@ #include #include //DTSC support #include //MP4 support +#include //TS support ff #include ///\brief Holds everything unique to converters. @@ -22,10 +23,18 @@ namespace Converters { ///\return The return code for the converter. int DTSC2MP4(Util::Config & conf){ DTSC::File input(conf.getString("filename")); - std::cerr << input.getMeta()["tracks"]["video0"].size() << std::endl; //ftyp box + /// \todo fill ftyp with non hardcoded values from file 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()); + + //moov box MP4::MOOV moovBox; MP4::MVHD mvhdBox; @@ -33,10 +42,17 @@ namespace Converters { //start arbitrary track addition 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++){ MP4::TRAK trakBox; 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()); if (it->second["type"].asString() == "video"){ @@ -59,35 +75,61 @@ namespace Converters { MP4::STBL stblBox; MP4::STSD stsdBox; - std::string tmpStr = it->second["type"].asString(); + /*std::string tmpStr = it->second["type"].asString(); if (tmpStr == "video"){//boxname = codec 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); }else if(tmpStr == "audio"){//boxname = codec 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); - } + }*/ stblBox.setContent(stsdBox,0); 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; - newEntry.sampleCount = it->second["frags"][i]["len"].asInt(); - newEntry.sampleDelta = it->second["frags"][i]["dur"].asInt() / newEntry.sampleCount; + newEntry.sampleCount = 1; + newEntry.sampleDelta = it->second["keylen"][i].asInt(); sttsBox.setSTTSEntry(newEntry, i); } stblBox.setContent(sttsBox,1); 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); MP4::STSZ stszBox; + /// \todo calculate byte position of DTSCkeyframes in MP4Sample + stszBox.setSampleSize(0); 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); - + MP4::STCO stcoBox; + for (int i = 0; i < it->second["keylen"].size(); i++){ + stcoBox.setChunkOffset(0, i); + } stblBox.setContent(stcoBox,4); minfBox.setContent(stblBox,1); mdiaBox.setContent(minfBox, 2); @@ -96,9 +138,25 @@ namespace Converters { boxOffset++; } //end arbitrary - //std::cout << input.getMeta()["audio"].toPrettyString() << std::endl; std::cout << std::string(moovBox.asBox(),moovBox.boxedSize()); + //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; } //DTSC2MP4