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
@@ -333,11 +334,7 @@ size_t VideoProperties::getBitRate() const
333
334
// discard no frame type when decode
334
335
_codecContext->skip_frame = AVDISCARD_NONE;
335
336
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;
341
338
AVPacket pkt;
342
339
av_init_packet (&pkt);
343
340
avcodec_open2 (_codecContext, _codec, NULL );
@@ -350,11 +347,11 @@ size_t VideoProperties::getBitRate() const
350
347
{
351
348
if (pkt.stream_index == (int )_streamIndex)
352
349
{
353
- avcodec_decode_video2 (_codecContext, frame, &gotFrame, &pkt);
350
+ avcodec_decode_video2 (_codecContext, & frame. getAVFrame () , &gotFrame, &pkt);
354
351
if (gotFrame)
355
352
{
356
353
#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 () );
358
355
#else
359
356
gopFramesSize += pkt.size ;
360
357
#endif
@@ -365,13 +362,6 @@ size_t VideoProperties::getBitRate() const
365
362
if (_codecContext->gop_size == count)
366
363
break ;
367
364
}
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
375
365
376
366
int bitsPerByte = 8 ;
377
367
return (gopFramesSize / _codecContext->gop_size ) * bitsPerByte * getFps ();
@@ -490,16 +480,10 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
490
480
AVPacket pkt;
491
481
av_init_packet (&pkt);
492
482
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
-
500
483
// Initialize the AVCodecContext to use the given AVCodec
501
484
avcodec_open2 (_codecContext, _codec, NULL );
502
485
486
+ Frame frame;
503
487
int count = 0 ;
504
488
int gotFrame = 0 ;
505
489
bool stopAnalyse = false ;
@@ -508,13 +492,14 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
508
492
{
509
493
if (pkt.stream_index == (int )_streamIndex)
510
494
{
511
- avcodec_decode_video2 (_codecContext, frame, &gotFrame, &pkt);
495
+ avcodec_decode_video2 (_codecContext, & frame. getAVFrame () , &gotFrame, &pkt);
512
496
if (gotFrame)
513
497
{
498
+ AVFrame& avFrame = frame.getAVFrame ();
514
499
_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 ;
518
503
++count;
519
504
if (progress.progress (count, _codecContext->gop_size ) == eJobStatusCancel)
520
505
stopAnalyse = true ;
@@ -534,17 +519,6 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
534
519
535
520
// Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext itself)
536
521
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
548
522
}
549
523
}
550
524
}
0 commit comments