@@ -21,13 +21,20 @@ namespace avtranscoder
21
21
22
22
VideoProperties::VideoProperties ( const AVFormatContext* formatContext, const size_t index, IProgress& progress, const EAnalyseLevel level )
23
23
: _formatContext( formatContext )
24
- , _codecContext( formatContext->streams[index]->codec )
24
+ , _codecContext( NULL )
25
+ , _codec( NULL )
25
26
, _pixFmt( NULL )
26
27
, _streamId( index )
27
28
, _isInterlaced( false )
28
29
, _isTopFieldFirst( false )
29
30
, _gopStructure()
30
31
{
32
+ if ( _formatContext )
33
+ _codecContext = formatContext->streams [index]->codec ;
34
+
35
+ if ( _formatContext && _codecContext )
36
+ _codec = avcodec_find_decoder ( _codecContext->codec_id );
37
+
31
38
// Skip decoding for selected frames
32
39
_codecContext->skip_frame = AVDISCARD_NONE;
33
40
@@ -46,42 +53,41 @@ VideoProperties::VideoProperties( const AVFormatContext* formatContext, const si
46
53
47
54
std::string VideoProperties::getCodecName () const
48
55
{
49
- AVCodec* codec = NULL ;
50
- if ( ( codec = avcodec_find_decoder ( _codecContext->codec_id ) ) != NULL )
56
+ if ( _codecContext && _codec )
51
57
{
52
- if ( codec ->capabilities & CODEC_CAP_TRUNCATED )
58
+ if ( _codec ->capabilities & CODEC_CAP_TRUNCATED )
53
59
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
54
60
55
- return std::string ( codec->name );
61
+ if ( _codec->name )
62
+ return std::string ( _codec->name );
56
63
}
57
64
return " unknown codec" ;
58
65
}
59
66
60
67
std::string VideoProperties::getCodecLongName () const
61
68
{
62
- AVCodec* codec = NULL ;
63
- if ( ( codec = avcodec_find_decoder ( _codecContext->codec_id ) ) != NULL )
69
+ if ( _codecContext && _codec )
64
70
{
65
- if ( codec ->capabilities & CODEC_CAP_TRUNCATED )
71
+ if ( _codec ->capabilities & CODEC_CAP_TRUNCATED )
66
72
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
67
73
68
- return std::string ( codec->long_name );
74
+ if ( _codec->long_name )
75
+ return std::string ( _codec->long_name );
69
76
}
70
77
return " unknown codec" ;
71
78
}
72
79
73
80
std::string VideoProperties::getProfileName () const
74
81
{
75
- AVCodec* codec = NULL ;
76
- if ( ( codec = avcodec_find_decoder ( _codecContext->codec_id ) ) != NULL )
82
+ if ( _codecContext && _codec )
77
83
{
78
- if ( codec ->capabilities & CODEC_CAP_TRUNCATED )
84
+ if ( _codec ->capabilities & CODEC_CAP_TRUNCATED )
79
85
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
80
86
81
87
if ( _codecContext->profile != -99 )
82
88
{
83
89
const char * profile;
84
- if ( ( profile = av_get_profile_name ( codec , _codecContext->profile ) ) != NULL )
90
+ if ( ( profile = av_get_profile_name ( _codec , _codecContext->profile ) ) != NULL )
85
91
return std::string ( profile );
86
92
}
87
93
}
@@ -363,10 +369,9 @@ bool VideoProperties::hasAlpha() const
363
369
364
370
void VideoProperties::analyseGopStructure ( IProgress& progress )
365
371
{
366
- AVCodec* codec = NULL ;
367
- if ( ( codec = avcodec_find_decoder ( _codecContext->codec_id ) ) != NULL )
372
+ if ( _formatContext && _codecContext && _codec )
368
373
{
369
- if ( codec ->capabilities & CODEC_CAP_TRUNCATED )
374
+ if ( _codec ->capabilities & CODEC_CAP_TRUNCATED )
370
375
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
371
376
372
377
if ( _codecContext->width && _codecContext->height )
@@ -380,7 +385,7 @@ void VideoProperties::analyseGopStructure( IProgress& progress )
380
385
#endif
381
386
382
387
av_init_packet ( &pkt );
383
- avcodec_open2 ( _codecContext, codec , NULL );
388
+ avcodec_open2 ( _codecContext, _codec , NULL );
384
389
385
390
int count = 0 ;
386
391
int gotFrame = 0 ;
0 commit comments