Skip to content

Commit 3ad0463

Browse files
author
Clement Champetier
committed
Merge branch 'master' of https://github.com/MarcAntoine-Arnaud/avTranscoder into dev_refactoring
Conflicts: src/AvTranscoder/InputFile.hpp src/AvTranscoder/Transcoder.tcc
2 parents 6105f25 + c7ff0c3 commit 3ad0463

15 files changed

+359
-9
lines changed

app/avTranscoder/avTranscoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <iostream>
22
#include <iomanip>
3+
#include <cstdlib>
34

45
#include <AvTranscoder/AvInputStream.hpp>
56
#include <AvTranscoder/InputStreamAudio.hpp>

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/DummyInputStream.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "DummyInputStream.hpp"
22

33
#include <cassert>
4+
#include <cstring>
45

56
namespace avtranscoder
67
{
@@ -66,4 +67,4 @@ void DummyInputStream::clearBuffering()
6667
{
6768
}
6869

69-
}
70+
}

src/AvTranscoder/InputFile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ InputFile& InputFile::analyse()
7171
{
7272
assert( m_formatContext != NULL );
7373

74+
seekAtFrame( 0 );
75+
7476
m_properties.filename = m_formatContext->filename;
7577
m_properties.formatName = m_formatContext->iformat->name;
7678
m_properties.formatLongName = m_formatContext->iformat->long_name;
@@ -129,6 +131,8 @@ InputFile& InputFile::analyse()
129131
}
130132
}
131133

134+
seekAtFrame( 0 );
135+
132136
return *this;
133137
}
134138

src/AvTranscoder/InputFile.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef _AV_TRANSCODER_INPUT_FILE_HPP_
22
#define _AV_TRANSCODER_INPUT_FILE_HPP_
33

4-
#include <AvTranscoder/AvInputStream.hpp>
54
#include <AvTranscoder/DatasStructures/DataStreamDesc.hpp>
65
#include <AvTranscoder/DatasStructures/AudioDesc.hpp>
76
#include <AvTranscoder/DatasStructures/VideoDesc.hpp>
@@ -20,6 +19,8 @@ class AVCodecContext;
2019
namespace avtranscoder
2120
{
2221

22+
class AvInputStream;
23+
2324
class AvExport InputFile
2425
{
2526
public:

src/AvTranscoder/InputStream.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class InputStream
1414
InputStream( )
1515
{}
1616

17+
virtual ~InputStream(){};
18+
1719
virtual size_t getStreamIndex() const = 0;
1820

1921
virtual bool readNextPacket( DataStream& data ) = 0;

src/AvTranscoder/InputStreamAudio.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ InputStreamAudio::InputStreamAudio( const InputStream& inputStream )
4343
std::cout << "Audio codec Id : " << m_codecContext->codec_id << std::endl;
4444
std::cout << "Audio codec Id : " << m_codec->long_name << std::endl;
4545

46+
m_codecContext->channels = m_inputStream->getAudioDesc().getCodecContext()->channels;
47+
4648
int ret = avcodec_open2( m_codecContext, m_codec, NULL );
4749

4850
std::cout << "ret value : " << ret << std::endl;
@@ -99,8 +101,7 @@ InputStreamAudio::~InputStreamAudio()
99101

100102
bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
101103
{
102-
/*
103-
int got_frame = 0;
104+
/*int got_frame = 0;
104105
while( ! got_frame )
105106
{
106107
AVPacket packet;
@@ -112,6 +113,10 @@ bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
112113
return false;
113114
}
114115
116+
packet.stream_index = m_selectedStream;
117+
packet.data = audioFrameBuffer.getPtr();
118+
packet.size = audioFrameBuffer.getSize();
119+
115120
int ret = avcodec_decode_audio4( m_codecContext, m_frame, &got_frame, &packet );
116121
117122
if( ret < 0 )
@@ -120,8 +125,8 @@ bool InputStreamAudio::readNextFrame( AudioFrame& audioFrameBuffer )
120125
}
121126
122127
av_free_packet( &packet );
123-
}*/
124-
128+
}
129+
*/
125130
//size_t unpadded_linesize = m_frame->nb_samples * av_get_bytes_per_sample( m_frame->format );
126131

127132
// size_t decodedSize = avpicture_get_size( (AVPixelFormat)m_frame->format, m_frame->width, m_frame->height );

src/AvTranscoder/OutputFile.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class AvExport OutputFile
2323
public:
2424
OutputFile( const std::string& file = "" );
2525

26+
virtual ~OutputFile(){};
27+
2628
virtual bool setup();
2729

2830
virtual void addVideoStream( const VideoDesc& videoDesc );

src/AvTranscoder/OutputStreamVideo.cpp

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ extern "C" {
1212
#include <libavutil/mathematics.h>
1313
}
1414

15+
#include "Profile.hpp"
16+
1517
#include <iostream>
1618

1719
namespace avtranscoder
@@ -101,19 +103,102 @@ bool OutputStreamVideo::encodeFrame( const Image& sourceImage, DataStream& coded
101103
memcpy( codedFrame.getPtr(), packet.data, packet.size );
102104
}
103105
#endif
104-
105-
106+
/*
107+
std::string imgType = "";
108+
switch( codecContext->coded_frame->pict_type )
109+
{
110+
case AV_PICTURE_TYPE_NONE : imgType = "None"; break;
111+
case AV_PICTURE_TYPE_I : imgType = "I"; break;
112+
case AV_PICTURE_TYPE_P : imgType = "P"; break;
113+
case AV_PICTURE_TYPE_B : imgType = "B"; break;
114+
case AV_PICTURE_TYPE_S : imgType = "S"; break;
115+
case AV_PICTURE_TYPE_SI : imgType = "SI"; break;
116+
case AV_PICTURE_TYPE_SP : imgType = "SP"; break;
117+
case AV_PICTURE_TYPE_BI : imgType = "BI"; break;
118+
}
119+
120+
std::clog << "\tframe " << codecContext->coded_frame->display_picture_number;
121+
std::clog << " coded @ " << codecContext->coded_frame->coded_picture_number;
122+
std::clog << " type : " << imgType;
123+
std::clog << " quality : " << codecContext->coded_frame->quality << std::endl;
124+
*/
106125
av_free_packet( &packet );
107126
#if LIBAVCODEC_VERSION_MAJOR > 54
108127
av_frame_free( &frame );
128+
return ret == 0 && gotPacket == 1;
109129
#else
110130
#if LIBAVCODEC_VERSION_MAJOR > 53
111131
avcodec_free_frame( &frame );
132+
return ret == 0 && gotPacket == 1;
112133
#else
113134
av_free( frame );
114135
#endif
115136
#endif
116-
return ret < 0;
137+
return ret == 0;
138+
}
139+
140+
141+
bool OutputStreamVideo::encodeFrame( DataStream& codedFrame )
142+
{
143+
AVCodecContext* codecContext = m_videoDesc.getCodecContext();
144+
145+
AVPacket packet;
146+
av_init_packet( &packet );
147+
// avcodec_encode_video allocate packet
148+
packet.size = 0;
149+
packet.data = NULL;
150+
packet.stream_index = 0;
151+
152+
#if LIBAVCODEC_VERSION_MAJOR > 53
153+
int gotPacket = 0;
154+
int ret = avcodec_encode_video2( codecContext, &packet, NULL, &gotPacket );
155+
if( ret == 0 && gotPacket == 1 )
156+
{
157+
codedFrame.getBuffer().resize( packet.size );
158+
memcpy( codedFrame.getPtr(), packet.data, packet.size );
159+
}
160+
av_free_packet( &packet );
161+
return ret == 0 && gotPacket == 1;
162+
163+
#else
164+
int ret = avcodec_encode_video( codecContext, packet.data, packet.size, NULL );
165+
if( ret > 0 )
166+
{
167+
codedFrame.getBuffer().resize( packet.size );
168+
memcpy( codedFrame.getPtr(), packet.data, packet.size );
169+
}
170+
av_free_packet( &packet );
171+
return ret == 0;
172+
173+
#endif
174+
}
175+
176+
void OutputStreamVideo::setProfile( const std::string& profile )
177+
{
178+
Profile p;
179+
p.loadProfiles();
180+
181+
Profile::ProfileDesc prof = p.getProfile( profile );
182+
183+
m_videoDesc.setVideoCodec( prof["codec"] );
184+
m_videoDesc.setTimeBase( 1, 25 ); // 25 fps
185+
// m_videoDesc.set( "pix_fmt", prof["pix_fmt"] );
186+
187+
setup();
188+
189+
for( Profile::ProfileDesc::iterator it = prof.begin(); it != prof.end(); ++it )
190+
{
191+
if( (*it).first == "avProfile" )
192+
continue;
193+
if( (*it).first == "avProfileLong" )
194+
continue;
195+
if( (*it).first == "codec" )
196+
continue;
197+
// if( (*it).first == "pix_fmt" )
198+
// continue;
199+
200+
m_videoDesc.set( (*it).first, (*it).second );
201+
}
117202
}
118203

119204
}

src/AvTranscoder/OutputStreamVideo.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ class AvExport OutputStreamVideo : public OutputStream
3737
*/
3838
bool encodeFrame( const Image& sourceImage, DataStream& codedFrame );
3939

40+
/**
41+
* get delayed encoded frames
42+
*/
43+
bool encodeFrame( DataStream& codedFrame );
44+
4045
VideoDesc& getVideoDesc() { return m_videoDesc; }
4146

47+
void setProfile( const std::string& profile );
48+
4249
private:
4350
VideoDesc m_videoDesc;
4451
};

0 commit comments

Comments
 (0)