Skip to content

Commit bbbd56e

Browse files
author
Clement Champetier
committed
FileProperties: add extractStreamProperties
The streams analysis is done in the FileProperties, not in the InputFile.
1 parent f041f8c commit bbbd56e

File tree

4 files changed

+80
-62
lines changed

4 files changed

+80
-62
lines changed

src/AvTranscoder/file/InputFile.cpp

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <AvTranscoder/mediaProperty/SubtitleProperties.hpp>
88
#include <AvTranscoder/mediaProperty/AttachementProperties.hpp>
99
#include <AvTranscoder/mediaProperty/UnknownProperties.hpp>
10-
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
1110

1211
extern "C" {
1312
#include <libavcodec/avcodec.h>
@@ -29,10 +28,6 @@ InputFile::InputFile( const std::string& filename )
2928
{
3029
_formatContext.findStreamInfo();
3130

32-
// Analyse header
33-
NoDisplayProgress p;
34-
analyse( p, eAnalyseLevelHeader );
35-
3631
// Create streams
3732
for( size_t streamIndex = 0; streamIndex < _formatContext.getNbStreams(); ++streamIndex )
3833
{
@@ -50,60 +45,7 @@ InputFile::~InputFile()
5045

5146
void InputFile::analyse( IProgress& progress, const EAnalyseLevel level )
5247
{
53-
_properties.clearStreamProperties();
54-
55-
if( level > eAnalyseLevelHeader )
56-
seekAtFrame( 0 );
57-
58-
for( size_t streamIndex = 0; streamIndex < _formatContext.getNbStreams(); streamIndex++ )
59-
{
60-
switch( _formatContext.getAVStream( streamIndex ).codec->codec_type )
61-
{
62-
case AVMEDIA_TYPE_VIDEO:
63-
{
64-
VideoProperties properties( _formatContext, streamIndex, progress, level );
65-
_properties.getVideoProperties().push_back( properties );
66-
break;
67-
}
68-
case AVMEDIA_TYPE_AUDIO:
69-
{
70-
AudioProperties properties( _formatContext, streamIndex );
71-
_properties.getAudioProperties().push_back( properties );
72-
break;
73-
}
74-
case AVMEDIA_TYPE_DATA:
75-
{
76-
DataProperties properties( _formatContext, streamIndex );
77-
_properties.getDataProperties().push_back( properties );
78-
break;
79-
}
80-
case AVMEDIA_TYPE_SUBTITLE:
81-
{
82-
SubtitleProperties properties( _formatContext, streamIndex );
83-
_properties.getSubtitleProperties().push_back( properties );
84-
break;
85-
}
86-
case AVMEDIA_TYPE_ATTACHMENT:
87-
{
88-
AttachementProperties properties( _formatContext, streamIndex );
89-
_properties.getAttachementProperties().push_back( properties );
90-
break;
91-
}
92-
case AVMEDIA_TYPE_UNKNOWN:
93-
{
94-
UnknownProperties properties( _formatContext, streamIndex );
95-
_properties.getUnknownPropertiesProperties().push_back( properties );
96-
break;
97-
}
98-
case AVMEDIA_TYPE_NB:
99-
{
100-
break;
101-
}
102-
}
103-
}
104-
105-
if( level > eAnalyseLevelHeader )
106-
seekAtFrame( 0 );
48+
_properties.extractStreamProperties( progress, level );
10749
}
10850

10951
FileProperties InputFile::analyseFile( const std::string& filename, IProgress& progress, const EAnalyseLevel level )

src/AvTranscoder/mediaProperty/FileProperties.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "FileProperties.hpp"
22

3+
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
4+
35
#include <stdexcept>
46

57
namespace avtranscoder
@@ -17,6 +19,69 @@ FileProperties::FileProperties( const FormatContext& formatContext )
1719
{
1820
if( _avFormatContext )
1921
detail::fillMetadataDictionnary( _avFormatContext->metadata, _metadatas );
22+
23+
NoDisplayProgress progress;
24+
extractStreamProperties( progress, eAnalyseLevelHeader );
25+
}
26+
27+
void FileProperties::extractStreamProperties( IProgress& progress, const EAnalyseLevel level )
28+
{
29+
clearStreamProperties();
30+
31+
// if the analysis level wiil decode some streams parts, seek at the beginning
32+
if( level > eAnalyseLevelHeader )
33+
const_cast<FormatContext*>( _formatContext )->seek( 0 );
34+
35+
for( size_t streamIndex = 0; streamIndex < _formatContext->getNbStreams(); ++streamIndex )
36+
{
37+
switch( _formatContext->getAVStream( streamIndex ).codec->codec_type )
38+
{
39+
case AVMEDIA_TYPE_VIDEO:
40+
{
41+
VideoProperties properties( *_formatContext, streamIndex, progress, level );
42+
_videoStreams.push_back( properties );
43+
break;
44+
}
45+
case AVMEDIA_TYPE_AUDIO:
46+
{
47+
AudioProperties properties( *_formatContext, streamIndex );
48+
_audioStreams.push_back( properties );
49+
break;
50+
}
51+
case AVMEDIA_TYPE_DATA:
52+
{
53+
DataProperties properties( *_formatContext, streamIndex );
54+
_dataStreams.push_back( properties );
55+
break;
56+
}
57+
case AVMEDIA_TYPE_SUBTITLE:
58+
{
59+
SubtitleProperties properties( *_formatContext, streamIndex );
60+
_subtitleStreams.push_back( properties );
61+
break;
62+
}
63+
case AVMEDIA_TYPE_ATTACHMENT:
64+
{
65+
AttachementProperties properties( *_formatContext, streamIndex );
66+
_attachementStreams.push_back( properties );
67+
break;
68+
}
69+
case AVMEDIA_TYPE_UNKNOWN:
70+
{
71+
UnknownProperties properties( *_formatContext, streamIndex );
72+
_unknownStreams.push_back( properties );
73+
break;
74+
}
75+
case AVMEDIA_TYPE_NB:
76+
{
77+
break;
78+
}
79+
}
80+
}
81+
82+
// if the analysis level has decoded some streams parts, return at the beginning
83+
if( level > eAnalyseLevelHeader )
84+
const_cast<FormatContext*>( _formatContext )->seek( 0 );
2085
}
2186

2287
std::string FileProperties::getFilename() const

src/AvTranscoder/mediaProperty/FileProperties.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <AvTranscoder/common.hpp>
55
#include <AvTranscoder/mediaProperty/util.hpp>
66
#include <AvTranscoder/file/FormatContext.hpp>
7+
#include <AvTranscoder/progress/IProgress.hpp>
8+
79
#include <AvTranscoder/mediaProperty/VideoProperties.hpp>
810
#include <AvTranscoder/mediaProperty/AudioProperties.hpp>
911
#include <AvTranscoder/mediaProperty/DataProperties.hpp>
@@ -20,8 +22,20 @@ namespace avtranscoder
2022
class AvExport FileProperties
2123
{
2224
public:
25+
/**
26+
* @brief Analayse a file from its FormatContext
27+
* @note The default streams analyse level is eAnalyseLevelHeader
28+
* @see FormatContext
29+
*/
2330
FileProperties( const FormatContext& formatContext );
2431

32+
/**
33+
* @brief Relaunch streams analysis with a specific level.
34+
* @param progress callback to get analysis progression
35+
* @param level of analysis
36+
*/
37+
void extractStreamProperties( IProgress& progress, const EAnalyseLevel level );
38+
2539
std::string getFilename() const;
2640
std::string getFormatName() const; ///< A comma separated list of short names for the format
2741
std::string getFormatLongName() const;

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,6 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s
375375

376376
ProfileLoader::Profile Transcoder::getProfileFromFile( InputFile& inputFile, const size_t streamIndex )
377377
{
378-
NoDisplayProgress progress;
379-
inputFile.analyse( progress, eAnalyseLevelHeader );
380-
381378
const VideoProperties* videoProperties = NULL;
382379
const AudioProperties* audioProperties = NULL;
383380
switch( inputFile.getStream( streamIndex ).getStreamType() )

0 commit comments

Comments
 (0)