Skip to content

Commit f6da521

Browse files
author
Clement Champetier
committed
VideoProperties: refactored the methods that use AVFrame
* Use Frame class instead (allocation/free is managed by the class).
1 parent a021550 commit f6da521

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

src/AvTranscoder/properties/VideoProperties.cpp

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

3+
#include <AvTranscoder/data/decoded/Frame.hpp>
34
#include <AvTranscoder/properties/util.hpp>
45
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
56

@@ -336,11 +337,7 @@ size_t VideoProperties::getBitRate() const
336337
// discard no frame type when decode
337338
_codecContext->skip_frame = AVDISCARD_NONE;
338339

339-
#if LIBAVCODEC_VERSION_MAJOR > 54
340-
AVFrame* frame = av_frame_alloc();
341-
#else
342-
AVFrame* frame = avcodec_alloc_frame();
343-
#endif
340+
Frame frame;
344341
AVPacket pkt;
345342
av_init_packet(&pkt);
346343
avcodec_open2(_codecContext, _codec, NULL);
@@ -353,11 +350,11 @@ size_t VideoProperties::getBitRate() const
353350
{
354351
if(pkt.stream_index == (int)_streamIndex)
355352
{
356-
avcodec_decode_video2(_codecContext, frame, &gotFrame, &pkt);
353+
avcodec_decode_video2(_codecContext, &frame.getAVFrame(), &gotFrame, &pkt);
357354
if(gotFrame)
358355
{
359356
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(54, 7, 100)
360-
gopFramesSize += av_frame_get_pkt_size(frame);
357+
gopFramesSize += av_frame_get_pkt_size(&frame.getAVFrame());
361358
#else
362359
gopFramesSize += pkt.size;
363360
#endif
@@ -368,13 +365,6 @@ size_t VideoProperties::getBitRate() const
368365
if(_codecContext->gop_size == count)
369366
break;
370367
}
371-
#if LIBAVCODEC_VERSION_MAJOR > 54
372-
av_frame_free(&frame);
373-
#elif LIBAVCODEC_VERSION_MAJOR > 53
374-
avcodec_free_frame(&frame);
375-
#else
376-
av_free(frame);
377-
#endif
378368

379369
int bitsPerByte = 8;
380370
return (gopFramesSize / _codecContext->gop_size) * bitsPerByte * getFps();
@@ -493,16 +483,10 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
493483
AVPacket pkt;
494484
av_init_packet(&pkt);
495485

496-
// Allocate frame
497-
#if LIBAVCODEC_VERSION_MAJOR > 54
498-
AVFrame* frame = av_frame_alloc();
499-
#else
500-
AVFrame* frame = avcodec_alloc_frame();
501-
#endif
502-
503486
// Initialize the AVCodecContext to use the given AVCodec
504487
avcodec_open2(_codecContext, _codec, NULL);
505488

489+
Frame frame;
506490
int count = 0;
507491
int gotFrame = 0;
508492
bool stopAnalyse = false;
@@ -511,13 +495,14 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
511495
{
512496
if(pkt.stream_index == (int)_streamIndex)
513497
{
514-
avcodec_decode_video2(_codecContext, frame, &gotFrame, &pkt);
498+
avcodec_decode_video2(_codecContext, &frame.getAVFrame(), &gotFrame, &pkt);
515499
if(gotFrame)
516500
{
501+
AVFrame& avFrame = frame.getAVFrame();
517502
_gopStructure.push_back(
518-
std::make_pair(av_get_picture_type_char(frame->pict_type), frame->key_frame));
519-
_isInterlaced = frame->interlaced_frame;
520-
_isTopFieldFirst = frame->top_field_first;
503+
std::make_pair(av_get_picture_type_char(avFrame.pict_type), avFrame.key_frame));
504+
_isInterlaced = avFrame.interlaced_frame;
505+
_isTopFieldFirst = avFrame.top_field_first;
521506
++count;
522507
if(progress.progress(count, _codecContext->gop_size) == eJobStatusCancel)
523508
stopAnalyse = true;
@@ -537,17 +522,6 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
537522

538523
// Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext itself)
539524
avcodec_close(_codecContext);
540-
541-
// Free frame
542-
#if LIBAVCODEC_VERSION_MAJOR > 54
543-
av_frame_free(&frame);
544-
#else
545-
#if LIBAVCODEC_VERSION_MAJOR > 53
546-
avcodec_free_frame(&frame);
547-
#else
548-
av_free(frame);
549-
#endif
550-
#endif
551525
}
552526
}
553527
}

0 commit comments

Comments
 (0)