1
1
#include " VideoProperties.hpp"
2
2
3
+ #include < AvTranscoder/data/decoded/Frame.hpp>
3
4
#include < AvTranscoder/properties/util.hpp>
4
5
#include < AvTranscoder/progress/NoDisplayProgress.hpp>
5
6
@@ -336,11 +337,7 @@ size_t VideoProperties::getBitRate() const
336
337
// discard no frame type when decode
337
338
_codecContext->skip_frame = AVDISCARD_NONE;
338
339
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;
344
341
AVPacket pkt;
345
342
av_init_packet (&pkt);
346
343
avcodec_open2 (_codecContext, _codec, NULL );
@@ -353,11 +350,11 @@ size_t VideoProperties::getBitRate() const
353
350
{
354
351
if (pkt.stream_index == (int )_streamIndex)
355
352
{
356
- avcodec_decode_video2 (_codecContext, frame, &gotFrame, &pkt);
353
+ avcodec_decode_video2 (_codecContext, & frame. getAVFrame () , &gotFrame, &pkt);
357
354
if (gotFrame)
358
355
{
359
356
#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 () );
361
358
#else
362
359
gopFramesSize += pkt.size ;
363
360
#endif
@@ -368,13 +365,6 @@ size_t VideoProperties::getBitRate() const
368
365
if (_codecContext->gop_size == count)
369
366
break ;
370
367
}
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
378
368
379
369
int bitsPerByte = 8 ;
380
370
return (gopFramesSize / _codecContext->gop_size ) * bitsPerByte * getFps ();
@@ -493,16 +483,10 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
493
483
AVPacket pkt;
494
484
av_init_packet (&pkt);
495
485
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
-
503
486
// Initialize the AVCodecContext to use the given AVCodec
504
487
avcodec_open2 (_codecContext, _codec, NULL );
505
488
489
+ Frame frame;
506
490
int count = 0 ;
507
491
int gotFrame = 0 ;
508
492
bool stopAnalyse = false ;
@@ -511,13 +495,14 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
511
495
{
512
496
if (pkt.stream_index == (int )_streamIndex)
513
497
{
514
- avcodec_decode_video2 (_codecContext, frame, &gotFrame, &pkt);
498
+ avcodec_decode_video2 (_codecContext, & frame. getAVFrame () , &gotFrame, &pkt);
515
499
if (gotFrame)
516
500
{
501
+ AVFrame& avFrame = frame.getAVFrame ();
517
502
_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 ;
521
506
++count;
522
507
if (progress.progress (count, _codecContext->gop_size ) == eJobStatusCancel)
523
508
stopAnalyse = true ;
@@ -537,17 +522,6 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
537
522
538
523
// Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext itself)
539
524
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
551
525
}
552
526
}
553
527
}
0 commit comments