Skip to content

Commit bade75a

Browse files
author
Clement Champetier
committed
Merge branch 'develop' of https://github.com/mikrosimage/avTranscoder into dev_frame_has_AVPacket
Conflicts: src/AvTranscoder/file/OutputFile.cpp
2 parents 854bac9 + 1ec6ff0 commit bade75a

37 files changed

+345
-164
lines changed

app/avProcessor/avProcessor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <AvTranscoder/transcoder/Transcoder.hpp>
2+
#include <AvTranscoder/file/OutputFile.hpp>
23
#include <AvTranscoder/progress/ConsoleProgress.hpp>
34

45
#include <iostream>

src/AvTranscoder/ProfileLoader.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <fstream>
77
#include <cstdlib>
88
#include <stdexcept>
9+
#include <dirent.h>
910

1011
namespace avtranscoder
1112
{
@@ -200,5 +201,35 @@ bool ProfileLoader::checkAudioProfile( const Profile& profileToCheck )
200201
return isValid;
201202
}
202203

204+
void split( std::vector< std::string >& splitString, const std::string& inputString, const std::string& splitChars )
205+
{
206+
char* part = strtok( const_cast<char*>( inputString.c_str() ), splitChars.c_str() );
207+
while( part != NULL )
208+
{
209+
splitString.push_back( std::string( part ) );
210+
part = strtok( NULL, splitChars.c_str() );
211+
}
212+
}
213+
214+
int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
215+
{
216+
DIR *dp;
217+
struct dirent *dirp;
218+
if( ( dp = opendir( dir.c_str() ) ) == NULL )
219+
{
220+
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
221+
return errno;
222+
}
223+
224+
while( ( dirp = readdir( dp ) ) != NULL )
225+
{
226+
std::string filename( dirp->d_name );
227+
if( filename == "." || filename == ".." )
228+
continue;
229+
files.push_back( filename );
230+
}
231+
closedir( dp );
232+
return 0;
233+
}
203234

204235
}

src/AvTranscoder/ProfileLoader.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,10 @@ class AvExport ProfileLoader
7373
Profiles _profiles;
7474
};
7575

76+
#ifndef SWIG
77+
void split( std::vector< std::string >& splitString, const std::string& inputString, const std::string& splitChars = ";" );
78+
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );
79+
#endif
80+
7681
}
7782
#endif

src/AvTranscoder/avTranscoder.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
%include "AvTranscoder/swig/avException.i"
1111
%include "AvTranscoder/swig/avExport.i"
1212
%include "AvTranscoder/swig/avDocumentation.i"
13+
%include "AvTranscoder/swig/avMediaType.i"
1314
%include "AvTranscoder/swig/avRational.i"
15+
%include "AvTranscoder/swig/avLogLevel.i"
1416

1517
%{
1618
#include <AvTranscoder/ProfileLoader.hpp>

src/AvTranscoder/codec/ICodec.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <AvTranscoder/common.hpp>
55
#include <AvTranscoder/Option.hpp>
66

7+
extern "C" {
8+
#include <libavcodec/avcodec.h>
9+
}
10+
711
#include <string>
812

913
namespace avtranscoder

src/AvTranscoder/common.cpp

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#include "common.hpp"
22

33
extern "C" {
4-
#include <libavcodec/avcodec.h>
54
#include <libavformat/avformat.h>
6-
#include <libavutil/error.h>
75
}
86

9-
#include <dirent.h>
10-
#include <iostream>
11-
127
namespace avtranscoder
138
{
149

@@ -17,56 +12,9 @@ void preloadCodecsAndFormats()
1712
av_register_all();
1813
}
1914

20-
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars )
21-
{
22-
char* part = strtok( const_cast<char*>( inputString.c_str() ), splitChars.c_str() );
23-
while( part != NULL )
24-
{
25-
splitedString.push_back( std::string( part ) );
26-
part = strtok( NULL, splitChars.c_str() );
27-
}
28-
}
29-
30-
int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
31-
{
32-
DIR *dp;
33-
struct dirent *dirp;
34-
if( ( dp = opendir( dir.c_str() ) ) == NULL )
35-
{
36-
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
37-
return errno;
38-
}
39-
40-
while( ( dirp = readdir( dp ) ) != NULL )
41-
{
42-
std::string filename( dirp->d_name );
43-
if( filename == "." || filename == ".." )
44-
continue;
45-
files.push_back( filename );
46-
}
47-
closedir( dp );
48-
return 0;
49-
}
50-
51-
std::string getFormat( const std::string& filename )
52-
{
53-
std::string format( "" );
54-
55-
AVOutputFormat* avOutputFormat = av_guess_format( NULL, filename.c_str(), NULL);
56-
if( avOutputFormat )
57-
{
58-
if( avOutputFormat->name )
59-
format = std::string( avOutputFormat->name );
60-
}
61-
62-
return format;
63-
}
64-
65-
bool matchFormat( const std::string& format, const std::string& filename )
15+
void setLogLevel( const int level )
6616
{
67-
AVOutputFormat* avOutputFormat = av_guess_format( format.c_str(), filename.c_str(), NULL);
68-
return avOutputFormat != NULL;
17+
av_log_set_level( level );
6918
}
7019

71-
7220
}

src/AvTranscoder/common.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ extern "C" {
99
#define INT64_C(c) (c ## LL)
1010
#define UINT64_C(c) (c ## ULL)
1111
#endif
12-
#include <libavformat/version.h>
1312
#include <libavcodec/version.h>
14-
#include <libavcodec/avcodec.h>
13+
#include <libavutil/error.h>
1514
#include <libavutil/rational.h>
15+
#include <libavutil/log.h>
1616
}
1717

1818
#include <string>
1919
#include <cstring>
20-
#include <vector>
2120

2221
#ifdef SWIG
2322
#define AvExport
@@ -59,13 +58,12 @@ typedef AVRational Rational;
5958
/// Register all the codecs and formats which are enabled at configuration time.
6059
void AvExport preloadCodecsAndFormats();
6160

62-
#ifndef SWIG
63-
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars = ";" );
64-
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );
65-
#endif
66-
67-
std::string AvExport getFormat( const std::string& filename );
68-
bool AvExport matchFormat( const std::string& format, const std::string& filename );
61+
/**
62+
* @brief Set the log level of ffmpeg/libav.
63+
* @param level: refer to define AV_LOG_xxx (from AV_LOG_QUIET to AV_LOG_DEBUG)
64+
* @see SWIG interface avLogLevel.i
65+
*/
66+
void AvExport setLogLevel( const int level );
6967

7068
}
7169

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,29 @@ bool AudioDecoder::decodeNextFrame()
149149
return true;
150150
}
151151

152+
void AudioDecoder::setProfile( const ProfileLoader::Profile& profile )
153+
{
154+
// set threads if not in profile
155+
if( ! profile.count( "threads" ) )
156+
_inputStream->getAudioCodec().getOption( "threads" ).setString( "auto" );
157+
158+
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
159+
{
160+
if( (*it).first == constants::avProfileIdentificator ||
161+
(*it).first == constants::avProfileIdentificatorHuman ||
162+
(*it).first == constants::avProfileType )
163+
continue;
164+
165+
try
166+
{
167+
Option& decodeOption = _inputStream->getAudioCodec().getOption( (*it).first );
168+
decodeOption.setString( (*it).second );
169+
}
170+
catch( std::exception& e )
171+
{
172+
std::cout << "[AudioDecoder] warning - can't set option " << (*it).first << " to " << (*it).second << ": " << e.what() << std::endl;
173+
}
174+
}
175+
}
176+
152177
}

src/AvTranscoder/decoder/AudioDecoder.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define _AV_TRANSCODER_ESSENCE_STREAM_AV_INPUT_AUDIO_HPP_
33

44
#include "IDecoder.hpp"
5+
#include <AvTranscoder/ProfileLoader.hpp>
56

67
struct AVFrame;
78

@@ -21,6 +22,8 @@ class AvExport AudioDecoder : public IDecoder
2122
bool decodeNextFrame( Frame& frameBuffer );
2223
bool decodeNextFrame( Frame& frameBuffer, const size_t subStreamIndex );
2324

25+
void setProfile( const ProfileLoader::Profile& profile );
26+
2427
private:
2528
bool decodeNextFrame();
2629

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ void VideoDecoder::flushDecoder()
110110

111111
void VideoDecoder::setProfile( const ProfileLoader::Profile& profile )
112112
{
113+
// set threads if not in profile
114+
if( ! profile.count( "threads" ) )
115+
_inputStream->getVideoCodec().getOption( "threads" ).setString( "auto" );
116+
113117
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
114118
{
115119
if( (*it).first == constants::avProfileIdentificator ||

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ void AudioEncoder::setProfile( const ProfileLoader::Profile& profile, const Audi
146146
// set sampleRate, number of channels, sample format
147147
_codec.setAudioParameters( frameDesc );
148148

149+
// set threads if not in profile
150+
if( ! profile.count( "threads" ) )
151+
_codec.getOption( "threads" ).setString( "auto" );
152+
149153
// set encoder options
150154
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
151155
{

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ void VideoEncoder::setProfile( const ProfileLoader::Profile& profile, const avtr
137137
// set width, height, pixel format, fps
138138
_codec.setImageParameters( frameDesc );
139139

140+
// set threads if not in profile
141+
if( ! profile.count( "threads" ) )
142+
_codec.getOption( "threads" ).setString( "auto" );
143+
140144
// set encoder options
141145
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
142146
{

src/AvTranscoder/file/IOutputFile.hpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#ifndef _AV_TRANSCODER_FILE_IOUTPUT_FILE_HPP_
2+
#define _AV_TRANSCODER_FILE_IOUTPUT_FILE_HPP_
3+
4+
#include <AvTranscoder/common.hpp>
5+
6+
#include <AvTranscoder/codec/VideoCodec.hpp>
7+
#include <AvTranscoder/codec/AudioCodec.hpp>
8+
#include <AvTranscoder/codec/DataCodec.hpp>
9+
10+
#include <AvTranscoder/stream/OutputStream.hpp>
11+
#include <AvTranscoder/ProfileLoader.hpp>
12+
13+
#include <string>
14+
#include <exception>
15+
16+
namespace avtranscoder
17+
{
18+
19+
/**
20+
* @brief IOutputfile is the interface to wrap and write medias.
21+
* It can be overloaded to integrate custom wrapper.
22+
**/
23+
class AvExport IOutputFile
24+
{
25+
public:
26+
virtual ~IOutputFile() {};
27+
28+
/**
29+
* @brief Initialize the wrapper
30+
**/
31+
virtual bool setup() = 0;
32+
33+
/**
34+
* @brief Add a video output stream
35+
* @note call setup() before adding any stream
36+
* @param videoCodec description of output stream
37+
**/
38+
virtual IOutputStream& addVideoStream( const VideoCodec& videoCodec )
39+
{
40+
throw std::logic_error("function is not implemented");
41+
}
42+
43+
/**
44+
* @brief Add an audio output stream
45+
* @note call setup() before adding any stream
46+
* @param audioCodec description of output stream
47+
**/
48+
virtual IOutputStream& addAudioStream( const AudioCodec& audioCodec )
49+
{
50+
throw std::logic_error("function is not implemented");
51+
}
52+
53+
/**
54+
* @brief Add a data output stream
55+
* @note call setup() before adding any stream
56+
* @param dataCodec description of output stream
57+
**/
58+
virtual IOutputStream& addDataStream( const DataCodec& dataCodec )
59+
{
60+
throw std::logic_error("function is not implemented");
61+
}
62+
63+
/**
64+
* @brief Write the header of file (if necessary)
65+
**/
66+
virtual bool beginWrap() = 0;
67+
68+
/**
69+
* @brief Wrap a packet of data in the output ressource
70+
* @param data coded packet information for the current stream
71+
* @param streamId refers to the stream in output ressource
72+
**/
73+
virtual IOutputStream::EWrappingStatus wrap( const CodedData& data, const size_t streamIndex ) = 0;
74+
75+
/**
76+
* @brief Write the footer of file (if necessary)
77+
**/
78+
virtual bool endWrap() = 0;
79+
80+
/**
81+
* @brief Get the output stream
82+
* @param streamId select the output stream
83+
* @return the output stream reference
84+
**/
85+
virtual IOutputStream& getStream( const size_t streamIndex ) = 0;
86+
};
87+
88+
}
89+
90+
#endif

0 commit comments

Comments
 (0)