Added file output option to MistFLV2DTSC

This commit is contained in:
Erik Zandvliet 2013-02-28 11:51:43 +01:00 committed by Thulinma
parent e3bb5253d0
commit 5f625a89b8

View file

@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <cstdlib> #include <cstdlib>
@ -40,17 +41,23 @@ namespace Converters {
if (counter > 8){ if (counter > 8){
sending = true; sending = true;
meta_out["moreheader"] = 0LL; meta_out["moreheader"] = 0LL;
std::cout << meta_out.toNetPacked(); std::string packed_header = meta_out.toNetPacked();
std::cout << prebuffer.rdbuf(); unsigned int size = htonl(packed_header.size());
output << std::string(DTSC::Magic_Header, 4) << std::string((char*) &size, 4) << packed_header;
output << prebuffer.rdbuf();
prebuffer.str(""); prebuffer.str("");
std::cerr << "Buffer done, starting real-time output..." << std::endl; std::cerr << "Buffer done, starting real-time output..." << std::endl;
}else{ }else{
prebuffer << pack_out.toNetPacked(); std::string packed_out = pack_out.toNetPacked();
unsigned int size = htonl(packed_out.size());
prebuffer << std::string(DTSC::Magic_Packet, 4) << std::string((char*) &size, 4) << packed_out;
continue; //don't also write continue; //don't also write
} }
} }
//simply write //simply write
std::cout << pack_out.toNetPacked(); std::string packed_out = pack_out.toNetPacked();
unsigned int size = htonl(packed_out.size());
output << std::string(DTSC::Magic_Packet, 4) << std::string((char*) &size, 4) << packed_out;
} }
} }
@ -58,10 +65,12 @@ namespace Converters {
if ( !sending){ if ( !sending){
std::cerr << "EOF - outputting buffer..." << std::endl; std::cerr << "EOF - outputting buffer..." << std::endl;
meta_out["moreheader"] = 0LL; meta_out["moreheader"] = 0LL;
std::cout << meta_out.toNetPacked(); std::string packed_header = meta_out.toNetPacked();
std::cout << prebuffer.rdbuf(); unsigned int size = htonl(packed_header.size());
output << std::string(DTSC::Magic_Header, 4) << std::string((char*) &size, 4) << packed_header;
output << prebuffer.rdbuf();
} }
std::cerr << "Done!" << std::endl; std::cerr << "Done! If you output this data to a file, don't forget to run MistDTSCFix next." << std::endl;
return 0; return 0;
} //FLV2DTSC } //FLV2DTSC
@ -71,6 +80,13 @@ namespace Converters {
///\brief Entry point for FLV2DTSC, simply calls Converters::FLV2DTSC(). ///\brief Entry point for FLV2DTSC, simply calls Converters::FLV2DTSC().
int main(int argc, char ** argv){ int main(int argc, char ** argv){
Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION); Util::Config conf = Util::Config(argv[0], PACKAGE_VERSION);
conf.addOption("output",
JSON::fromString(
"{\"long\":\"output\", \"value\":[\"stdout\"], \"short\":\"o\", \"arg\":\"string\", \"help\":\"Name of the outputfile or stdout for standard output.\"}"));
conf.parseArgs(argc, argv); conf.parseArgs(argc, argv);
return Converters::FLV2DTSC(); if (conf.getString("output") == "stdout"){
return Converters::FLV2DTSC(std::cout);
}
std::ofstream oFile(conf.getString("output").c_str());
return Converters::FLV2DTSC(oFile);
} //main } //main