|
| 1 | +#include <AvTranscoder/transcoder/Transcoder.hpp> |
| 2 | +#include <AvTranscoder/file/OutputFile.hpp> |
| 3 | + |
| 4 | +static std::string outputFileName = "thumbnail.jpg"; |
| 5 | + |
| 6 | +int main( int argc, char** argv ) |
| 7 | +{ |
| 8 | + std::string help; |
| 9 | + help += "Usage\n"; |
| 10 | + help += "\tavthumbnail INPUT_FILE_NAME FRAME [OUTPUT_FILE_NAME] [--help]\n"; |
| 11 | + help += "Command line options\n"; |
| 12 | + help += "\tOUTPUT_FILE_NAME: name of the output file (thumbnail.jpg by default)\n"; |
| 13 | + help += "\t--help: display this help\n"; |
| 14 | + |
| 15 | + // List command line arguments |
| 16 | + std::vector< std::string > arguments; |
| 17 | + for( int argument = 1; argument < argc; ++argument ) |
| 18 | + { |
| 19 | + arguments.push_back( argv[argument] ); |
| 20 | + } |
| 21 | + for( size_t argument = 0; argument < arguments.size(); ++argument ) |
| 22 | + { |
| 23 | + if( arguments.at( argument ) == "--help" ) |
| 24 | + { |
| 25 | + std::cout << help << std::endl; |
| 26 | + return 0; |
| 27 | + } |
| 28 | + } |
| 29 | + if( argc > 3 ) |
| 30 | + { |
| 31 | + outputFileName = arguments.at( 2 ); |
| 32 | + } |
| 33 | + |
| 34 | + // Check required arguments |
| 35 | + if( argc < 3 ) |
| 36 | + { |
| 37 | + std::cout << "avthumbnail creates a thumbnail from an input file at an indicated frame." << std::endl; |
| 38 | + std::cout << "Use option --help to display help" << std::endl; |
| 39 | + return( -1 ); |
| 40 | + } |
| 41 | + |
| 42 | + avtranscoder::setLogLevel( AV_LOG_QUIET ); |
| 43 | + avtranscoder::preloadCodecsAndFormats(); |
| 44 | + |
| 45 | + // input file |
| 46 | + std::string inputFileName( argv[1] ); |
| 47 | + avtranscoder::InputFile intputFile( inputFileName ); |
| 48 | + intputFile.seekAtFrame( atoi( argv[2] ) ); |
| 49 | + |
| 50 | + // output file |
| 51 | + avtranscoder::ProfileLoader::Profile formatProfile; |
| 52 | + formatProfile[ avtranscoder::constants::avProfileIdentificator ] = "thumbnailFormatPreset"; |
| 53 | + formatProfile[ avtranscoder::constants::avProfileIdentificatorHuman ] = "Thumbnail format preset"; |
| 54 | + formatProfile[ avtranscoder::constants::avProfileType ] = avtranscoder::constants::avProfileTypeFormat; |
| 55 | + formatProfile[ avtranscoder::constants::avProfileFormat ] = "mjpeg"; |
| 56 | + avtranscoder::OutputFile outputFile( outputFileName ); |
| 57 | + outputFile.setProfile( formatProfile ); |
| 58 | + |
| 59 | + // input stream |
| 60 | + avtranscoder::InputStream inputStream( intputFile, 0 ); |
| 61 | + inputStream.activate(); |
| 62 | + |
| 63 | + // output stream |
| 64 | + avtranscoder::ProfileLoader profileLoader( true ); |
| 65 | + avtranscoder::StreamTranscoder outputStream( inputStream, outputFile, profileLoader.getProfile( "mjpeg" ) ); |
| 66 | + |
| 67 | + // transcoder |
| 68 | + avtranscoder::Transcoder transcoder( outputFile ); |
| 69 | + transcoder.add( outputStream ); |
| 70 | + |
| 71 | + // process |
| 72 | + outputFile.beginWrap(); |
| 73 | + transcoder.preProcessCodecLatency(); |
| 74 | + transcoder.processFrame(); |
| 75 | + outputFile.endWrap(); |
| 76 | +} |
0 commit comments