Skip to content

Commit a2f1f4b

Browse files
change API
1 parent 16a004f commit a2f1f4b

20 files changed

+581
-260
lines changed

app/avTranscoder/avTranscoder.cpp

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
#include <AvTranscoder/OutputStream.hpp>
99
#include <AvTranscoder/OutputStreamAudio.hpp>
1010
#include <AvTranscoder/OutputStreamVideo.hpp>
11+
#include <AvTranscoder/InputFile.hpp>
1112
#include <AvTranscoder/OutputFile.hpp>
1213

1314
#include <AvTranscoder/ColorTransform.hpp>
1415

15-
#include <AvTranscoder/DatasStructures/VideoStream.hpp>
16+
#include <AvTranscoder/DatasStructures/VideoDesc.hpp>
1617
#include <AvTranscoder/DatasStructures/Image.hpp>
1718

1819
void displayMetadatas( const char* filename )
@@ -53,7 +54,8 @@ void displayMetadatas( const char* filename )
5354
std::cout << "display aspect ratio : " << input.getProperties().videoStreams.at(videoStreamIndex).dar.num << "/" <<
5455
input.getProperties().videoStreams.at(videoStreamIndex).dar.den << std::endl;
5556
std::cout << "pixel type : " << input.getProperties().videoStreams.at(videoStreamIndex).pixelName << std::endl;
56-
std::cout << "number of components : " << input.getProperties().videoStreams.at(videoStreamIndex).componentsCount << std::endl;
57+
58+
std::cout << "bit rate : " << input.getProperties().videoStreams.at(videoStreamIndex).bitRate << std::endl;
5759

5860
std::cout << "color transfert : " << input.getProperties().videoStreams.at(videoStreamIndex).colorTransfert << std::endl;
5961
std::cout << "colorspace : " << input.getProperties().videoStreams.at(videoStreamIndex).colorspace << std::endl;
@@ -118,7 +120,7 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
118120
// init video & audio encoders
119121
OutputStreamVideo outputStreamVideo;
120122

121-
VideoStream& videoStream = outputStreamVideo.getVideoDesc();
123+
VideoDesc& videoDesc = outputStreamVideo.getVideoDesc();
122124

123125
Pixel oPixel;
124126

@@ -132,22 +134,22 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
132134

133135
Image sourceImage( imageDesc );
134136

135-
videoStream.setVideoCodec( "dnxhd" );
136-
videoStream.set( "b", 120000000 );
137+
videoDesc.setVideoCodec( "dnxhd" );
138+
videoDesc.set( "b", 120000000 );
137139
try
138140
{
139-
videoStream.set( "unknownParameter", 120000000 );
141+
videoDesc.set( "unknownParameter", 120000000 );
140142
}
141143
catch( const std::exception& e )
142144
{
143145
std::cout << "[ERROR] " << e.what() << std::endl;
144146
}
145147

146-
videoStream.setTimeBase( 1, 25 ); // 25 fps
148+
videoDesc.setTimeBase( 1, 25 ); // 25 fps
147149

148-
videoStream.setParametersFromImage( sourceImage );
150+
videoDesc.setImageParameters( sourceImage );
149151

150-
//videoStream.initCodecContext();
152+
//videoDesc.initCodecContext();
151153

152154
if( !outputStreamVideo.setup( ) )
153155
{
@@ -173,7 +175,10 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
173175
exit( -1 );
174176
}
175177

176-
if( ! of.addVideoStream() )
178+
InputFile inputFile( inputfilename );
179+
inputFile.setup();
180+
181+
if( ! of.addVideoStream( inputFile.getVideoDesc( 0 ) ) )
177182
{
178183
std::cout << "error during adding output video stream" << std::endl;
179184
exit( -1 );
@@ -198,34 +203,21 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
198203
// Encodage/transcodage
199204
std::cout << "start transcoding" << std::endl;
200205

201-
for( size_t count = 0; count < 10; ++count )
206+
size_t frame = 0;
207+
208+
while( inputStreamVideo.readNextFrame( sourceImage ) )
202209
{
203-
inputStreamVideo.readNextFrame( sourceImage );
210+
std::cout << "\rprocess frame " << frame << std::flush;
204211

205212
ct.convert( sourceImage, imageToEncode );
206-
std::cout << "encode" << std::endl;
207-
outputStreamVideo.encodeFrame( imageToEncode, codedImage );
208-
//std::cout << "decoded size " << frameBuffer.size() << " encode frame " << count << " size " << codedImage.size() << std::endl;
209-
std::cout << "wrap" << std::endl;
210-
of.wrap( codedImage, 0 );
211-
}
212-
213213

214-
//for( size_t frame : dVideo.framesCount() )
215-
{
216-
// read & decode source image,
217-
// send it to encoder which wraps it automatically
218-
//eVideo.encode( /* raw data */ dVideo.readNextFrame() );
219-
//eVideo.write()
220-
221-
// also to access to decoded data image
222-
//dVideo.getDataFrame();
214+
outputStreamVideo.encodeFrame( imageToEncode, codedImage );
223215

216+
of.wrap( codedImage, 0 );
224217

225-
//wrapper.write( /* char */ myRawData, streamIndex );
218+
++frame;
226219
}
227-
228-
//eAudioLeft.encode( );
220+
std::cout << std::endl;
229221
}
230222

231223
int main( int argc, char** argv )
@@ -238,7 +230,6 @@ int main( int argc, char** argv )
238230

239231
std::cout << "start ..." << std::endl;
240232

241-
242233
// a simply metadata getter
243234
displayMetadatas( argv[1] );
244235

src/AvTranscoder/ColorTransform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "ColorTransform.hpp"
2+
#include "common.hpp"
23

34
extern "C" {
45
#ifndef __STDC_CONSTANT_MACROS
@@ -13,7 +14,7 @@ extern "C" {
1314

1415
#include <iostream>
1516
#include <iomanip>
16-
#include <assert.h>
17+
#include <cassert>
1718
#include <stdexcept>
1819

1920
namespace avtranscoder

src/AvTranscoder/ColorTransform.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace avtranscoder
1414

1515
class ColorTransform
1616
{
17-
#define MAX_SWS_PLANE 4
1817
public:
1918
ColorTransform();
2019

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef _AV_TRANSCODER_DATA_DATA_STREAM_DESC_HPP_
2+
#define _AV_TRANSCODER_DATA_DATA_STREAM_DESC_HPP_
3+
4+
#include <string>
5+
6+
extern "C" {
7+
#ifndef __STDC_CONSTANT_MACROS
8+
#define __STDC_CONSTANT_MACROS
9+
#endif
10+
#ifndef INT64_C
11+
#define INT64_C(c) (c ## LL)
12+
#define UINT64_C(c) (c ## ULL)
13+
#endif
14+
#include <libavcodec/avcodec.h>
15+
}
16+
17+
namespace avtranscoder
18+
{
19+
20+
class DataStreamDesc
21+
{
22+
public:
23+
DataStreamDesc()
24+
{};
25+
26+
private:
27+
};
28+
29+
30+
class DataStream
31+
{
32+
public:
33+
DataStream( const DataStreamDesc& ref )
34+
: m_dataBuffer( 0, 0 )
35+
, m_dataStreamDesc( ref )
36+
{ }
37+
38+
const DataStreamDesc& desc() const { return m_dataStreamDesc; }
39+
DataBuffer& getBuffer() { return m_dataBuffer; }
40+
unsigned char* getPtr() { return &m_dataBuffer[0]; }
41+
#ifndef SWIG
42+
const unsigned char* getPtr() const { return &m_dataBuffer[0]; }
43+
#endif
44+
size_t getSize() const { return m_dataBuffer.size(); }
45+
46+
private:
47+
DataBuffer m_dataBuffer;
48+
const DataStreamDesc m_dataStreamDesc;
49+
};
50+
51+
}
52+
53+
#endif

src/AvTranscoder/DatasStructures/Image.hpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _AV_TRANSCODER_DATA_IMAGE_HPP_
22
#define _AV_TRANSCODER_DATA_IMAGE_HPP_
33

4+
#include <AvTranscoder/common.hpp>
5+
46
extern "C" {
57
#ifndef __STDC_CONSTANT_MACROS
68
#define __STDC_CONSTANT_MACROS
@@ -39,15 +41,14 @@ class ImageDesc
3941
void setWidth ( const size_t width ) { m_width = width; }
4042
void setHeight( const size_t height ) { m_height = height; }
4143
void setPixel ( const Pixel& pixel ) { m_pixel = pixel; }
42-
void setDar ( const size_t num, const size_t den ) { m_displayAspectRatioNum = num; m_displayAspectRatioDen = den; }
44+
void setDar ( const size_t num, const size_t den ) { m_displayAspectRatio.num = num; m_displayAspectRatio.den = den; }
45+
void setDar ( const Ratio ratio ) { m_displayAspectRatio = ratio; }
4346

44-
size_t getWidth () const { return m_width; }
45-
size_t getHeight() const { return m_height; }
46-
// Ratio getDar() const { return m_displayAspectRatio; }
47+
size_t getWidth () const { return m_width; }
48+
size_t getHeight() const { return m_height; }
49+
Ratio getDar() const { return m_displayAspectRatio; }
4750
Pixel getPixelDesc() const { return m_pixel; }
4851

49-
//AVFrame getEmptyFrame() const;
50-
5152
size_t getDataSize() const
5253
{
5354
return avpicture_get_size( m_pixel.findPixel(), m_width, m_height );
@@ -57,9 +58,7 @@ class ImageDesc
5758

5859
size_t m_width;
5960
size_t m_height;
60-
size_t m_displayAspectRatioNum;
61-
size_t m_displayAspectRatioDen;
62-
// Ratio m_displayAspectRatio;
61+
Ratio m_displayAspectRatio;
6362
Pixel m_pixel;
6463
// ColorProperties m_color;
6564

@@ -83,16 +82,6 @@ class Image
8382
#endif
8483
size_t getSize() const { return m_dataBuffer.size(); }
8584

86-
//void alloc() { m_dataBuffer = data; }
87-
88-
// for overloading get_buffer2
89-
// int alloc( struct AVCodecContext* s,
90-
// AVFrame* frame,
91-
// int flags )
92-
// {
93-
94-
// }
95-
9685
private:
9786
DataBuffer m_dataBuffer;
9887
const ImageDesc m_imageDesc;

0 commit comments

Comments
 (0)