Skip to content

Commit be52513

Browse files
Merge branch 'master' of github.com:MarcAntoine-Arnaud/avTranscoder
2 parents 06530e9 + 87322aa commit be52513

25 files changed

+660
-114
lines changed

app/audioRewrapper/audioRewrapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <iomanip>
33

44
#include <AvTranscoder/InputFile.hpp>
5-
#include <AvTranscoder/InputStream.hpp>
5+
#include <AvTranscoder/AvInputStream.hpp>
66
#include <AvTranscoder/InputStreamAudio.hpp>
77

88
#include <AvTranscoder/OutputFile.hpp>
@@ -21,7 +21,7 @@ void rewrapAudio( const char* inputfilename, const char* outputFilename )
2121

2222
outputFile.setup();
2323

24-
outputFile.addAudioStream( inputFile.getStream( 0 ).getAudioDesc() );
24+
outputFile.addAudioStream( inputFile.getStream( 0 )->getAudioDesc() );
2525

2626
DataStream data;
2727

@@ -30,7 +30,7 @@ void rewrapAudio( const char* inputfilename, const char* outputFilename )
3030

3131
size_t frame = 0;
3232

33-
while( inputFile.getStream( 0 ).readNextPacket( data ) )
33+
while( inputFile.getStream( 0 )->readNextPacket( data ) )
3434
{
3535
std::cout << "\rprocess frame " << (int)frame - 1 << std::flush;
3636

@@ -58,7 +58,7 @@ void transcodeAudio( const char* inputfilename, const char* outputFilename )
5858

5959
outputFile.setup();
6060

61-
outputFile.addAudioStream( inputFile.getStream( 0 ).getAudioDesc() );
61+
outputFile.addAudioStream( inputFile.getStream( 0 )->getAudioDesc() );
6262

6363
DataStream data;
6464

app/avTranscoder/avTranscoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22
#include <iomanip>
33

4-
#include <AvTranscoder/InputStream.hpp>
4+
#include <AvTranscoder/AvInputStream.hpp>
55
#include <AvTranscoder/InputStreamAudio.hpp>
66
#include <AvTranscoder/InputStreamVideo.hpp>
77
#include <AvTranscoder/OutputStream.hpp>
@@ -91,7 +91,7 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
9191
exit( -1 );
9292
}
9393

94-
of.addVideoStream( inputFile.getStream( 0 ).getVideoDesc() );
94+
of.addVideoStream( inputFile.getStream( 0 )->getVideoDesc() );
9595
/*of.addAudioStream();
9696
of.addAudioStream();
9797
of.addAudioStream();

app/avplay/AvReader.hpp

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

44

5-
#include <AvTranscoder/InputStream.hpp>
5+
#include <AvTranscoder/AvInputStream.hpp>
66
#include <AvTranscoder/InputStreamAudio.hpp>
77
#include <AvTranscoder/InputStreamVideo.hpp>
88
#include <AvTranscoder/InputFile.hpp>
@@ -29,7 +29,7 @@ class AvReader : public Reader
2929

3030
m_inputStreamVideo = new avtranscoder::InputStreamVideo( m_inputFile.getStream( m_videoStream ) );
3131

32-
m_sourceImage = new avtranscoder::Image( m_inputFile.getStream( m_videoStream ).getVideoDesc().getImageDesc() );
32+
m_sourceImage = new avtranscoder::Image( m_inputFile.getStream( m_videoStream )->getVideoDesc().getImageDesc() );
3333

3434
pixel.setBitsPerPixel( getComponents() * getBitDepth() );
3535
pixel.setComponents( getComponents() );

app/presetChecker/presetChecker.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#include <iostream>
3+
#include <iomanip>
4+
#include <AvTranscoder/Profile.hpp>
5+
6+
#include <AvTranscoder/OutputStreamVideo.hpp>
7+
8+
9+
int main( int argc, char** argv )
10+
{
11+
avtranscoder::Profile p;
12+
p.loadProfiles();
13+
14+
std::cout << p.getProfiles().size() << std::endl;
15+
16+
std::cout << std::left;
17+
18+
for( auto profile : p.getProfiles() )
19+
{
20+
std::cout << "********************" << std::endl;
21+
for( auto key : profile )
22+
std::cout << std::setw(35) << key.first << key.second << std::endl;
23+
24+
avtranscoder::OutputStreamVideo outputVideoStream;
25+
outputVideoStream.setProfile( profile[ "avProfile" ] );
26+
}
27+
28+
}

src/AvTranscoder/InputStream.cpp renamed to src/AvTranscoder/AvInputStream.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#include "InputStream.hpp"
1+
#include "AvInputStream.hpp"
2+
3+
#include <AvTranscoder/InputFile.hpp>
24

35
extern "C" {
46
#ifndef __STDC_CONSTANT_MACROS
5-
#define __STDC_CONSTANT_MACROS
7+
#define __STDC_CONSTANT_MACROS
68
#endif
9+
710
#include <libavcodec/avcodec.h>
811
#include <libavformat/avformat.h>
912
#include <libavutil/avutil.h>
@@ -17,19 +20,29 @@ extern "C" {
1720
namespace avtranscoder
1821
{
1922

20-
InputStream::InputStream( InputFile* inputFile, const size_t streamIndex )
21-
: m_inputFile( inputFile )
23+
AvInputStream::AvInputStream( )
24+
: InputStream( )
25+
, m_inputFile( NULL )
26+
, m_packetDuration( 0 )
27+
, m_streamIndex( 0 )
28+
, m_bufferized( false )
29+
{
30+
}
31+
32+
AvInputStream::AvInputStream( InputFile* inputFile, const size_t streamIndex )
33+
: InputStream( )
34+
, m_inputFile( inputFile )
2235
, m_packetDuration( 0 )
2336
, m_streamIndex( streamIndex )
2437
, m_bufferized( false )
2538
{
26-
};
39+
}
2740

28-
InputStream::~InputStream( )
41+
AvInputStream::~AvInputStream( )
2942
{
3043
}
3144

32-
bool InputStream::readNextPacket( DataStream& data )
45+
bool AvInputStream::readNextPacket( DataStream& data )
3346
{
3447
if( m_streamCache.empty() )
3548
m_inputFile->readNextPacket( m_streamIndex );
@@ -44,7 +57,7 @@ bool InputStream::readNextPacket( DataStream& data )
4457
return true;
4558
}
4659

47-
void InputStream::addPacket( AVPacket& packet )
60+
void AvInputStream::addPacket( AVPacket& packet )
4861
{
4962
//std::cout << "add packet for stream " << m_streamIndex << std::endl;
5063
DataStream data;
@@ -71,7 +84,7 @@ void InputStream::addPacket( AVPacket& packet )
7184
// std::cout << this << " buffer size " << m_streamCache.size() << std::endl;
7285
}
7386

74-
VideoDesc InputStream::getVideoDesc() const
87+
VideoDesc AvInputStream::getVideoDesc() const
7588
{
7689
assert( m_inputFile->getFormatContext() != NULL );
7790
assert( m_streamIndex <= m_inputFile->getFormatContext()->nb_streams );
@@ -91,7 +104,7 @@ VideoDesc InputStream::getVideoDesc() const
91104
return desc;
92105
}
93106

94-
AudioDesc InputStream::getAudioDesc() const
107+
AudioDesc AvInputStream::getAudioDesc() const
95108
{
96109
assert( m_inputFile->getFormatContext() != NULL );
97110
assert( m_streamIndex <= m_inputFile->getFormatContext()->nb_streams );
@@ -111,17 +124,17 @@ AudioDesc InputStream::getAudioDesc() const
111124
}
112125

113126

114-
double InputStream::getDuration() const
127+
double AvInputStream::getDuration() const
115128
{
116129
return 1.0 * m_inputFile->getFormatContext()->duration / AV_TIME_BASE;
117130
}
118131

119-
double InputStream::getPacketDuration() const
132+
double AvInputStream::getPacketDuration() const
120133
{
121134
return m_packetDuration * av_q2d( m_inputFile->getFormatContext()->streams[m_streamIndex]->time_base );
122135
}
123136

124-
void InputStream::clearBuffering()
137+
void AvInputStream::clearBuffering()
125138
{
126139
m_streamCache.clear();
127140
}

src/AvTranscoder/AvInputStream.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef _AV_TRANSCODER_AV_INPUT_STREAM_HPP_
2+
#define _AV_TRANSCODER_AV_INPUT_STREAM_HPP_
3+
4+
#include <AvTranscoder/InputStream.hpp>
5+
6+
namespace avtranscoder
7+
{
8+
9+
class InputFile;
10+
11+
class AvExport AvInputStream : public InputStream
12+
{
13+
public:
14+
AvInputStream( );
15+
16+
AvInputStream( InputFile* inputFile, const size_t streamIndex );
17+
~AvInputStream( );
18+
19+
AvInputStream( const AvInputStream& inputStream )
20+
: InputStream( )
21+
, m_inputFile( inputStream.m_inputFile )
22+
, m_streamIndex( inputStream.m_streamIndex )
23+
, m_bufferized( inputStream.m_bufferized )
24+
{
25+
}
26+
27+
size_t getStreamIndex() const { return m_streamIndex; }
28+
29+
bool readNextPacket( DataStream& data );
30+
31+
// Stream propeerties
32+
VideoDesc getVideoDesc() const;
33+
AudioDesc getAudioDesc() const;
34+
35+
double getDuration() const;
36+
double getPacketDuration() const;
37+
38+
void addPacket( AVPacket& packet );
39+
40+
void setBufferred( const bool bufferized ){ m_bufferized = bufferized; };
41+
42+
void clearBuffering();
43+
44+
private:
45+
InputFile* m_inputFile;
46+
std::vector<DataStream> m_streamCache;
47+
48+
VideoDesc m_videoDesc;
49+
AudioDesc m_audioDesc;
50+
51+
int m_packetDuration;
52+
size_t m_streamIndex;
53+
bool m_bufferized;
54+
};
55+
56+
}
57+
58+
#endif

src/AvTranscoder/DatasStructures/AudioFrame.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,33 @@ class AudioFrameDesc
3030
{
3131
public:
3232
AudioFrameDesc()
33+
: m_sampleRate( 0 )
34+
, m_channels( 0 )
35+
, m_fps( 1.0 )
36+
, m_sampleFormat( AV_SAMPLE_FMT_NONE )
3337
{};
3438

39+
void setSampleRate ( const size_t sampleRate ){ m_sampleRate = sampleRate; }
40+
void setChannels ( const size_t channels ){ m_channels = channels; }
41+
void setFps ( const size_t fps ){ m_fps = fps; }
42+
void setSampleFormat( const AVSampleFormat sampleFormat ){ m_sampleFormat = sampleFormat; }
43+
3544
size_t getDataSize() const
3645
{
37-
size_t size = 0;
38-
return size;
46+
return ( m_sampleRate / m_fps ) * m_channels * av_get_bytes_per_sample( m_sampleFormat );
3947
}
4048

49+
size_t getSampleRate() const { return m_sampleRate; }
50+
size_t getChannels () const { return m_channels; }
51+
size_t getFps () const { return m_fps; }
52+
AVSampleFormat getSampleFormat() const { return m_sampleFormat; }
53+
4154
private:
55+
size_t m_sampleRate;
56+
size_t m_channels;
57+
double m_fps;
58+
59+
AVSampleFormat m_sampleFormat;
4260
};
4361

4462
class AudioFrame

src/AvTranscoder/DummyInputStream.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "DummyInputStream.hpp"
2+
3+
#include <cassert>
4+
5+
namespace avtranscoder
6+
{
7+
8+
DummyInputStream::DummyInputStream( )
9+
: InputStream( )
10+
{
11+
}
12+
13+
DummyInputStream::~DummyInputStream( )
14+
{
15+
}
16+
17+
bool DummyInputStream::readNextPacket( DataStream& data )
18+
{
19+
data.getBuffer().resize( m_frameDesc.getDataSize() );
20+
21+
//av_samples_set_silence( data.getPtr(), offset, nb_samples, nb_channels, sample_fmt );
22+
int fill_char = ( m_frameDesc.getSampleFormat() == AV_SAMPLE_FMT_U8 || m_frameDesc.getSampleFormat() == AV_SAMPLE_FMT_U8P) ? 0x80 : 0x00;
23+
24+
memset( data.getPtr(), fill_char, data.getSize() );
25+
26+
return true;
27+
}
28+
29+
void DummyInputStream::setVideoDesc( VideoDesc videoDesc )
30+
{
31+
m_videoDesc = videoDesc;
32+
}
33+
34+
void DummyInputStream::setAudioDesc( AudioDesc audioDesc )
35+
{
36+
m_audioDesc = audioDesc;
37+
m_frameDesc.setSampleRate ( m_audioDesc.getCodecContext()->sample_rate );
38+
m_frameDesc.setChannels ( m_audioDesc.getCodecContext()->channels );
39+
m_frameDesc.setFps ( 25.0 );
40+
m_frameDesc.setSampleFormat( m_audioDesc.getCodecContext()->sample_fmt );
41+
}
42+
43+
44+
VideoDesc DummyInputStream::getVideoDesc() const
45+
{
46+
return m_videoDesc;
47+
}
48+
49+
AudioDesc DummyInputStream::getAudioDesc() const
50+
{
51+
return m_audioDesc;
52+
}
53+
54+
55+
double DummyInputStream::getDuration() const
56+
{
57+
return 0;
58+
}
59+
60+
double DummyInputStream::getPacketDuration() const
61+
{
62+
return 0;
63+
}
64+
65+
void DummyInputStream::clearBuffering()
66+
{
67+
}
68+
69+
}

0 commit comments

Comments
 (0)