Skip to content

Commit 52713ee

Browse files
adapt Transcoder to opening minimal number of files
1 parent 9398795 commit 52713ee

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

app/genericProcessor/genericProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void parseConfigFile( const std::string& configFilename, avtranscoder::Transcode
2323
std::string streamId;
2424
if( std::getline( is_line, streamId ) )
2525
{
26-
std::cout << filename << "( " << streamId << " )" << std::endl;
26+
std::cout << filename << " ( " << streamId << " )" << std::endl;
2727
streams.push_back( std::pair< std::string, int >( filename, atoi( streamId.c_str() ) ) );
2828
}
2929
}

src/AvTranscoder/InputFile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ InputFile::InputFile( const std::string& filename )
2929
: m_formatContext ( NULL )
3030
, m_filename ( filename )
3131
{
32+
std::cout << "opening file " << m_filename << std::endl;
33+
3234
av_register_all(); // Warning: should be called only once
3335
if( avformat_open_input( &m_formatContext, m_filename.c_str(), NULL, NULL ) < 0 )
3436
{

src/AvTranscoder/InputFile.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class AvExport InputFile
2626
InputFile( const std::string& filename );
2727
~InputFile();
2828

29+
std::string getFilename() const { return m_filename; }
30+
2931
// *** Metadatas section ***
3032
// run the analyse on the file after a setup.
3133
InputFile& analyse();

src/AvTranscoder/InputStreamVideo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ bool InputStreamVideo::readNextFrame( Image& frameBuffer )
103103
av_init_packet( &packet );
104104

105105
packet.stream_index = m_selectedStream;
106-
packet.data = data.getPtr();
107-
packet.size = data.getSize();
106+
packet.data = data.getPtr();
107+
packet.size = data.getSize();
108108

109109
avcodec_decode_video2( m_codecContext, m_frame, &got_frame, &packet );
110110

src/AvTranscoder/OutputStreamVideo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ bool OutputStreamVideo::setup( )
2626
{
2727
av_register_all(); // Warning: should be called only once
2828

29-
AVCodecContext* codecContext;
30-
codecContext = m_videoDesc.getCodecContext();
29+
AVCodecContext* codecContext( m_videoDesc.getCodecContext() );
3130

3231
if( codecContext == NULL )
3332
return false;

src/AvTranscoder/Transcoder.hpp

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

4+
#include <AvTranscoder/InputFile.hpp>
45
#include <AvTranscoder/InputStream.hpp>
56
#include <AvTranscoder/OutputFile.hpp>
67
#include <AvTranscoder/ProgressListener.hpp>
@@ -28,8 +29,9 @@ class Transcoder
2829
void process( ProgressListener& progress );
2930

3031
private:
31-
OutputFile& _outputFile;
32-
std::vector< InputStream > _inputStreams;
32+
OutputFile& _outputFile;
33+
std::vector< InputFile* > _inputFiles;
34+
std::vector< InputStream* > _inputStreams;
3335
};
3436

3537
}

src/AvTranscoder/Transcoder.tcc

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,45 @@ Transcoder::Transcoder( OutputFile& outputFile )
1111

1212
Transcoder::~Transcoder()
1313
{
14+
for( std::vector< InputFile* >::iterator it = _inputFiles.begin(); it != _inputFiles.end(); ++it )
15+
{
16+
delete (*it);
17+
}
1418
}
1519

1620
void Transcoder::add( const std::string& filename, const size_t streamIndex )
1721
{
18-
InputFile inputFile( filename );
22+
InputFile* referenceFile = NULL;
23+
24+
for( std::vector< InputFile* >::iterator it = _inputFiles.begin(); it != _inputFiles.end(); ++it )
25+
{
26+
if( (*it)->getFilename() == filename )
27+
{
28+
referenceFile = (*it);
29+
break;
30+
}
31+
}
1932

20-
switch( inputFile.getStreamType( streamIndex ) )
33+
if( ! referenceFile )
34+
{
35+
_inputFiles.push_back( new InputFile( filename ) );
36+
referenceFile = _inputFiles.back();
37+
}
38+
39+
referenceFile->readStream( streamIndex );
40+
41+
switch( referenceFile->getStreamType( streamIndex ) )
2142
{
2243
case AVMEDIA_TYPE_VIDEO:
2344
{
24-
_inputStreams.push_back( inputFile.getStream( streamIndex ) );
25-
_outputFile.addVideoStream( _inputStreams.back().getVideoDesc() );
45+
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
46+
_outputFile.addVideoStream( _inputStreams.back()->getVideoDesc() );
2647
break;
2748
}
2849
case AVMEDIA_TYPE_AUDIO:
2950
{
30-
_inputStreams.push_back( inputFile.getStream( streamIndex ) );
31-
_outputFile.addAudioStream( _inputStreams.back().getAudioDesc() );
51+
_inputStreams.push_back( &referenceFile->getStream( streamIndex ) );
52+
_outputFile.addAudioStream( _inputStreams.back()->getAudioDesc() );
3253
break;
3354
}
3455
case AVMEDIA_TYPE_DATA:
@@ -74,16 +95,18 @@ void Transcoder::process( ProgressListener& progress )
7495
// read one frame for each streamIndex
7596
for( size_t streamIndex = 0; streamIndex < _inputStreams.size(); ++streamIndex )
7697
{
77-
bool ret = _inputStreams.at( streamIndex ).readNextPacket( dataStreams.at( streamIndex ) );
98+
bool ret = _inputStreams.at( streamIndex )->readNextPacket( dataStreams.at( streamIndex ) );
7899

79100
if( ! ret || ( dataStreams.at( streamIndex ).getBuffer().size() == 0 ) )
101+
{
80102
continueProcess = false;
103+
}
81104
}
82105

83106
if( ! continueProcess )
84107
break;
85108

86-
switch( progress.progress( _inputStreams.at( 0 ).getPacketDuration() * ( frame + 1 ), _inputStreams.at( 0 ).getDuration() ) )
109+
switch( progress.progress( _inputStreams.at( 0 )->getPacketDuration() * ( frame + 1 ), _inputStreams.at( 0 )->getDuration() ) )
87110
{
88111
case eJobStatusContinue:
89112
{

0 commit comments

Comments
 (0)