Skip to content

Commit 7f63c93

Browse files
committed
Merge pull request #103 from cchampet/dev_useFFmpegLogSystem
Add log system based on ffmpeg/libav
2 parents 5e5d310 + 81d02ae commit 7f63c93

27 files changed

+249
-268
lines changed

app/avProcessor/avProcessor.cpp

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ static const std::string dummyAudioCodec = "pcm_s16le";
2121

2222
static bool useVideoGenerator = false;
2323

24-
static bool verbose = false;
25-
2624
void parseConfigFile( const std::string& configFilename, avtranscoder::Transcoder& transcoder )
2725
{
2826
std::ifstream configFile( configFilename.c_str(), std::ifstream::in );
@@ -49,17 +47,6 @@ void parseConfigFile( const std::string& configFilename, avtranscoder::Transcode
4947
if( separator == '.' )
5048
ss >> subStreamIndex;
5149

52-
if( verbose )
53-
{
54-
std::cout << ( filename.length() ? filename : "dummy stream" );
55-
std::cout << " ( " << streamIndex;
56-
if( subStreamIndex > -1 )
57-
std::cout << " | " << subStreamIndex << " ";
58-
std::cout << " ) : ";
59-
std::cout << ( transcodeProfile.length() ? transcodeProfile : "rewrap" );
60-
std::cout << std::endl;
61-
}
62-
6350
// dummy stream, need a ICodec (audio or video)
6451
if( ! filename.length() )
6552
{
@@ -97,7 +84,7 @@ int main( int argc, char** argv )
9784
{
9885
std::string help;
9986
help += "Usage\n";
100-
help += "\tavprocessor CONFIG.TXT OUTPUT_FILE_NAME [--generate-black] [--verbose] [--help]\n";
87+
help += "\tavprocessor CONFIG.TXT OUTPUT_FILE_NAME [--generate-black] [--verbose] [--logFile] [--help]\n";
10188
help += "CONFIG.TXT\n";
10289
help += "\tEach line will be one stream in the output.\n";
10390
help += "\tPattern of each line is:\n";
@@ -107,8 +94,14 @@ int main( int argc, char** argv )
10794
help += "\tNo profileName: will rewrap the stream\n";
10895
help += "Command line options\n";
10996
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";
97+
help += "\t--verbose: set log level to AV_LOG_DEBUG\n";
98+
help += "\t--logFile: put log in 'avtranscoder.log' file\n";
11099
help += "\t--help: display this help\n";
111100

101+
// Preload FFmpeg context
102+
avtranscoder::preloadCodecsAndFormats();
103+
avtranscoder::Logger::setLogLevel( AV_LOG_QUIET );
104+
112105
// List command line arguments
113106
std::vector< std::string > arguments;
114107
for( int argument = 1; argument < argc; ++argument )
@@ -122,13 +115,17 @@ int main( int argc, char** argv )
122115
std::cout << help << std::endl;
123116
return 0;
124117
}
125-
if( arguments.at( argument ) == "--generate-black" )
118+
else if( arguments.at( argument ) == "--generate-black" )
126119
{
127120
useVideoGenerator = true;
128121
}
129-
if( arguments.at( argument ) == "--verbose" )
122+
else if( arguments.at( argument ) == "--verbose" )
123+
{
124+
avtranscoder::Logger::setLogLevel( AV_LOG_DEBUG );
125+
}
126+
else if( arguments.at( argument ) == "--logFile" )
130127
{
131-
verbose = true;
128+
avtranscoder::Logger::logInFile();
132129
}
133130
}
134131

@@ -140,40 +137,17 @@ int main( int argc, char** argv )
140137
return( -1 );
141138
}
142139

143-
avtranscoder::setLogLevel( AV_LOG_QUIET );
144-
if( verbose )
145-
avtranscoder::setLogLevel( AV_LOG_DEBUG );
146-
147140
try
148141
{
149-
if( verbose )
150-
std::cout << "start ..." << std::endl;
151-
avtranscoder::preloadCodecsAndFormats();
152-
153-
if( verbose )
154-
std::cout << "output file: " << argv[2] << std::endl;
155-
156142
std::string inputConfigFile( argv[1] );
157143
avtranscoder::OutputFile outputFile( argv[2] );
158144

159145
avtranscoder::Transcoder transcoder( outputFile );
160146

161-
if( verbose )
162-
std::cout << "parse config file" << std::endl;
163147
parseConfigFile( inputConfigFile, transcoder );
164148

165-
// set verbose of all stream
166-
transcoder.setVerbose( verbose );
167-
168-
if( verbose )
169-
std::cout << "start Transcode" << std::endl;
170-
171149
avtranscoder::ConsoleProgress progress;
172150
transcoder.process( progress );
173-
174-
std::cout << std::endl;
175-
if( verbose )
176-
std::cout << "end ..." << std::endl;
177151
}
178152
catch( std::exception& e )
179153
{

app/avThumbnail/avThumbnail.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <AvTranscoder/transcoder/Transcoder.hpp>
22
#include <AvTranscoder/file/OutputFile.hpp>
33

4+
#include <iostream>
5+
46
static std::string outputFileName = "thumbnail.jpg";
57
static bool seekInFrame = false;
68

@@ -54,7 +56,7 @@ int main( int argc, char** argv )
5456
return( -1 );
5557
}
5658

57-
avtranscoder::setLogLevel( AV_LOG_QUIET );
59+
avtranscoder::Logger::setLogLevel( AV_LOG_QUIET );
5860
avtranscoder::preloadCodecsAndFormats();
5961

6062
// input file

src/AvTranscoder/Option.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ extern "C" {
55
#include <libavutil/mem.h>
66
}
77

8-
#include <iostream>
98
#include <sstream>
109
#include <stdexcept>
1110

@@ -288,7 +287,7 @@ void loadOptions( OptionMap& outOptions, void* av_class, int req_flags )
288287

289288
if( ! parentFound )
290289
{
291-
std::cout << "Warning: Can't find a choice option for " << itOption->getName() << std::endl;
290+
LOG_WARN( "Can't find a choice option for " << itOption->getName() )
292291
}
293292
}
294293
}

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern "C" {
66

77
#include <stdexcept>
88
#include <cassert>
9-
#include <iostream>
109

1110
namespace avtranscoder {
1211

@@ -118,7 +117,7 @@ void ICodec::setCodec( const ECodecType type, const AVCodecID codecId )
118117
{
119118
if( codecId == 0 )
120119
{
121-
std::cout << "Warning: Unsupported codec with id 0" << std::endl;
120+
LOG_WARN( "Unsupported codec with id 0")
122121
return;
123122
}
124123

src/AvTranscoder/common.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
extern "C" {
44
#include <libavformat/avformat.h>
5+
#include <libavutil/error.h>
56
}
67

78
namespace avtranscoder
@@ -12,12 +13,7 @@ void preloadCodecsAndFormats()
1213
av_register_all();
1314
}
1415

15-
void setLogLevel( const int level )
16-
{
17-
av_log_set_level( level );
18-
}
19-
20-
std::string AvExport getDescriptionFromErrorCode( const int code )
16+
std::string getDescriptionFromErrorCode( const int code )
2117
{
2218
char err[AV_ERROR_MAX_STRING_SIZE];
2319
av_strerror( code, err, sizeof(err) );

src/AvTranscoder/common.hpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ extern "C" {
1212
#define UINT64_C(c) (c ## ULL)
1313
#endif
1414
#include <libavcodec/version.h>
15-
#include <libavutil/error.h>
1615
#include <libavutil/rational.h>
17-
#include <libavutil/log.h>
1816
}
1917

2018
#include <string>
21-
#include <cstring>
2219

2320
#ifdef SWIG
2421
#define AvExport
@@ -50,6 +47,8 @@ extern "C" {
5047
#endif
5148
#endif
5249

50+
#include <AvTranscoder/log.hpp>
51+
5352
namespace avtranscoder
5453
{
5554

@@ -60,14 +59,6 @@ typedef AVRational Rational;
6059
/// Register all the codecs and formats which are enabled at configuration time.
6160
void AvExport preloadCodecsAndFormats();
6261

63-
/**
64-
* @brief Set the log level of ffmpeg/libav.
65-
* @param level: refer to define AV_LOG_xxx (from AV_LOG_QUIET to AV_LOG_DEBUG)
66-
* @see SWIG interface avLogLevel.i
67-
*/
68-
void AvExport setLogLevel( const int level );
69-
70-
7162
/// Get the string description corresponding to the error code provided by ffmpeg/libav
7263
std::string AvExport getDescriptionFromErrorCode( const int code );
7364

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212
#include <libavutil/channel_layout.h>
1313
}
1414

15-
#include <iostream>
1615
#include <stdexcept>
1716

1817
namespace avtranscoder
@@ -173,7 +172,7 @@ void AudioDecoder::setProfile( const ProfileLoader::Profile& profile )
173172
}
174173
catch( std::exception& e )
175174
{
176-
std::cout << "[AudioDecoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
175+
LOG_WARN( "AudioDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
177176
}
178177
}
179178
}

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern "C" {
1212
}
1313

1414
#include <stdexcept>
15-
#include <iostream>
1615

1716
namespace avtranscoder
1817
{
@@ -134,7 +133,7 @@ void VideoDecoder::setProfile( const ProfileLoader::Profile& profile )
134133
}
135134
catch( std::exception& e )
136135
{
137-
std::cout << "[VideoDecoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
136+
LOG_WARN( "VideoDecoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
138137
}
139138
}
140139
}

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern "C" {
66
#include <libavutil/avutil.h>
77
}
88

9-
#include <iostream>
109
#include <stdexcept>
1110

1211
namespace avtranscoder
@@ -185,7 +184,7 @@ void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const Audi
185184
}
186185
catch( std::exception& e )
187186
{
188-
std::cout << "[AudioEncoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
187+
LOG_WARN( "AudioEncoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
189188
}
190189
}
191190
}

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ extern "C" {
66
#include <libavutil/avutil.h>
77
}
88

9-
#include <iostream>
109
#include <stdexcept>
1110
#include <cstdlib>
1211

@@ -183,7 +182,7 @@ void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtr
183182
}
184183
catch( std::exception& e )
185184
{
186-
std::cout << "[VideoEncoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
185+
LOG_WARN( "VideoEncoder - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
187186
}
188187
}
189188
}

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <stdexcept>
44
#include <sstream>
5-
#include <iostream>
65

76
namespace avtranscoder
87
{
@@ -119,7 +118,7 @@ void FormatContext::addMetaData( const std::string& key, const std::string& valu
119118
int ret = av_dict_set( &_avFormatContext->metadata, key.c_str(), value.c_str(), 0 );
120119
if( ret < 0 )
121120
{
122-
std::cout << getDescriptionFromErrorCode( ret ) << std::endl;
121+
LOG_ERROR( getDescriptionFromErrorCode( ret ) )
123122
}
124123
}
125124

src/AvTranscoder/file/InputFile.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern "C" {
1616
}
1717

1818
#include <stdexcept>
19+
#include <sstream>
1920

2021
namespace avtranscoder
2122
{
@@ -25,7 +26,6 @@ InputFile::InputFile( const std::string& filename )
2526
, _properties( _formatContext )
2627
, _filename( filename )
2728
, _inputStreams()
28-
, _verbose( false )
2929
{
3030
_formatContext.findStreamInfo();
3131

@@ -160,7 +160,7 @@ void InputFile::seek( uint64_t position )
160160

161161
if( av_seek_frame( &_formatContext.getAVFormatContext(), -1, position, AVSEEK_FLAG_BACKWARD ) < 0 )
162162
{
163-
std::cerr << "Error during seek at " << position << " (in AV_TIME_BASE units) in file" << std::endl;
163+
LOG_ERROR( "Error when seek at " << position << " (in AV_TIME_BASE units) in file" )
164164
}
165165

166166
for( std::vector<InputStream*>::iterator it = _inputStreams.begin(); it != _inputStreams.end(); ++it )
@@ -214,8 +214,7 @@ void InputFile::setProfile( const ProfileLoader::Profile& profile )
214214
}
215215
catch( std::exception& e )
216216
{
217-
if( _verbose )
218-
std::cout << "[InputFile] warning: " << e.what() << std::endl;
217+
LOG_WARN( "InputFile - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() )
219218
}
220219
}
221220
}

src/AvTranscoder/file/InputFile.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ class AvExport InputFile
8484
*/
8585
virtual void setProfile( const ProfileLoader::Profile& profile );
8686

87-
/**
88-
* @brief Set to verbose mode.
89-
*/
90-
void setVerbose( bool verbose = true ) { _verbose = verbose; }
91-
9287
public:
9388
/**
9489
* @brief Get media file properties using static method.
@@ -117,8 +112,6 @@ class AvExport InputFile
117112
FileProperties _properties;
118113
std::string _filename;
119114
std::vector<InputStream*> _inputStreams; ///< Has ownership
120-
121-
bool _verbose;
122115
};
123116

124117
}

0 commit comments

Comments
 (0)