1
1
#include " VideoProperties.hpp"
2
2
3
- #include < AvTranscoder/data/decoded/Frame.hpp>
3
+ #include < AvTranscoder/decoder/VideoDecoder.hpp>
4
+ #include < AvTranscoder/data/decoded/VideoFrame.hpp>
4
5
#include < AvTranscoder/properties/util.hpp>
5
6
#include < AvTranscoder/properties/FileProperties.hpp>
6
7
#include < AvTranscoder/progress/NoDisplayProgress.hpp>
@@ -502,46 +503,36 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
502
503
if (! _codecContext->width || ! _codecContext->height )
503
504
return ;
504
505
506
+ InputFile& file = const_cast <InputFile&>(_fileProperties->getInputFile ());
507
+ // Get the stream
508
+ IInputStream& stream = file.getStream (_streamIndex);
509
+ stream.activate ();
510
+ // Setup a decoder
511
+ VideoDecoder decoder (static_cast <InputStream&>(stream));
505
512
// Discard no frame type when decode
506
513
_codecContext->skip_frame = AVDISCARD_NONE;
507
514
508
- AVPacket pkt;
509
- av_init_packet (&pkt);
510
-
511
- // Initialize the AVCodecContext to use the given AVCodec
512
- avcodec_open2 (_codecContext, _codec, NULL );
513
-
514
- Frame frame;
515
515
size_t count = 0 ;
516
- int gotFrame = 0 ;
517
516
int positionOfFirstKeyFrame = -1 ;
518
517
int positionOfLastKeyFrame = -1 ;
519
-
520
- while (! av_read_frame ( const_cast <AVFormatContext*>(_formatContext), &pkt ))
518
+ VideoFrame frame ( VideoFrameDesc ( getWidth (), getHeight (), getPixelProperties (). getAVPixelFormat ()));
519
+ while (decoder. decodeNextFrame (frame ))
521
520
{
522
- if (pkt.stream_index == (int )_streamIndex)
521
+ AVFrame& avFrame = frame.getAVFrame ();
522
+
523
+ _gopStructure.push_back (
524
+ std::make_pair (av_get_picture_type_char (avFrame.pict_type ), frame.getEncodedSize ()));
525
+ _isInterlaced = avFrame.interlaced_frame ;
526
+ _isTopFieldFirst = avFrame.top_field_first ;
527
+ if (avFrame.pict_type == AV_PICTURE_TYPE_I)
523
528
{
524
- avcodec_decode_video2 (_codecContext, &frame.getAVFrame (), &gotFrame, &pkt);
525
- if (gotFrame)
526
- {
527
- AVFrame& avFrame = frame.getAVFrame ();
528
-
529
- _gopStructure.push_back (
530
- std::make_pair (av_get_picture_type_char (avFrame.pict_type ), frame.getEncodedSize ()));
531
- _isInterlaced = avFrame.interlaced_frame ;
532
- _isTopFieldFirst = avFrame.top_field_first ;
533
- if (avFrame.pict_type == AV_PICTURE_TYPE_I)
534
- {
535
- if (positionOfFirstKeyFrame == -1 )
536
- positionOfFirstKeyFrame = count;
537
- else
538
- positionOfLastKeyFrame = count;
539
- }
540
-
541
- _gopSize = ++count;
542
- }
529
+ if (positionOfFirstKeyFrame == -1 )
530
+ positionOfFirstKeyFrame = count;
531
+ else
532
+ positionOfLastKeyFrame = count;
543
533
}
544
- av_free_packet (&pkt);
534
+
535
+ _gopSize = ++count;
545
536
546
537
// If the first 2 key frames are found
547
538
if (positionOfFirstKeyFrame != -1 && positionOfLastKeyFrame != -1 )
@@ -555,11 +546,8 @@ void VideoProperties::analyseGopStructure(IProgress& progress)
555
546
}
556
547
}
557
548
558
- // Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext itself)
559
- avcodec_close (_codecContext);
560
-
561
549
// Returns at the beginning of the stream
562
- const_cast <InputFile&>(_fileProperties-> getInputFile ()) .seekAtFrame (0 , AVSEEK_FLAG_BYTE);
550
+ file .seekAtFrame (0 , AVSEEK_FLAG_BYTE);
563
551
564
552
// Check GOP size
565
553
if (_gopSize <= 0 )
0 commit comments