00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <liveMedia.hh>
00024 #include <BasicUsageEnvironment.hh>
00025
00026 void afterPlaying(void* clientData);
00027
00028 UsageEnvironment* env;
00029 char const* programName;
00030
00031 void usage() {
00032 *env << "usage: " << programName << " <transport-stream-file-name>\n";
00033 *env << "\twhere <transport-stream-file-name> ends with \".ts\"\n";
00034 exit(1);
00035 }
00036
00037 int main(int argc, char const** argv) {
00038
00039 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00040 env = BasicUsageEnvironment::createNew(*scheduler);
00041
00042
00043 programName = argv[0];
00044 if (argc != 2) usage();
00045
00046 char const* inputFileName = argv[1];
00047
00048 int len = strlen(inputFileName);
00049 if (len < 4 || strcmp(&inputFileName[len-3], ".ts") != 0) {
00050 *env << "ERROR: input file name \"" << inputFileName
00051 << "\" does not end with \".ts\"\n";
00052 usage();
00053 }
00054
00055
00056 FramedSource* input
00057 = ByteStreamFileSource::createNew(*env, inputFileName, TRANSPORT_PACKET_SIZE);
00058 if (input == NULL) {
00059 *env << "Failed to open input file \"" << inputFileName << "\" (does it exist?)\n";
00060 exit(1);
00061 }
00062
00063
00064 FramedSource* indexer
00065 = MPEG2IFrameIndexFromTransportStream::createNew(*env, input);
00066
00067
00068 char* outputFileName = new char[len+2];
00069 sprintf(outputFileName, "%sx", inputFileName);
00070
00071
00072 MediaSink* output = FileSink::createNew(*env, outputFileName);
00073 if (output == NULL) {
00074 *env << "Failed to open output file \"" << outputFileName << "\"\n";
00075 exit(1);
00076 }
00077
00078
00079 *env << "Writing index file \"" << outputFileName << "\"...";
00080 output->startPlaying(*indexer, afterPlaying, NULL);
00081
00082 env->taskScheduler().doEventLoop();
00083
00084 return 0;
00085 }
00086
00087 void afterPlaying(void* ) {
00088 *env << "...done\n";
00089 exit(0);
00090 }