Skip to content

Commit 8635b3b

Browse files
author
Clement Champetier
committed
VideoProperties: refactor how to decode the first frames to get info
Because we are using ffmpeg/libav functions, we should use ffmpeg/libav structures too.
1 parent c2edefe commit 8635b3b

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/AvTranscoder/properties/VideoProperties.cpp

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

3-
#include <AvTranscoder/data/decoded/Frame.hpp>
43
#include <AvTranscoder/properties/util.hpp>
54
#include <AvTranscoder/properties/FileProperties.hpp>
65
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
@@ -342,7 +341,7 @@ size_t VideoProperties::getBitRate() const
342341
// discard no frame type when decode
343342
_codecContext->skip_frame = AVDISCARD_NONE;
344343

345-
Frame frame;
344+
AVFrame avFrame;
346345
AVPacket pkt;
347346
av_init_packet(&pkt);
348347
avcodec_open2(_codecContext, _codec, NULL);
@@ -357,11 +356,10 @@ size_t VideoProperties::getBitRate() const
357356
{
358357
if(pkt.stream_index == (int)_streamIndex)
359358
{
360-
avcodec_decode_video2(_codecContext, &frame.getAVFrame(), &gotFrame, &pkt);
359+
avcodec_decode_video2(_codecContext, &avFrame, &gotFrame, &pkt);
361360
if(gotFrame)
362361
{
363362
// check distance between key frames
364-
AVFrame& avFrame = frame.getAVFrame();
365363
if(avFrame.pict_type == AV_PICTURE_TYPE_I)
366364
{
367365
if(positionOfFirstKeyFrame == -1)
@@ -375,7 +373,7 @@ size_t VideoProperties::getBitRate() const
375373
if(positionOfLastKeyFrame == -1)
376374
{
377375
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(54, 7, 100)
378-
gopFramesSize += frame.getEncodedSize();
376+
gopFramesSize += av_frame_get_pkt_size(&avFrame);
379377
#else
380378
gopFramesSize += pkt.size;
381379
#endif
@@ -567,7 +565,7 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
567565
// Initialize the AVCodecContext to use the given AVCodec
568566
avcodec_open2(_codecContext, _codec, NULL);
569567

570-
Frame frame;
568+
AVFrame avFrame;
571569
size_t count = 0;
572570
int gotFrame = 0;
573571
int positionOfFirstKeyFrame = -1;
@@ -577,13 +575,11 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
577575
{
578576
if(pkt.stream_index == (int)_streamIndex)
579577
{
580-
avcodec_decode_video2(_codecContext, &frame.getAVFrame(), &gotFrame, &pkt);
578+
avcodec_decode_video2(_codecContext, &avFrame, &gotFrame, &pkt);
581579
if(gotFrame)
582580
{
583-
AVFrame& avFrame = frame.getAVFrame();
584-
585581
_gopStructure.push_back(
586-
std::make_pair(av_get_picture_type_char(avFrame.pict_type), frame.getEncodedSize()));
582+
std::make_pair(av_get_picture_type_char(avFrame.pict_type), av_frame_get_pkt_size(&avFrame)));
587583
_isInterlaced = avFrame.interlaced_frame;
588584
_isTopFieldFirst = avFrame.top_field_first;
589585
if(avFrame.pict_type == AV_PICTURE_TYPE_I)

0 commit comments

Comments
 (0)