Skip to content

Commit acd25dc

Browse files
author
Clement Champetier
committed
VideoProperties: refactor how to analyse the GOP structure
Use the avtranscoder objects: easier to maintain.
1 parent 42f78c9 commit acd25dc

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

src/AvTranscoder/properties/VideoProperties.cpp

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "VideoProperties.hpp"
22

3-
#include <AvTranscoder/data/decoded/Frame.hpp>
3+
#include <AvTranscoder/decoder/VideoDecoder.hpp>
4+
#include <AvTranscoder/data/decoded/VideoFrame.hpp>
45
#include <AvTranscoder/properties/util.hpp>
56
#include <AvTranscoder/properties/FileProperties.hpp>
67
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
@@ -502,46 +503,36 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
502503
if(! _codecContext->width || ! _codecContext->height)
503504
return;
504505

506+
InputFile& file = const_cast<InputFile&>(_fileProperties->getInputFile());
507+
// Get the stream
508+
IInputStream& stream = file.getStream(_streamIndex);
509+
stream.activate();
510+
// Setup a decoder
511+
VideoDecoder decoder(static_cast<InputStream&>(stream));
505512
// Discard no frame type when decode
506513
_codecContext->skip_frame = AVDISCARD_NONE;
507514

508-
AVPacket pkt;
509-
av_init_packet(&pkt);
510-
511-
// Initialize the AVCodecContext to use the given AVCodec
512-
avcodec_open2(_codecContext, _codec, NULL);
513-
514-
Frame frame;
515515
size_t count = 0;
516-
int gotFrame = 0;
517516
int positionOfFirstKeyFrame = -1;
518517
int positionOfLastKeyFrame = -1;
519-
520-
while(!av_read_frame(const_cast<AVFormatContext*>(_formatContext), &pkt))
518+
VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelProperties().getAVPixelFormat()));
519+
while(decoder.decodeNextFrame(frame))
521520
{
522-
if(pkt.stream_index == (int)_streamIndex)
521+
AVFrame& avFrame = frame.getAVFrame();
522+
523+
_gopStructure.push_back(
524+
std::make_pair(av_get_picture_type_char(avFrame.pict_type), frame.getEncodedSize()));
525+
_isInterlaced = avFrame.interlaced_frame;
526+
_isTopFieldFirst = avFrame.top_field_first;
527+
if(avFrame.pict_type == AV_PICTURE_TYPE_I)
523528
{
524-
avcodec_decode_video2(_codecContext, &frame.getAVFrame(), &gotFrame, &pkt);
525-
if(gotFrame)
526-
{
527-
AVFrame& avFrame = frame.getAVFrame();
528-
529-
_gopStructure.push_back(
530-
std::make_pair(av_get_picture_type_char(avFrame.pict_type), frame.getEncodedSize()));
531-
_isInterlaced = avFrame.interlaced_frame;
532-
_isTopFieldFirst = avFrame.top_field_first;
533-
if(avFrame.pict_type == AV_PICTURE_TYPE_I)
534-
{
535-
if(positionOfFirstKeyFrame == -1)
536-
positionOfFirstKeyFrame = count;
537-
else
538-
positionOfLastKeyFrame = count;
539-
}
540-
541-
_gopSize = ++count;
542-
}
529+
if(positionOfFirstKeyFrame == -1)
530+
positionOfFirstKeyFrame = count;
531+
else
532+
positionOfLastKeyFrame = count;
543533
}
544-
av_free_packet(&pkt);
534+
535+
_gopSize = ++count;
545536

546537
// If the first 2 key frames are found
547538
if(positionOfFirstKeyFrame != -1 && positionOfLastKeyFrame != -1)
@@ -555,11 +546,8 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
555546
}
556547
}
557548

558-
// Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext itself)
559-
avcodec_close(_codecContext);
560-
561549
// Returns at the beginning of the stream
562-
const_cast<InputFile&>(_fileProperties->getInputFile()).seekAtFrame(0, AVSEEK_FLAG_BYTE);
550+
file.seekAtFrame(0, AVSEEK_FLAG_BYTE);
563551

564552
// Check GOP size
565553
if(_gopSize <= 0)

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