@@ -28,6 +28,7 @@ VideoProperties::VideoProperties(const FileProperties& fileProperties, const siz
28
28
, _isTopFieldFirst(false )
29
29
, _gopSize(0 )
30
30
, _gopStructure()
31
+ , _nbFrames(0 )
31
32
, _firstGopTimeCode(-1 )
32
33
{
33
34
if (_codecContext)
@@ -38,6 +39,8 @@ VideoProperties::VideoProperties(const FileProperties& fileProperties, const siz
38
39
39
40
if (_levelAnalysis == eAnalyseLevelFirstGop)
40
41
analyseGopStructure (progress);
42
+ else if (_levelAnalysis == eAnalyseLevelFull)
43
+ analyseFull (progress);
41
44
}
42
45
43
46
std::string VideoProperties::getProfileName () const
@@ -365,6 +368,9 @@ size_t VideoProperties::getNbFrames() const
365
368
size_t nbFrames = _formatContext->streams [_streamIndex]->nb_frames ;
366
369
if (nbFrames == 0 )
367
370
{
371
+ if (_levelAnalysis == eAnalyseLevelFull)
372
+ return _nbFrames;
373
+
368
374
LOG_WARN (" The number of frames in the stream '" << _streamIndex << " ' of file '" << _formatContext->filename
369
375
<< " ' is unknown." )
370
376
const float duration = getDuration ();
@@ -554,6 +560,38 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
554
560
}
555
561
}
556
562
563
+ void VideoProperties::analyseFull (IProgress& progress)
564
+ {
565
+ analyseGopStructure (progress);
566
+
567
+ if (! _formatContext || ! _codecContext || ! _codec)
568
+ return ;
569
+ if (! _codecContext->width || ! _codecContext->height )
570
+ return ;
571
+
572
+ InputFile& file = const_cast <InputFile&>(_fileProperties->getInputFile ());
573
+ // Get the stream
574
+ IInputStream& stream = file.getStream (_streamIndex);
575
+ stream.activate ();
576
+ // Create a decoder
577
+ VideoDecoder decoder (static_cast <InputStream&>(stream));
578
+
579
+ VideoFrame frame (VideoFrameDesc (getWidth (), getHeight (), getPixelProperties ().getAVPixelFormat ()));
580
+ while (decoder.decodeNextFrame (frame))
581
+ {
582
+ ++_nbFrames;
583
+ }
584
+
585
+ // Returns at the beginning of the stream
586
+ file.seekAtFrame (0 , AVSEEK_FLAG_BYTE);
587
+
588
+ // Check GOP size
589
+ if (_nbFrames <= 0 )
590
+ {
591
+ throw std::runtime_error (" Invalid number of frames when decoding the video stream." );
592
+ }
593
+ }
594
+
557
595
PropertyVector& VideoProperties::fillVector (PropertyVector& data) const
558
596
{
559
597
// Add properties of base class
0 commit comments