Skip to content

Commit 567a5a8

Browse files
author
Clement Champetier
committed
VideoProperties: updated getters to the properties defined when analyse GOP
Throw an exception when the first GOP has not been analysed.
1 parent 27ad3d7 commit 567a5a8

File tree

3 files changed

+85
-12
lines changed

3 files changed

+85
-12
lines changed

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,34 @@ bool VideoProperties::hasBFrames() const
523523
// return ( _codecContext->flags & CODEC_FLAG_CLOSED_GOP ) == CODEC_FLAG_CLOSED_GOP;
524524
//}
525525

526+
bool VideoProperties::isInterlaced() const
527+
{
528+
if(_levelAnalysis < eAnalyseLevelFirstGop)
529+
throw std::runtime_error("Need a deeper analysis: see eAnalyseLevelFirstGop.");
530+
return _isInterlaced;
531+
}
532+
533+
bool VideoProperties::isTopFieldFirst() const
534+
{
535+
if(_levelAnalysis < eAnalyseLevelFirstGop)
536+
throw std::runtime_error("Need a deeper analysis: see eAnalyseLevelFirstGop.");
537+
return _isTopFieldFirst;
538+
}
539+
540+
size_t VideoProperties::getGopSize() const
541+
{
542+
if(_levelAnalysis < eAnalyseLevelFirstGop)
543+
throw std::runtime_error("Need a deeper analysis: see eAnalyseLevelFirstGop.");
544+
return _gopSize;
545+
}
546+
547+
std::vector<std::pair<char, int> > VideoProperties::getGopStructure() const
548+
{
549+
if(_levelAnalysis < eAnalyseLevelFirstGop)
550+
throw std::runtime_error("Need a deeper analysis: see eAnalyseLevelFirstGop.");
551+
return _gopStructure;
552+
}
553+
526554
void VideoProperties::analyseGopStructure(IProgress& progress)
527555
{
528556
if(_formatContext && _codecContext && _codec)

src/AvTranscoder/properties/VideoProperties.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ class AvExport VideoProperties : public StreamProperties
7171
// bool isClosedGop() const;
7272

7373
//@{
74-
// Warning: Can acces these data when analyse first gop
74+
// Warning: Can access these data only when analyse first gop (else throw a runtime_error)
7575
// @see EAnalyseLevel
7676
// @see analyseGopStructure
77-
bool isInterlaced() const { return _isInterlaced; }
78-
bool isTopFieldFirst() const { return _isTopFieldFirst; }
77+
bool isInterlaced() const;
78+
bool isTopFieldFirst() const;
7979
/**
8080
* @return the distance between two nearest I frame
8181
*/
82-
size_t getGopSize() const { return _gopSize; }
83-
std::vector<std::pair<char, int> > getGopStructure() const { return _gopStructure; }
82+
size_t getGopSize() const;
83+
std::vector<std::pair<char, int> > getGopStructure() const;
8484
//@}
8585

8686
#ifndef SWIG

test/pyTest/testInputFile.py

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,64 @@ def testCreateInputFileFromUnexistingFilename():
2020
av.InputFile( inputFileName )
2121

2222

23-
def testInputFileAnalyseFirstGop():
23+
@raises(RuntimeError)
24+
def testInputFileAnalyseHeaderTryToAccessisInterlaced():
2425
"""
25-
Analyse the first gop of an InputFile, and check if the correct attributes are filled.
26+
Analyse only header of an InputFile, and try to access a properties computed when access the first GOP.
2627
"""
2728
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
28-
inputFile = av.InputFile( inputFileName )
29+
inputFile = av.InputFile(inputFileName)
30+
31+
# The analyse of the first GOP is not done yet
32+
videoProperties = inputFile.getProperties().getVideoProperties()[0]
33+
videoProperties.isInterlaced()
34+
35+
36+
@raises(RuntimeError)
37+
def testInputFileAnalyseHeaderTryToAccessisTopFieldFirst():
38+
"""
39+
Analyse only header of an InputFile, and try to access a properties computed when access the first GOP.
40+
"""
41+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
42+
inputFile = av.InputFile(inputFileName)
2943

3044
# The analyse of the first GOP is not done yet
3145
videoProperties = inputFile.getProperties().getVideoProperties()[0]
32-
assert_equals(videoProperties.isInterlaced(), False)
33-
assert_equals(videoProperties.isTopFieldFirst(), False)
34-
assert_equals(videoProperties.getGopSize(), 0)
35-
assert_equals(videoProperties.getGopStructure(), ())
46+
videoProperties.isTopFieldFirst()
47+
48+
49+
@raises(RuntimeError)
50+
def testInputFileAnalyseHeaderTryToAccessisGopSize():
51+
"""
52+
Analyse only header of an InputFile, and try to access a properties computed when access the first GOP.
53+
"""
54+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
55+
inputFile = av.InputFile(inputFileName)
56+
57+
# The analyse of the first GOP is not done yet
58+
videoProperties = inputFile.getProperties().getVideoProperties()[0]
59+
videoProperties.getGopSize()
60+
61+
62+
@raises(RuntimeError)
63+
def testInputFileAnalyseHeaderTryToAccessisGopStructure():
64+
"""
65+
Analyse only header of an InputFile, and try to access a properties computed when access the first GOP.
66+
"""
67+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
68+
inputFile = av.InputFile(inputFileName)
69+
70+
# The analyse of the first GOP is not done yet
71+
videoProperties = inputFile.getProperties().getVideoProperties()[0]
72+
videoProperties.getGopStructure()
73+
74+
75+
def testInputFileAnalyseFirstGop():
76+
"""
77+
Analyse the first gop of an InputFile, and check if the correct attributes are filled.
78+
"""
79+
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
80+
inputFile = av.InputFile( inputFileName )
3681

3782
# Analyse first GOP
3883
progress = av.NoDisplayProgress()

0 commit comments

Comments
 (0)