testProgs/testH264VideoToTransportStream.cpp

Go to the documentation of this file.
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 H.264 (Elementary Stream) video file into a Transport Stream file.
00018 // main program
00019 
00020 #include "liveMedia.hh"
00021 #include "BasicUsageEnvironment.hh"
00022 
00023 char const* inputFileName = "in.264";
00024 char const* outputFileName = "out.ts";
00025 
00026 void afterPlaying(void* clientData); // forward
00027 
00028 UsageEnvironment* env;
00029 
00030 int main(int argc, char** argv) {
00031   // Begin by setting up our usage environment:
00032   TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00033   env = BasicUsageEnvironment::createNew(*scheduler);
00034 
00035   // Open the input file as a 'byte-stream file source':
00036   FramedSource* inputSource = ByteStreamFileSource::createNew(*env, inputFileName);
00037   if (inputSource == NULL) {
00038     *env << "Unable to open file \"" << inputFileName
00039          << "\" as a byte-stream file source\n";
00040     exit(1);
00041   }
00042 
00043   // Create a 'framer' filter for this file source, to generate presentation times for each NAL unit:
00044   H264VideoStreamFramer* framer = H264VideoStreamFramer::createNew(*env, inputSource, True/*includeStartCodeInOutput*/);
00045 
00046   // Then create a filter that packs the H.264 video data into a Transport Stream:
00047   MPEG2TransportStreamFromESSource* tsFrames = MPEG2TransportStreamFromESSource::createNew(*env);
00048   tsFrames->addNewVideoSource(framer, 5/*mpegVersion: H.264*/);
00049   
00050   // Open the output file as a 'file sink':
00051   MediaSink* outputSink = FileSink::createNew(*env, outputFileName);
00052   if (outputSink == NULL) {
00053     *env << "Unable to open file \"" << outputFileName << "\" as a file sink\n";
00054     exit(1);
00055   }
00056 
00057   // Finally, start playing:
00058   *env << "Beginning to read...\n";
00059   outputSink->startPlaying(*tsFrames, afterPlaying, NULL);
00060 
00061   env->taskScheduler().doEventLoop(); // does not return
00062 
00063   return 0; // only to prevent compiler warning
00064 }
00065 
00066 void afterPlaying(void* /*clientData*/) {
00067   *env << "Done reading.\n";
00068   *env << "Wrote output file: \"" << outputFileName << "\"\n";
00069   exit(0);
00070 }

Generated on Mon Apr 29 13:28:03 2013 for live by  doxygen 1.5.2