From dffb65a639ae97e5084f3cb82e0e6a3190ff4de3 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 2 Nov 2016 18:44:34 +0100 Subject: [PATCH 01/18] file: add eAnalyseLevelFull level --- src/AvTranscoder/file/util.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/file/util.hpp b/src/AvTranscoder/file/util.hpp index e01a62bc..b8b84a3b 100644 --- a/src/AvTranscoder/file/util.hpp +++ b/src/AvTranscoder/file/util.hpp @@ -11,7 +11,7 @@ enum EAnalyseLevel { eAnalyseLevelHeader = 0, eAnalyseLevelFirstGop = 1, - // eAnalyseLevelFull = 2, + eAnalyseLevelFull = 2 }; } From 525f0aa8f14384021ed78a7da42db91a5eba0d3c Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 2 Nov 2016 18:45:36 +0100 Subject: [PATCH 02/18] VideoProperties: add analyseFull private method which decodes all the stream And compute the exact number of frames. --- .../properties/VideoProperties.cpp | 38 +++++++++++++++++++ .../properties/VideoProperties.hpp | 17 +++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 32c5177c..c99742a1 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -28,6 +28,7 @@ VideoProperties::VideoProperties(const FileProperties& fileProperties, const siz , _isTopFieldFirst(false) , _gopSize(0) , _gopStructure() + , _nbFrames(0) , _firstGopTimeCode(-1) { if(_codecContext) @@ -38,6 +39,8 @@ VideoProperties::VideoProperties(const FileProperties& fileProperties, const siz if(_levelAnalysis == eAnalyseLevelFirstGop) analyseGopStructure(progress); + else if(_levelAnalysis == eAnalyseLevelFull) + analyseFull(progress); } std::string VideoProperties::getProfileName() const @@ -365,6 +368,9 @@ size_t VideoProperties::getNbFrames() const size_t nbFrames = _formatContext->streams[_streamIndex]->nb_frames; if(nbFrames == 0) { + if(_levelAnalysis == eAnalyseLevelFull) + return _nbFrames; + LOG_WARN("The number of frames in the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.") const float duration = getDuration(); @@ -554,6 +560,38 @@ void VideoProperties::analyseGopStructure(IProgress& progress) } } +void VideoProperties::analyseFull(IProgress& progress) +{ + analyseGopStructure(progress); + + if(! _formatContext || ! _codecContext || ! _codec) + return; + if(! _codecContext->width || ! _codecContext->height) + return; + + InputFile& file = const_cast(_fileProperties->getInputFile()); + // Get the stream + IInputStream& stream = file.getStream(_streamIndex); + stream.activate(); + // Create a decoder + VideoDecoder decoder(static_cast(stream)); + + VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelProperties().getAVPixelFormat())); + while(decoder.decodeNextFrame(frame)) + { + ++_nbFrames; + } + + // Returns at the beginning of the stream + file.seekAtFrame(0, AVSEEK_FLAG_BYTE); + + // Check GOP size + if(_nbFrames <= 0) + { + throw std::runtime_error("Invalid number of frames when decoding the video stream."); + } +} + PropertyVector& VideoProperties::fillVector(PropertyVector& data) const { // Add properties of base class diff --git a/src/AvTranscoder/properties/VideoProperties.hpp b/src/AvTranscoder/properties/VideoProperties.hpp index ed9d59ec..035ca9cd 100644 --- a/src/AvTranscoder/properties/VideoProperties.hpp +++ b/src/AvTranscoder/properties/VideoProperties.hpp @@ -101,11 +101,15 @@ class AvExport VideoProperties : public StreamProperties private: /** - * @brief frame type / is key frame - * @param progress: callback to get analysis progression + * @param progress: callback to get analysis progression */ void analyseGopStructure(IProgress& progress); + /** + * @param progress: callback to get analysis progression + */ + void analyseFull(IProgress& progress); + #ifndef SWIG template void addProperty(PropertyVector& dataVector, const std::string& key, T (VideoProperties::*getter)(void) const) const @@ -133,13 +137,20 @@ class AvExport VideoProperties : public StreamProperties PixelProperties _pixelProperties; //@{ - // Can acces these data when analyse first gop + // @brief Can access these data when analysing the first GOP. + // @see eAnalyseLevelFirstGOP bool _isInterlaced; bool _isTopFieldFirst; size_t _gopSize; std::vector > _gopStructure; ///< picture type, encoded frame size in bytes //@} + //@{ + // @brief Can access these data when analysing all the stream. + // @see eAnalyseLevelFull + size_t _nbFrames; + //} + /** * @brief GOP timecode of the first frame * @note AVCodecContext stores the GOP timecode of the last decoded frame From 16aafd0a54a293c2b8900d0e5085e03d1d666d7c Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 12:02:54 +0100 Subject: [PATCH 03/18] VideoProperties: fix compilation since updates of VideoFrameDesc --- src/AvTranscoder/properties/VideoProperties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index a7f78ec4..ef782dab 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -583,7 +583,7 @@ void VideoProperties::analyseFull(IProgress& progress) // Create a decoder VideoDecoder decoder(static_cast(stream)); - VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelProperties().getAVPixelFormat())); + VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelFormatName(getPixelProperties().getAVPixelFormat())), false); while(decoder.decodeNextFrame(frame)) { ++_nbFrames; From c33fb0f19754a8b2920dbfd1b2db3abca8020d35 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 16:17:28 +0100 Subject: [PATCH 04/18] VideoProperties: analyseGopStructure returns nb decoded frames --- src/AvTranscoder/properties/VideoProperties.cpp | 17 +++++++++-------- src/AvTranscoder/properties/VideoProperties.hpp | 3 ++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index ef782dab..5d747c57 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -509,12 +509,12 @@ std::vector > VideoProperties::getGopStructure() const return _gopStructure; } -void VideoProperties::analyseGopStructure(IProgress& progress) +size_t VideoProperties::analyseGopStructure(IProgress& progress) { if(! _formatContext || ! _codecContext || ! _codec) - return; + return 0; if(! _codecContext->width || ! _codecContext->height) - return; + return 0; InputFile& file = const_cast(_fileProperties->getInputFile()); // Get the stream @@ -522,11 +522,11 @@ void VideoProperties::analyseGopStructure(IProgress& progress) stream.activate(); // Create a decoder VideoDecoder decoder(static_cast(stream)); + VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelFormatName(getPixelProperties().getAVPixelFormat())), false); - size_t count = 0; + size_t nbDecodedFrames = 0; int positionOfFirstKeyFrame = -1; int positionOfLastKeyFrame = -1; - VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelFormatName(getPixelProperties().getAVPixelFormat())), false); while(decoder.decodeNextFrame(frame)) { AVFrame& avFrame = frame.getAVFrame(); @@ -538,12 +538,12 @@ void VideoProperties::analyseGopStructure(IProgress& progress) if(avFrame.pict_type == AV_PICTURE_TYPE_I) { if(positionOfFirstKeyFrame == -1) - positionOfFirstKeyFrame = count; + positionOfFirstKeyFrame = nbDecodedFrames; else - positionOfLastKeyFrame = count; + positionOfLastKeyFrame = nbDecodedFrames; } - _gopSize = ++count; + _gopSize = ++nbDecodedFrames; // If the first 2 key frames are found if(positionOfFirstKeyFrame != -1 && positionOfLastKeyFrame != -1) @@ -565,6 +565,7 @@ void VideoProperties::analyseGopStructure(IProgress& progress) { throw std::runtime_error("Invalid GOP size when decoding the first data."); } + return nbDecodedFrames; } void VideoProperties::analyseFull(IProgress& progress) diff --git a/src/AvTranscoder/properties/VideoProperties.hpp b/src/AvTranscoder/properties/VideoProperties.hpp index 9a5bab8e..d87b5716 100644 --- a/src/AvTranscoder/properties/VideoProperties.hpp +++ b/src/AvTranscoder/properties/VideoProperties.hpp @@ -105,8 +105,9 @@ class AvExport VideoProperties : public StreamProperties private: /** * @param progress: callback to get analysis progression + * @return the number of decoded frames to compute the GOP structure. */ - void analyseGopStructure(IProgress& progress); + size_t analyseGopStructure(IProgress& progress); /** * @param progress: callback to get analysis progression From ac763ff0b3131b00615c7c700088827f62210574 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 16:18:40 +0100 Subject: [PATCH 05/18] VideoProperties: fix nb decoded frames in analyseFull method Use the number of decoded frames in analyseGopStructure method. --- src/AvTranscoder/properties/VideoProperties.cpp | 15 ++++++++++----- src/AvTranscoder/properties/VideoProperties.hpp | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 5d747c57..b0d8f0fc 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -568,14 +568,17 @@ size_t VideoProperties::analyseGopStructure(IProgress& progress) return nbDecodedFrames; } -void VideoProperties::analyseFull(IProgress& progress) +size_t VideoProperties::analyseFull(IProgress& progress) { - analyseGopStructure(progress); + const size_t nbDecodedFrames = analyseGopStructure(progress); + + if(! _fileProperties->isRawFormat()) + return nbDecodedFrames; if(! _formatContext || ! _codecContext || ! _codec) - return; + return 0; if(! _codecContext->width || ! _codecContext->height) - return; + return 0; InputFile& file = const_cast(_fileProperties->getInputFile()); // Get the stream @@ -583,8 +586,9 @@ void VideoProperties::analyseFull(IProgress& progress) stream.activate(); // Create a decoder VideoDecoder decoder(static_cast(stream)); - VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelFormatName(getPixelProperties().getAVPixelFormat())), false); + + _nbFrames = nbDecodedFrames; while(decoder.decodeNextFrame(frame)) { ++_nbFrames; @@ -598,6 +602,7 @@ void VideoProperties::analyseFull(IProgress& progress) { throw std::runtime_error("Invalid number of frames when decoding the video stream."); } + return _nbFrames; } PropertyVector& VideoProperties::fillVector(PropertyVector& data) const diff --git a/src/AvTranscoder/properties/VideoProperties.hpp b/src/AvTranscoder/properties/VideoProperties.hpp index d87b5716..df7b669c 100644 --- a/src/AvTranscoder/properties/VideoProperties.hpp +++ b/src/AvTranscoder/properties/VideoProperties.hpp @@ -111,8 +111,9 @@ class AvExport VideoProperties : public StreamProperties /** * @param progress: callback to get analysis progression + * @return the number of decoded frames to parse all the file. */ - void analyseFull(IProgress& progress); + size_t analyseFull(IProgress& progress); #ifndef SWIG template From 465af95e4652477e86526e410120336c4ee68b5f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 16:19:36 +0100 Subject: [PATCH 06/18] VideoProperties: refactor seek to the beginning of the file after analysis --- .../properties/VideoProperties.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index b0d8f0fc..c3f83766 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -38,10 +38,16 @@ VideoProperties::VideoProperties(const FileProperties& fileProperties, const siz _firstGopTimeCode = _codecContext->timecode_frame_start; } - if(_levelAnalysis == eAnalyseLevelFirstGop) - analyseGopStructure(progress); - else if(_levelAnalysis == eAnalyseLevelFull) - analyseFull(progress); + if(_levelAnalysis > eAnalyseLevelHeader) + { + if(_levelAnalysis == eAnalyseLevelFirstGop) + analyseGopStructure(progress); + else if(_levelAnalysis == eAnalyseLevelFull) + analyseFull(progress); + + // Returns at the beginning of the stream + const_cast(_fileProperties->getInputFile()).seekAtFrame(0, AVSEEK_FLAG_BYTE); + } } std::string VideoProperties::getProfileName() const @@ -557,9 +563,6 @@ size_t VideoProperties::analyseGopStructure(IProgress& progress) } } - // Returns at the beginning of the stream - file.seekAtFrame(0, AVSEEK_FLAG_BYTE); - // Check GOP size if(_gopSize <= 0) { @@ -594,9 +597,6 @@ size_t VideoProperties::analyseFull(IProgress& progress) ++_nbFrames; } - // Returns at the beginning of the stream - file.seekAtFrame(0, AVSEEK_FLAG_BYTE); - // Check GOP size if(_nbFrames <= 0) { From b112ba8111b083500e41f5861b90f81908be4719 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 16:26:39 +0100 Subject: [PATCH 07/18] VideoProperties: add progress callback in analyseFull method --- src/AvTranscoder/properties/VideoProperties.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index c3f83766..f4cfce56 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -376,7 +376,7 @@ size_t VideoProperties::getNbFrames() const size_t nbFrames = _formatContext->streams[_streamIndex]->nb_frames; if(nbFrames == 0) { - if(_levelAnalysis == eAnalyseLevelFull) + if(_levelAnalysis == eAnalyseLevelFull && _nbFrames) return _nbFrames; LOG_WARN("The number of frames in the stream '" << _streamIndex << "' of file '" << _formatContext->filename @@ -591,9 +591,11 @@ size_t VideoProperties::analyseFull(IProgress& progress) VideoDecoder decoder(static_cast(stream)); VideoFrame frame(VideoFrameDesc(getWidth(), getHeight(), getPixelFormatName(getPixelProperties().getAVPixelFormat())), false); + const size_t estimateNbFrames = getNbFrames(); _nbFrames = nbDecodedFrames; while(decoder.decodeNextFrame(frame)) { + progress.progress(_nbFrames, estimateNbFrames); ++_nbFrames; } From 604d7a87c5f4b4ae041109cb9b528f0aad84afac Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 17:01:24 +0100 Subject: [PATCH 08/18] VideoProperties: update log when estimate bitrate / duration --- src/AvTranscoder/properties/VideoProperties.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index f4cfce56..9876a38b 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -338,11 +338,11 @@ size_t VideoProperties::getBitRate() const // return bit rate of stream if present or VBR mode if(_codecContext->bit_rate || _codecContext->rc_max_rate) return _codecContext->bit_rate; + LOG_WARN("The bitrate of the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.") if(_levelAnalysis == eAnalyseLevelHeader) { - LOG_WARN("The bitrate of the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown. " - "Need a deeper analysis: see eAnalyseLevelFirstGop.") + LOG_INFO("Need a deeper analysis: see eAnalyseLevelFirstGop.") return 0; } @@ -457,16 +457,14 @@ float VideoProperties::getDuration() const const float duration = StreamProperties::getDuration(); if(duration != 0) return duration; + LOG_WARN("The duration of the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.") if(_fileProperties->isRawFormat()) { - LOG_INFO("Get the stream bitrate to compute the duration.") + LOG_INFO("Estimate the duration from the file size and the bitrate.") const size_t bitRate = getBitRate(); if(bitRate) - { - LOG_INFO("Get the file size to compute the duration.") return _fileProperties->getFileSize() / bitRate * 8; - } } return 0; } From eb7442d0ba2762d6c2763df7c47e8a70f6f270bb Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 17:09:46 +0100 Subject: [PATCH 09/18] VideoProperties: refactor how to return the number of frames * Add log. * Avoid complicate if/else... --- .../properties/VideoProperties.cpp | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 9876a38b..bdd79ef8 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -373,24 +373,28 @@ size_t VideoProperties::getNbFrames() const { if(!_formatContext) throw std::runtime_error("unknown format context"); + size_t nbFrames = _formatContext->streams[_streamIndex]->nb_frames; - if(nbFrames == 0) - { - if(_levelAnalysis == eAnalyseLevelFull && _nbFrames) - return _nbFrames; + if(nbFrames) + return nbFrames; + LOG_WARN("The number of frames of the stream '" << _streamIndex << "' of file '" << _formatContext->filename + << "' is unknown.") - LOG_WARN("The number of frames in the stream '" << _streamIndex << "' of file '" << _formatContext->filename - << "' is unknown.") - const float duration = getDuration(); - if(duration != 0) + if(_levelAnalysis == eAnalyseLevelHeader) + { + LOG_INFO("Need a deeper analysis: see eAnalyseLevelFirstGop.") + return 0; + } + else + { + if(! _nbFrames) { - LOG_INFO("Try to compute the number of frames from the fps and the duration.") - nbFrames = getFps() * duration; + LOG_INFO("Estimate the number of frames from the fps and the duration.") + return getFps() * getDuration(); } - else - return 0; + LOG_INFO("Get the exact number of frames.") + return _nbFrames; } - return nbFrames; } size_t VideoProperties::getTicksPerFrame() const From b6978bc4231c4b4f275212707bfa5ca89d89a7af Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 17:15:48 +0100 Subject: [PATCH 10/18] VideoProperties: in case of full analysis get the exact duration From the number of frames and the fps. --- .../properties/VideoProperties.cpp | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index bdd79ef8..751bb5ae 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -463,14 +463,23 @@ float VideoProperties::getDuration() const return duration; LOG_WARN("The duration of the stream '" << _streamIndex << "' of file '" << _formatContext->filename << "' is unknown.") - if(_fileProperties->isRawFormat()) + if(_levelAnalysis == eAnalyseLevelHeader) { - LOG_INFO("Estimate the duration from the file size and the bitrate.") - const size_t bitRate = getBitRate(); - if(bitRate) - return _fileProperties->getFileSize() / bitRate * 8; + LOG_INFO("Need a deeper analysis: see eAnalyseLevelFirstGop.") + return 0; + } + else + { + if(! _nbFrames) + { + LOG_INFO("Estimate the duration from the file size and the bitrate.") + const size_t bitRate = getBitRate(); + if(bitRate) + return _fileProperties->getFileSize() / bitRate * 8; + } + LOG_INFO("Get the exact duration from the number of frames and the fps.") + return _nbFrames / getFps(); } - return 0; } bool VideoProperties::hasBFrames() const From b01356f96f9051194c871c947af1f2ca56418bca Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 17:17:53 +0100 Subject: [PATCH 11/18] VideoProperties: add log when no need to decode all the stream in case of full analysis --- src/AvTranscoder/properties/VideoProperties.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 751bb5ae..597d6ced 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -587,7 +587,10 @@ size_t VideoProperties::analyseFull(IProgress& progress) const size_t nbDecodedFrames = analyseGopStructure(progress); if(! _fileProperties->isRawFormat()) + { + LOG_INFO("No need to decode all the stream to get more information.") return nbDecodedFrames; + } if(! _formatContext || ! _codecContext || ! _codec) return 0; From b977583bde8f14a7f565f24ed137872464ea5a73 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 17:28:09 +0100 Subject: [PATCH 12/18] VideoProperties: fix progress of full analysis The current frame is already decoded when we call the callback. --- src/AvTranscoder/properties/VideoProperties.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 597d6ced..8264c600 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -609,8 +609,7 @@ size_t VideoProperties::analyseFull(IProgress& progress) _nbFrames = nbDecodedFrames; while(decoder.decodeNextFrame(frame)) { - progress.progress(_nbFrames, estimateNbFrames); - ++_nbFrames; + progress.progress(++_nbFrames, estimateNbFrames); } // Check GOP size From d853c8c7fee7ae119a05a4b8c62c7250e516e17a Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 17:29:10 +0100 Subject: [PATCH 13/18] pyTest: add a test to check full analysis of a raw video stream --- test/pyTest/testInputFile.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/pyTest/testInputFile.py b/test/pyTest/testInputFile.py index 822f6f1b..9fe74537 100644 --- a/test/pyTest/testInputFile.py +++ b/test/pyTest/testInputFile.py @@ -92,3 +92,31 @@ def testInputFileAnalyseFirstGop(): encodedPictureSize = image[1] assert_in(pictureType, ['I', 'P', 'B']) assert_greater(encodedPictureSize, 0) + assert_not_equals(videoProperties.getDuration(), 0) + assert_not_equals(videoProperties.getBitRate(), 0) + assert_not_equals(videoProperties.getNbFrames(), 0) + + +def testInputFileAnalyseFull(): + """ + Analyse the full video stream of an InputFile, and check if the correct attributes are filled. + """ + inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_RAW_FILE'] + inputFile = av.InputFile( inputFileName ) + + # Analyse full stream + progress = av.ConsoleProgress() + inputFile.analyse(progress, av.eAnalyseLevelFull) + + # Check properties after full analysis + videoProperties = inputFile.getProperties().getVideoProperties()[0] + assert_greater(videoProperties.getGopSize(), 0) + assert_not_equals(videoProperties.getGopStructure(), ()) + for image in videoProperties.getGopStructure(): + pictureType = image[0] + encodedPictureSize = image[1] + assert_in(pictureType, ['I', 'P', 'B']) + assert_greater(encodedPictureSize, 0) + assert_not_equals(videoProperties.getDuration(), 0) + assert_not_equals(videoProperties.getBitRate(), 0) + assert_not_equals(videoProperties.getNbFrames(), 0) From 7f1077f97149057c71743f164a6db906ff7827a4 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 21 Nov 2016 18:09:20 +0100 Subject: [PATCH 14/18] avMeta: use eAnalyseLevelFull level And show the progress. --- app/avMeta/avMeta.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/avMeta/avMeta.cpp b/app/avMeta/avMeta.cpp index 9aa326ca..b8451f9c 100644 --- a/app/avMeta/avMeta.cpp +++ b/app/avMeta/avMeta.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include @@ -43,8 +43,8 @@ int main(int argc, char** argv) // analyse inputFile avtranscoder::InputFile input(argv[1]); - avtranscoder::NoDisplayProgress p; - input.analyse(p, avtranscoder::eAnalyseLevelFirstGop); + avtranscoder::ConsoleProgress p; + input.analyse(p, avtranscoder::eAnalyseLevelFull); // display file properties if(toJson) From 84fc4bf6924318e491c88e2db34cd3284c5d4afc Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 22 Nov 2016 09:53:35 +0100 Subject: [PATCH 15/18] VideoProperties: add const to local variables of getNbFrames --- src/AvTranscoder/properties/VideoProperties.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 8264c600..dbb97b31 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -374,7 +374,7 @@ size_t VideoProperties::getNbFrames() const if(!_formatContext) throw std::runtime_error("unknown format context"); - size_t nbFrames = _formatContext->streams[_streamIndex]->nb_frames; + const size_t nbFrames = _formatContext->streams[_streamIndex]->nb_frames; if(nbFrames) return nbFrames; LOG_WARN("The number of frames of the stream '" << _streamIndex << "' of file '" << _formatContext->filename From ad44be7ec50a4f18e209c17bc13839f080864822 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 22 Nov 2016 17:35:21 +0100 Subject: [PATCH 16/18] VideoProperties: refactor how to launch deeper analysis Use a switch statement instead of several if. --- src/AvTranscoder/properties/VideoProperties.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index dbb97b31..07834d48 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -38,13 +38,20 @@ VideoProperties::VideoProperties(const FileProperties& fileProperties, const siz _firstGopTimeCode = _codecContext->timecode_frame_start; } - if(_levelAnalysis > eAnalyseLevelHeader) + switch(_levelAnalysis) { - if(_levelAnalysis == eAnalyseLevelFirstGop) + case eAnalyseLevelFirstGop: analyseGopStructure(progress); - else if(_levelAnalysis == eAnalyseLevelFull) + break; + case eAnalyseLevelFull: analyseFull(progress); + break; + default: + break; + } + if(_levelAnalysis > eAnalyseLevelHeader) + { // Returns at the beginning of the stream const_cast(_fileProperties->getInputFile()).seekAtFrame(0, AVSEEK_FLAG_BYTE); } From a61d95fb35b600373225153076da819d9d97f67f Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 22 Nov 2016 18:26:19 +0100 Subject: [PATCH 17/18] VideoProperties: refactor how to getDuration Else statement was not necessary! --- .../properties/VideoProperties.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 07834d48..f4e4924d 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -475,18 +475,16 @@ float VideoProperties::getDuration() const LOG_INFO("Need a deeper analysis: see eAnalyseLevelFirstGop.") return 0; } - else + + if(! _nbFrames) { - if(! _nbFrames) - { - LOG_INFO("Estimate the duration from the file size and the bitrate.") - const size_t bitRate = getBitRate(); - if(bitRate) - return _fileProperties->getFileSize() / bitRate * 8; - } - LOG_INFO("Get the exact duration from the number of frames and the fps.") - return _nbFrames / getFps(); + LOG_INFO("Estimate the duration from the file size and the bitrate.") + const size_t bitRate = getBitRate(); + if(bitRate) + return _fileProperties->getFileSize() / bitRate * 8; } + LOG_INFO("Get the exact duration from the number of frames and the fps.") + return _nbFrames / getFps(); } bool VideoProperties::hasBFrames() const From 0f7508fa11cdb2afe28581a3825e9c5f08780593 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 23 Nov 2016 11:10:41 +0100 Subject: [PATCH 18/18] VideoProperties: refactor how to getNbFrames Else statement was not necessary! --- src/AvTranscoder/properties/VideoProperties.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index f4e4924d..18ab1dad 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -392,16 +392,14 @@ size_t VideoProperties::getNbFrames() const LOG_INFO("Need a deeper analysis: see eAnalyseLevelFirstGop.") return 0; } - else + + if(! _nbFrames) { - if(! _nbFrames) - { - LOG_INFO("Estimate the number of frames from the fps and the duration.") - return getFps() * getDuration(); - } - LOG_INFO("Get the exact number of frames.") - return _nbFrames; + LOG_INFO("Estimate the number of frames from the fps and the duration.") + return getFps() * getDuration(); } + LOG_INFO("Get the exact number of frames.") + return _nbFrames; } size_t VideoProperties::getTicksPerFrame() const pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy