Skip to content

Commit cfbafef

Browse files
Update buidl and start adding Data Structures
1 parent 20ca6ed commit cfbafef

20 files changed

+421
-76
lines changed

app/SConscript

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Import( 'AvTranscoder' )
2-
Import( 'jAvTranscoder' )
2+
Import( 'AvTranscoder_jar' )
33

44
env = Environment().Clone()
55

@@ -13,6 +13,7 @@ env.Program(
1313
'avutil',
1414
'avformat',
1515
'avcodec',
16+
'swscale',
1617
]
1718
)
1819

app/avTranscoder/avTranscoder.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include <AvTranscoder/OutputStreamVideo.hpp>
1010
#include <AvTranscoder/OutputFile.hpp>
1111

12+
#include <AvTranscoder/ColorTransform.hpp>
13+
14+
#include <AvTranscoder/DatasStructures/Image.hpp>
15+
1216
int main( int argc, char** argv )
1317
{
1418
using namespace avtranscoder;
@@ -30,9 +34,9 @@ int main( int argc, char** argv )
3034
std::cout << "duration : " << input.getProperties().duration << std::endl;
3135
std::cout << "bitrate : " << input.getProperties().bitRate << std::endl;
3236
std::cout << "number of streams : " << input.getProperties().streamsCount << std::endl;
37+
std::cout << "number of programs : " << input.getProperties().programsCount << std::endl;
3338
std::cout << "number of video streams : " << input.getProperties().videoStreams.size() << std::endl;
3439
std::cout << "number of audio streams : " << input.getProperties().audioStreams.size() << std::endl;
35-
3640

3741
for( size_t videoStreamIndex = 0; videoStreamIndex < input.getProperties().videoStreams.size(); ++videoStreamIndex )
3842
{
@@ -51,6 +55,15 @@ int main( int argc, char** argv )
5155
std::cout << "pixel type : " << input.getProperties().videoStreams.at(videoStreamIndex).pixelName << std::endl;
5256
std::cout << "number of components : " << input.getProperties().videoStreams.at(videoStreamIndex).componentsCount << std::endl;
5357

58+
std::cout << "color transfert : " << input.getProperties().videoStreams.at(videoStreamIndex).colorTransfert << std::endl;
59+
std::cout << "colorspace : " << input.getProperties().videoStreams.at(videoStreamIndex).colorspace << std::endl;
60+
std::cout << "color range : " << input.getProperties().videoStreams.at(videoStreamIndex).colorRange << std::endl;
61+
std::cout << "color primaries : " << input.getProperties().videoStreams.at(videoStreamIndex).colorPrimaries << std::endl;
62+
std::cout << "chroma sample location : " << input.getProperties().videoStreams.at(videoStreamIndex).chromaSampleLocation << std::endl;
63+
std::cout << "interlaced : " << ( input.getProperties().videoStreams.at(videoStreamIndex).isInterlaced ? "True" : "False" ) << std::endl;
64+
std::cout << "top field first : " << ( input.getProperties().videoStreams.at(videoStreamIndex).topFieldFirst ? "True" : "False" ) << std::endl;
65+
std::cout << "field order : " << input.getProperties().videoStreams.at(videoStreamIndex).fieldOrder << std::endl;
66+
5467
std::cout << "gop : ";
5568
for( size_t frameIndex = 0; frameIndex < input.getProperties().videoStreams.at(videoStreamIndex).gopStructure.size(); ++frameIndex )
5669
{
@@ -142,6 +155,13 @@ int main( int argc, char** argv )
142155
143156
wrapper.createAudioEncoder( eAudioLeft, 2 );*/
144157

158+
ColorTransform ct;
159+
ct.setWidth( isVideo.getWidth() );
160+
ct.setHeight( isVideo.getHeight() );
161+
//ct.setInputPixel( const Pixel& pixel );
162+
ct.init();
163+
//ct.convert( codedImage, codedImage );
164+
145165

146166
// Encodage/transcodage
147167

@@ -154,6 +174,8 @@ int main( int argc, char** argv )
154174
{
155175
isVideo.readNextFrame( frameBuffer );
156176

177+
// ct.convert( codedImage, codedImage );
178+
157179
osVideo.encodeFrame( frameBuffer, codedImage );
158180
//std::cout << "decoded size " << frameBuffer.size() << " encode frame " << count << " size " << codedImage.size() << std::endl;
159181

@@ -194,4 +216,5 @@ int main( int argc, char** argv )
194216

195217
// Audio * N // Video * N -> Audio *N + video * N
196218

219+
197220
}

src/AvTranscoder/ColorTransform.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include "ColorTransform.hpp"
2+
3+
extern "C" {
4+
#ifndef __STDC_CONSTANT_MACROS
5+
#define __STDC_CONSTANT_MACROS
6+
#endif
7+
#include <libswscale/swscale.h>
8+
#include <libavutil/imgutils.h>
9+
#include <libavutil/pixdesc.h>
10+
#include <libavutil/frame.h>
11+
}
12+
13+
#include <iostream>
14+
#include <iomanip>
15+
16+
namespace avtranscoder
17+
{
18+
19+
ColorTransform::ColorTransform()
20+
: m_width( 0 )
21+
, m_height( 0 )
22+
{
23+
// m_inputPixel = AV_PIX_FMT_YUV422P10;
24+
// m_outputPixel = AV_PIX_FMT_YUV422P;
25+
}
26+
27+
void ColorTransform::setWidth ( const size_t width )
28+
{
29+
m_width = width;
30+
}
31+
32+
void ColorTransform::setHeight( const size_t height )
33+
{
34+
m_height = height;
35+
}
36+
37+
void ColorTransform::setInputPixel( const Pixel& pixel )
38+
{
39+
m_inputPixel = pixel;
40+
}
41+
42+
void ColorTransform::setOutputPixel( const Pixel& pixel )
43+
{
44+
m_outputPixel = pixel;
45+
}
46+
47+
bool ColorTransform::init()
48+
{
49+
return true;
50+
}
51+
52+
void ColorTransform::convert( const Image& src, Image& dst )
53+
{
54+
55+
SwsContext* m_imageConvertContext = sws_getContext(
56+
m_width, m_height, m_inputPixel(),
57+
m_width, m_height, m_outputPixel(),
58+
SWS_POINT, NULL, NULL, NULL);
59+
60+
// resize dst buffer ? using :
61+
// av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align);
62+
63+
unsigned char* dataIn [ AV_NUM_DATA_POINTERS ];
64+
unsigned char* dataOut [ AV_NUM_DATA_POINTERS ];
65+
int linesizeIn [ AV_NUM_DATA_POINTERS ];
66+
int linesizeOut[ AV_NUM_DATA_POINTERS ];
67+
68+
// std::vector< int > lineSizeOut( AV_NUM_DATA_POINTERS, 0 );
69+
70+
for( size_t i = 0; i < AV_NUM_DATA_POINTERS; ++i )
71+
{
72+
dataIn [i] = NULL;
73+
dataOut[i] = NULL;
74+
linesizeIn [i] = 0;
75+
linesizeOut[i] = 0;
76+
}
77+
78+
//dataIn [0] = const_cast< unsigned char* >( &src[0] );
79+
//dataOut[0] = &dst[0];
80+
linesizeIn [0] = av_image_get_linesize( m_inputPixel(), m_width, 3 );
81+
linesizeOut[0] = av_image_get_linesize( m_outputPixel(), m_width, 3 );
82+
83+
sws_scale( m_imageConvertContext,
84+
dataIn, linesizeIn, 0, m_height,
85+
dataOut, linesizeOut );
86+
}
87+
88+
}

src/AvTranscoder/ColorTransform.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef _AV_TRANSCODER_COLOR_TRANSFORM_HPP_
2+
#define _AV_TRANSCODER_COLOR_TRANSFORM_HPP_
3+
4+
#include "DatasStructures/Pixel.hpp"
5+
#include "DatasStructures/Image.hpp"
6+
7+
#include <vector>
8+
#include <string>
9+
10+
namespace avtranscoder
11+
{
12+
13+
class ColorTransform
14+
{
15+
public:
16+
ColorTransform();
17+
18+
void setWidth ( const size_t width );
19+
void setHeight( const size_t height );
20+
21+
void setInputPixel ( const Pixel& pixel ); // ColorProfile
22+
void setOutputPixel( const Pixel& pixel );
23+
24+
bool init();
25+
26+
void convert( const Image& src, Image& dst );
27+
28+
29+
private:
30+
size_t m_width;
31+
size_t m_height;
32+
33+
Pixel m_inputPixel;
34+
Pixel m_outputPixel;
35+
};
36+
37+
}
38+
39+
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef _AV_TRANSCODER_DATA_FRAME_HPP_
2+
#define _AV_TRANSCODER_DATA_FRAME_HPP_
3+
4+
#include <string>
5+
6+
namespace avtranscoder
7+
{
8+
9+
class Frame
10+
{
11+
public:
12+
Frame(){};
13+
14+
private:
15+
16+
};
17+
18+
}
19+
20+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#ifndef _AV_TRANSCODER_DATA_IMAGE_HPP_
2+
#define _AV_TRANSCODER_DATA_IMAGE_HPP_
3+
4+
#include <string>
5+
#include <vector>
6+
#include "Pixel.hpp"
7+
8+
namespace avtranscoder
9+
{
10+
11+
typedef std::vector< unsigned char > DataBuffer;
12+
13+
// struct ColorProperties
14+
// {
15+
// //EColorspace eColorspace;
16+
// AVColorTransferCharacteristic eColorTransfer;
17+
// AVColorPrimaries eColorPrimaries;
18+
// //EColorRange eColorRange;
19+
// };
20+
21+
class Image
22+
{
23+
public:
24+
Image()
25+
{};
26+
27+
//void alloc() { m_dataBuffer = data; }
28+
29+
// for overloading get_buffer2
30+
// int alloc( struct AVCodecContext* s,
31+
// AVFrame* frame,
32+
// int flags )
33+
// {
34+
35+
// }
36+
37+
void setWidth ( const size_t width ) { m_width = width; }
38+
void setHeight( const size_t height ) { m_height = height; }
39+
// void setDar ( const Ratio& dar ) { m_displayAspectRatio = dar; }
40+
void setPixel ( const Pixel& pixel ) { m_pixel = pixel; }
41+
42+
DataBuffer& getBuffer() { return m_dataBuffer; }
43+
unsigned char* getPtr() { return &m_dataBuffer[0]; }
44+
const unsigned char* getPtr() const { return &m_dataBuffer[0]; }
45+
46+
size_t getWidth () const { return m_width; }
47+
size_t getHeight() const { return m_height; }
48+
// Ratio getDar() const { return m_displayAspectRatio; }
49+
Pixel getPixel() const { return m_pixel; }
50+
51+
private:
52+
DataBuffer m_dataBuffer;
53+
size_t m_width;
54+
size_t m_height;
55+
// Ratio m_displayAspectRatio;
56+
Pixel m_pixel;
57+
// ColorProperties m_color;
58+
59+
bool m_interlaced;
60+
bool m_topFieldFirst;
61+
};
62+
63+
}
64+
65+
#endif

0 commit comments

Comments
 (0)