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-2012, 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'.  Give it a large buffer size, because the input H.264 NAL units may be large:
00051   unsigned const fileSinkBufferSize = 100000;
00052   MediaSink* outputSink = FileSink::createNew(*env, outputFileName, fileSinkBufferSize);
00053   if (outputSink == NULL) {
00054     *env << "Unable to open file \"" << outputFileName << "\" as a file sink\n";
00055     exit(1);
00056   }
00057 
00058   // Finally, start playing:
00059   *env << "Beginning to read...\n";
00060   outputSink->startPlaying(*tsFrames, afterPlaying, NULL);
00061 
00062   env->taskScheduler().doEventLoop(); // does not return
00063 
00064   return 0; // only to prevent compiler warning
00065 }
00066 
00067 void afterPlaying(void* /*clientData*/) {
00068   *env << "Done reading.\n";
00069   *env << "Wrote output file: \"" << outputFileName << "\"\n";
00070   exit(0);
00071 }

Generated on Thu May 17 07:11:47 2012 for live by  doxygen 1.5.2