Skip to content

Commit 2aaa176

Browse files
adding callback on analysis, and level of analysis (detecting gop structure or not)
1 parent ef11c95 commit 2aaa176

File tree

7 files changed

+60
-21
lines changed

7 files changed

+60
-21
lines changed

app/audioRewrapper/audioRewrapper.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
#include <AvTranscoder/AudioTransform.hpp>
1212

13-
14-
1513
void rewrapAudio( const char* inputfilename, const char* outputFilename )
1614
{
1715
using namespace avtranscoder;
1816

1917
av_log_set_level( AV_LOG_FATAL );
2018
av_log_set_level( AV_LOG_DEBUG );
2119

20+
ProgressListener p;
21+
2222
InputFile inputFile( inputfilename );
23-
inputFile.analyse();
23+
inputFile.analyse( p );
2424

2525
OutputFile outputFile( outputFilename );
2626

@@ -53,8 +53,10 @@ void transcodeAudio( const char* inputfilename, const char* outputFilename )
5353
av_log_set_level( AV_LOG_FATAL );
5454
av_log_set_level( AV_LOG_DEBUG );
5555

56+
ProgressListener p;
57+
5658
InputFile inputFile( inputfilename );
57-
inputFile.analyse();
59+
inputFile.analyse( p );
5860

5961
OutputFile outputFile( outputFilename );
6062
outputFile.setup();

app/avMeta/avMeta.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ int main( int argc, char** argv )
1111
return( -1 );
1212
}
1313

14+
avtranscoder::ProgressListener p;
15+
1416
avtranscoder::InputFile input( argv[1] );
15-
input.analyse();
17+
input.analyse( p );
1618

1719
// a simply metadata display
1820
displayMetadatas( input );

app/avTranscoder/avTranscoder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
2222

2323
// av_log_set_level( AV_LOG_DEBUG );
2424

25+
ProgressListener p;
26+
2527
InputFile input( inputfilename );
26-
input.analyse();
28+
input.analyse( p );
2729

2830
input.readStream( input.getProperties().videoStreams.at( 0 ).streamId );
2931

app/avplay/AvReader.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ class AvReader : public Reader
2222
, m_sourceImage( NULL )
2323
, m_imageToDisplay( NULL )
2424
{
25-
m_inputFile.analyse();
25+
avtranscoder::ProgressListener p;
26+
27+
m_inputFile.analyse( p );
2628
m_videoStream = m_inputFile.getProperties().videoStreams.at(0).streamId;
2729

2830
m_inputFile.readStream( m_videoStream );

src/AvTranscoder/InputFile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ InputFile::~InputFile()
6767
}
6868
}
6969

70-
InputFile& InputFile::analyse()
70+
InputFile& InputFile::analyse( ProgressListener& progress, const EAnalyseLevel level )
7171
{
7272
assert( _formatContext != NULL );
7373

@@ -95,7 +95,7 @@ InputFile& InputFile::analyse()
9595
{
9696
case AVMEDIA_TYPE_VIDEO:
9797
{
98-
_properties.videoStreams.push_back( videoStreamInfo( _formatContext, streamId ) );
98+
_properties.videoStreams.push_back( videoStreamInfo( _formatContext, streamId, progress, level ) );
9999
break;
100100
}
101101
case AVMEDIA_TYPE_AUDIO:
@@ -136,10 +136,10 @@ InputFile& InputFile::analyse()
136136
return *this;
137137
}
138138

139-
Properties InputFile::analyseFile( const std::string& filename )
139+
Properties InputFile::analyseFile( const std::string& filename, ProgressListener& progress, const EAnalyseLevel level )
140140
{
141141
InputFile file( filename );
142-
file.analyse();
142+
file.analyse( progress, level );
143143
Properties properties;
144144
file.getProperties( properties );
145145
return properties;

src/AvTranscoder/InputFile.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <AvTranscoder/DatasStructures/AudioDesc.hpp>
77
#include <AvTranscoder/DatasStructures/VideoDesc.hpp>
88
#include <AvTranscoder/Metadatas/MediaMetadatasStructures.hpp>
9+
#include <AvTranscoder/ProgressListener.hpp>
910

1011
#include <string>
1112
#include <vector>
@@ -31,6 +32,12 @@ class AvExport InputFile
3132

3233
~InputFile();
3334

35+
enum EAnalyseLevel
36+
{
37+
eAnalyseLevelFast = 0,
38+
eAnalyseLevelFull = 0,
39+
};
40+
3441
/**
3542
* @return Return the resource to access
3643
**/
@@ -39,8 +46,9 @@ class AvExport InputFile
3946
/**
4047
* @brief Run the analyse on the file after a setup.
4148
* call this function before getProperties().
49+
* @param progress callback to get analysis progression
4250
**/
43-
InputFile& analyse();
51+
InputFile& analyse( ProgressListener& progress, const EAnalyseLevel level = eAnalyseLevelFull );
4452

4553
/**
4654
* @brief Return media properties on the current InputFile.
@@ -53,9 +61,11 @@ class AvExport InputFile
5361

5462
/**
5563
* @brief Get media file properties using static method.
64+
* @param filename input filename
65+
* @param progress callback to get analysis progression
5666
* @return structure of media metadatas
5767
**/
58-
static Properties analyseFile( const std::string& filename );
68+
static Properties analyseFile( const std::string& filename, ProgressListener& progress, const EAnalyseLevel level = eAnalyseLevelFull );
5969

6070
/**
6171
* @brief Get stream type: video, audio, subtitle, etc.

src/AvTranscoder/Metadatas/VideoStreamProperties.hpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ namespace avtranscoder
2727
namespace details
2828
{
2929

30-
void getGopProperties( VideoProperties& vp, AVFormatContext* formatContext, AVCodecContext* codecContext, AVCodec* codec, const int index )
30+
void getGopProperties(
31+
VideoProperties& vp,
32+
AVFormatContext* formatContext,
33+
AVCodecContext* codecContext,
34+
AVCodec* codec,
35+
const int videoStreamIndex,
36+
ProgressListener& progress
37+
)
3138
{
3239
AVPacket pkt;
3340

@@ -42,10 +49,11 @@ void getGopProperties( VideoProperties& vp, AVFormatContext* formatContext, AVCo
4249

4350
int count = 0;
4451
int gotFrame = 0;
45-
52+
bool stopAnalyse = false;
53+
4654
while( ! av_read_frame( formatContext, &pkt ) )
4755
{
48-
if( pkt.stream_index == index )
56+
if( pkt.stream_index == videoStreamIndex )
4957
{
5058
avcodec_decode_video2( codecContext, frame, &gotFrame, &pkt );
5159
if( gotFrame )
@@ -54,15 +62,20 @@ void getGopProperties( VideoProperties& vp, AVFormatContext* formatContext, AVCo
5462
vp.isInterlaced = frame->interlaced_frame;
5563
vp.topFieldFirst = frame->top_field_first;
5664
++count;
65+
if( progress.progress( count, codecContext->gop_size ) == eJobStatusCancel )
66+
stopAnalyse = true;
5767
}
5868
}
5969

6070
av_free_packet( &pkt );
6171

6272
if( codecContext->gop_size == count )
6373
{
64-
break;
74+
stopAnalyse = true;
6575
}
76+
77+
if( stopAnalyse )
78+
break;
6679
}
6780
#if LIBAVCODEC_VERSION_MAJOR > 54
6881
av_frame_free( &frame );
@@ -90,14 +103,19 @@ std::string makeTimecodeMpegToString( uint32_t tc25bit )
90103
}
91104

92105

93-
VideoProperties videoStreamInfo( AVFormatContext* formatContext, const size_t index )
106+
VideoProperties videoStreamInfo(
107+
AVFormatContext* formatContext,
108+
const size_t videoStreamIndex,
109+
ProgressListener& progress,
110+
const InputFile::EAnalyseLevel level
111+
)
94112
{
95113
VideoProperties vp;
96-
AVCodecContext* codec_context = formatContext->streams[index]->codec;
114+
AVCodecContext* codec_context = formatContext->streams[videoStreamIndex]->codec;
97115

98116
codec_context->skip_frame = AVDISCARD_NONE;
99117

100-
vp.streamId = index;
118+
vp.streamId = videoStreamIndex;
101119

102120
vp.codecName = codec_context->codec_name;
103121
vp.codecLongName = codec_context->codec_name;
@@ -289,6 +307,9 @@ VideoProperties videoStreamInfo( AVFormatContext* formatContext, const size_t in
289307
}
290308
}
291309

310+
if( level == InputFile::eAnalyseLevelFast )
311+
return vp;
312+
292313
AVCodec* codec = NULL;
293314
if( ( codec = avcodec_find_decoder( codec_context->codec_id ) ) != NULL )
294315
{
@@ -307,7 +328,7 @@ VideoProperties videoStreamInfo( AVFormatContext* formatContext, const size_t in
307328

308329
if( codec_context->width && codec_context->height )
309330
{
310-
details::getGopProperties( vp, formatContext, codec_context, codec, index);
331+
details::getGopProperties( vp, formatContext, codec_context, codec, videoStreamIndex, progress );
311332
}
312333
}
313334

0 commit comments

Comments
 (0)