Skip to content

Commit c33fb0f

Browse files
author
Clement Champetier
committed
VideoProperties: analyseGopStructure returns nb decoded frames
1 parent 16aafd0 commit c33fb0f

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -509,24 +509,24 @@ std::vector<std::pair<char, int> > VideoProperties::getGopStructure() const
509509
return _gopStructure;
510510
}
511511

512-
void VideoProperties::analyseGopStructure(IProgress& progress)
512+
size_t VideoProperties::analyseGopStructure(IProgress& progress)
513513
{
514514
if(! _formatContext || ! _codecContext || ! _codec)
515-
return;
515+
return 0;
516516
if(! _codecContext->width || ! _codecContext->height)
517-
return;
517+
return 0;
518518

519519
InputFile& file = const_cast<InputFile&>(_fileProperties->getInputFile());
520520
// Get the stream
521521
IInputStream& stream = file.getStream(_streamIndex);
522522
stream.activate();
523523
// Create a decoder
524524
VideoDecoder decoder(static_cast<InputStream&>(stream));
525+
VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelFormatName(getPixelProperties().getAVPixelFormat())), false);
525526

526-
size_t count = 0;
527+
size_t nbDecodedFrames = 0;
527528
int positionOfFirstKeyFrame = -1;
528529
int positionOfLastKeyFrame = -1;
529-
VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelFormatName(getPixelProperties().getAVPixelFormat())), false);
530530
while(decoder.decodeNextFrame(frame))
531531
{
532532
AVFrame& avFrame = frame.getAVFrame();
@@ -538,12 +538,12 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
538538
if(avFrame.pict_type == AV_PICTURE_TYPE_I)
539539
{
540540
if(positionOfFirstKeyFrame == -1)
541-
positionOfFirstKeyFrame = count;
541+
positionOfFirstKeyFrame = nbDecodedFrames;
542542
else
543-
positionOfLastKeyFrame = count;
543+
positionOfLastKeyFrame = nbDecodedFrames;
544544
}
545545

546-
_gopSize = ++count;
546+
_gopSize = ++nbDecodedFrames;
547547

548548
// If the first 2 key frames are found
549549
if(positionOfFirstKeyFrame != -1 && positionOfLastKeyFrame != -1)
@@ -565,6 +565,7 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
565565
{
566566
throw std::runtime_error("Invalid GOP size when decoding the first data.");
567567
}
568+
return nbDecodedFrames;
568569
}
569570

570571
void VideoProperties::analyseFull(IProgress& progress)

src/AvTranscoder/properties/VideoProperties.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ class AvExport VideoProperties : public StreamProperties
105105
private:
106106
/**
107107
* @param progress: callback to get analysis progression
108+
* @return the number of decoded frames to compute the GOP structure.
108109
*/
109-
void analyseGopStructure(IProgress& progress);
110+
size_t analyseGopStructure(IProgress& progress);
110111

111112
/**
112113
* @param progress: callback to get analysis progression

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy