Skip to content

Commit 07a71ae

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 f60840e commit 07a71ae

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

@@ -333,11 +334,7 @@ size_t VideoProperties::getBitRate() const
333334
// discard no frame type when decode
334335
_codecContext->skip_frame = AVDISCARD_NONE;
335336

336-
#if LIBAVCODEC_VERSION_MAJOR > 54
337-
AVFrame* frame = av_frame_alloc();
338-
#else
339-
AVFrame* frame = avcodec_alloc_frame();
340-
#endif
337+
Frame frame;
341338
AVPacket pkt;
342339
av_init_packet(&pkt);
343340
avcodec_open2(_codecContext, _codec, NULL);
@@ -350,11 +347,11 @@ size_t VideoProperties::getBitRate() const
350347
{
351348
if(pkt.stream_index == (int)_streamIndex)
352349
{
353-
avcodec_decode_video2(_codecContext, frame, &gotFrame, &pkt);
350+
avcodec_decode_video2(_codecContext, &frame.getAVFrame(), &gotFrame, &pkt);
354351
if(gotFrame)
355352
{
356353
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(54, 7, 100)
357-
gopFramesSize += av_frame_get_pkt_size(frame);
354+
gopFramesSize += av_frame_get_pkt_size(&frame.getAVFrame());
358355
#else
359356
gopFramesSize += pkt.size;
360357
#endif
@@ -365,13 +362,6 @@ size_t VideoProperties::getBitRate() const
365362
if(_codecContext->gop_size == count)
366363
break;
367364
}
368-
#if LIBAVCODEC_VERSION_MAJOR > 54
369-
av_frame_free(&frame);
370-
#elif LIBAVCODEC_VERSION_MAJOR > 53
371-
avcodec_free_frame(&frame);
372-
#else
373-
av_free(frame);
374-
#endif
375365

376366
int bitsPerByte = 8;
377367
return (gopFramesSize / _codecContext->gop_size) * bitsPerByte * getFps();
@@ -490,16 +480,10 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
490480
AVPacket pkt;
491481
av_init_packet(&pkt);
492482

493-
// Allocate frame
494-
#if LIBAVCODEC_VERSION_MAJOR > 54
495-
AVFrame* frame = av_frame_alloc();
496-
#else
497-
AVFrame* frame = avcodec_alloc_frame();
498-
#endif
499-
500483
// Initialize the AVCodecContext to use the given AVCodec
501484
avcodec_open2(_codecContext, _codec, NULL);
502485

486+
Frame frame;
503487
int count = 0;
504488
int gotFrame = 0;
505489
bool stopAnalyse = false;
@@ -508,13 +492,14 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
508492
{
509493
if(pkt.stream_index == (int)_streamIndex)
510494
{
511-
avcodec_decode_video2(_codecContext, frame, &gotFrame, &pkt);
495+
avcodec_decode_video2(_codecContext, &frame.getAVFrame(), &gotFrame, &pkt);
512496
if(gotFrame)
513497
{
498+
AVFrame& avFrame = frame.getAVFrame();
514499
_gopStructure.push_back(
515-
std::make_pair(av_get_picture_type_char(frame->pict_type), frame->key_frame));
516-
_isInterlaced = frame->interlaced_frame;
517-
_isTopFieldFirst = frame->top_field_first;
500+
std::make_pair(av_get_picture_type_char(avFrame.pict_type), avFrame.key_frame));
501+
_isInterlaced = avFrame.interlaced_frame;
502+
_isTopFieldFirst = avFrame.top_field_first;
518503
++count;
519504
if(progress.progress(count, _codecContext->gop_size) == eJobStatusCancel)
520505
stopAnalyse = true;
@@ -534,17 +519,6 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
534519

535520
// Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext itself)
536521
avcodec_close(_codecContext);
537-
538-
// Free frame
539-
#if LIBAVCODEC_VERSION_MAJOR > 54
540-
av_frame_free(&frame);
541-
#else
542-
#if LIBAVCODEC_VERSION_MAJOR > 53
543-
avcodec_free_frame(&frame);
544-
#else
545-
av_free(frame);
546-
#endif
547-
#endif
548522
}
549523
}
550524
}

0 commit comments

Comments
 (0)