forked from mikrosimage/avTranscoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavProcessor.cpp
More file actions
161 lines (141 loc) · 4.79 KB
/
Copy pathavProcessor.cpp
File metadata and controls
161 lines (141 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <AvTranscoder/transcoder/Transcoder.hpp>
#include <AvTranscoder/file/OutputFile.hpp>
#include <AvTranscoder/progress/ConsoleProgress.hpp>
#include <iostream>
#include <iomanip>
#include <vector>
#include <fstream>
#include <sstream>
#include <cstdlib>
static const size_t dummyWidth = 1920;
static const size_t dummyHeight = 1080;
static const std::string dummyPixelFormat = "yuv420p";
static const std::string dummyVideoCodec = "mpeg2video";
static const size_t dummySampleRate = 48000;
static const size_t dummyChannels = 1;
static const std::string dummySampleFormat = "s16";
static const std::string dummyAudioCodec = "pcm_s16le";
static bool useVideoGenerator = false;
void parseConfigFile( const std::string& configFilename, avtranscoder::Transcoder& transcoder )
{
std::ifstream configFile( configFilename.c_str(), std::ifstream::in );
std::string line;
while( std::getline( configFile, line ) )
{
std::istringstream is_line( line );
std::string filename;
if( std::getline( is_line, filename, '=' ) )
{
std::string streamId;
if( std::getline( is_line, streamId, ':' ) )
{
std::string transcodeProfile;
std::getline( is_line, transcodeProfile );
std::stringstream ss( streamId );
size_t streamIndex = 0;
char separator;
int subStreamIndex = -1;
ss >> streamIndex;
ss >> separator;
if( separator == '.' )
ss >> subStreamIndex;
// dummy stream, need a ICodec (audio or video)
if( ! filename.length() )
{
if( useVideoGenerator )
{
// video
avtranscoder::VideoCodec inputCodec( avtranscoder::eCodecTypeEncoder, dummyVideoCodec );
avtranscoder::VideoFrameDesc imageDesc( dummyWidth, dummyHeight, dummyPixelFormat );
inputCodec.setImageParameters( imageDesc );
transcoder.add( filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec );
}
else
{
// audio
avtranscoder::AudioCodec inputCodec( avtranscoder::eCodecTypeEncoder, dummyAudioCodec );
avtranscoder::AudioFrameDesc audioDesc( dummySampleRate, dummyChannels, dummySampleFormat );
inputCodec.setAudioParameters( audioDesc );
transcoder.add( filename, streamIndex, subStreamIndex, transcodeProfile, inputCodec );
}
}
else
{
transcoder.add( filename, streamIndex, subStreamIndex, transcodeProfile );
}
}
}
}
configFile.close();
}
int main( int argc, char** argv )
{
std::string help;
help += "Usage\n";
help += "\tavprocessor CONFIG.TXT OUTPUT_FILE_NAME [--generate-black] [--verbose] [--logFile] [--help]\n";
help += "CONFIG.TXT\n";
help += "\tEach line will be one stream in the output.\n";
help += "\tPattern of each line is:\n";
help += "\t[inputFile]=STREAM_ID.[subStreamId]:[profileName]\n";
help += "\tNo inputFile: will generate black image / audio silence (audio by default)\n";
help += "\tNo subStreamId: will process of channels of the stream\n";
help += "\tNo profileName: will rewrap the stream\n";
help += "Command line options\n";
help += "\t--generate-black: stream which not referred to an input, will generate an output video stream with black images (by default generate audio stream with silence)\n";
help += "\t--verbose: set log level to AV_LOG_DEBUG\n";
help += "\t--logFile: put log in 'avtranscoder.log' file\n";
help += "\t--help: display this help\n";
// Preload FFmpeg context
avtranscoder::preloadCodecsAndFormats();
avtranscoder::Logger::setLogLevel( AV_LOG_QUIET );
// List command line arguments
std::vector< std::string > arguments;
for( int argument = 1; argument < argc; ++argument )
{
arguments.push_back( argv[argument] );
}
for( size_t argument = 0; argument < arguments.size(); ++argument )
{
if( arguments.at( argument ) == "--help" )
{
std::cout << help << std::endl;
return 0;
}
else if( arguments.at( argument ) == "--generate-black" )
{
useVideoGenerator = true;
}
else if( arguments.at( argument ) == "--verbose" )
{
avtranscoder::Logger::setLogLevel( AV_LOG_DEBUG );
}
else if( arguments.at( argument ) == "--logFile" )
{
avtranscoder::Logger::logInFile();
}
}
// Check required arguments
if( argc < 3 )
{
std::cout << "avprocessor can rewrap or transcode inputs to create an output media file." << std::endl;
std::cout << "Use option --help to display help" << std::endl;
return( -1 );
}
try
{
std::string inputConfigFile( argv[1] );
avtranscoder::OutputFile outputFile( argv[2] );
avtranscoder::Transcoder transcoder( outputFile );
parseConfigFile( inputConfigFile, transcoder );
avtranscoder::ConsoleProgress progress;
transcoder.process( progress );
}
catch( std::exception& e )
{
std::cerr << "ERROR: during process, an error occured: " << e.what() << std::endl;
}
catch( ... )
{
std::cerr << "ERROR: during process, an unknown error occured" << std::endl;
}
}