00001 /********** 00002 This library is free software; you can redistribute it and/or modify it under 00003 the terms of the GNU Lesser General Public License as published by the 00004 Free Software Foundation; either version 2.1 of the License, or (at your 00005 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.) 00006 00007 This library is distributed in the hope that it will be useful, but WITHOUT 00008 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00009 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00010 more details. 00011 00012 You should have received a copy of the GNU Lesser General Public License 00013 along with this library; if not, write to the Free Software Foundation, Inc., 00014 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00015 **********/ 00016 // Copyright (c) 1996-2013, Live Networks, Inc. All rights reserved 00017 // A program that converts a MPEG-1 or 2 Program Stream file into 00018 // a Transport Stream file. 00019 // main program 00020 00021 #include "liveMedia.hh" 00022 #include "BasicUsageEnvironment.hh" 00023 00024 char const* inputFileName = "in.mpg"; 00025 char const* outputFileName = "out.ts"; 00026 00027 void afterPlaying(void* clientData); // forward 00028 00029 UsageEnvironment* env; 00030 00031 int main(int argc, char** argv) { 00032 // Begin by setting up our usage environment: 00033 TaskScheduler* scheduler = BasicTaskScheduler::createNew(); 00034 env = BasicUsageEnvironment::createNew(*scheduler); 00035 00036 // Open the input file as a 'byte-stream file source': 00037 FramedSource* inputSource = ByteStreamFileSource::createNew(*env, inputFileName); 00038 if (inputSource == NULL) { 00039 *env << "Unable to open file \"" << inputFileName 00040 << "\" as a byte-stream file source\n"; 00041 exit(1); 00042 } 00043 00044 // Create a MPEG demultiplexor that reads from that source. 00045 MPEG1or2Demux* baseDemultiplexor = MPEG1or2Demux::createNew(*env, inputSource); 00046 00047 // Create, from this, a source that returns raw PES packets: 00048 MPEG1or2DemuxedElementaryStream* pesSource = baseDemultiplexor->newRawPESStream(); 00049 00050 // And, from this, a filter that converts to MPEG-2 Transport Stream frames: 00051 FramedSource* tsFrames 00052 = MPEG2TransportStreamFromPESSource::createNew(*env, pesSource); 00053 00054 // Open the output file as a 'file sink': 00055 MediaSink* outputSink = FileSink::createNew(*env, outputFileName); 00056 if (outputSink == NULL) { 00057 *env << "Unable to open file \"" << outputFileName << "\" as a file sink\n"; 00058 exit(1); 00059 } 00060 00061 // Finally, start playing: 00062 *env << "Beginning to read...\n"; 00063 outputSink->startPlaying(*tsFrames, afterPlaying, NULL); 00064 00065 env->taskScheduler().doEventLoop(); // does not return 00066 00067 return 0; // only to prevent compiler warning 00068 } 00069 00070 void afterPlaying(void* /*clientData*/) { 00071 *env << "Done reading.\n"; 00072 *env << "Wrote output file: \"" << outputFileName << "\"\n"; 00073 exit(0); 00074 }
1.5.2