Skip to content

Added pyTests to check ProcessStat #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ AvTranscoder uses CMake as build system.

#### Dependencies
AvTranscoder can depend on ffmpeg, libav, or any fork of these projects that follow the same API.
* Recommended ffmpeg versions: 2.2.11, 2.4.2, 2.5.7
* Recommended ffmpeg versions: 2.4.2, 2.4.5, 2.5.7
* Recommended libav versions: 11.3

#### To build
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ platform:
- x86
# - x64

environment:
FFMPEG_VERSION: 2.4.5

matrix:
fast_finish: true

Expand Down
13 changes: 9 additions & 4 deletions src/AvTranscoder/file/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ namespace avtranscoder

InputFile::InputFile(const std::string& filename)
: _formatContext(filename, AV_OPT_FLAG_DECODING_PARAM)
, _properties(_formatContext)
, _properties(NULL)
, _filename(filename)
, _inputStreams()
{
// Fill the FormatContext with the stream information
_formatContext.findStreamInfo();

// Get the stream information as properties
_properties = new FileProperties(_formatContext);

// Create streams
for(size_t streamIndex = 0; streamIndex < _formatContext.getNbStreams(); ++streamIndex)
{
Expand All @@ -37,6 +41,7 @@ InputFile::InputFile(const std::string& filename)

InputFile::~InputFile()
{
delete _properties;
for(std::vector<InputStream*>::iterator it = _inputStreams.begin(); it != _inputStreams.end(); ++it)
{
delete(*it);
Expand All @@ -45,7 +50,7 @@ InputFile::~InputFile()

void InputFile::analyse(IProgress& progress, const EAnalyseLevel level)
{
_properties.extractStreamProperties(progress, level);
_properties->extractStreamProperties(progress, level);
}

FileProperties InputFile::analyseFile(const std::string& filename, IProgress& progress, const EAnalyseLevel level)
Expand Down Expand Up @@ -160,8 +165,8 @@ std::string InputFile::getFormatMimeType() const
double InputFile::getFps()
{
double fps = 1;
if(_properties.getNbVideoStreams())
fps = _properties.getVideoProperties().at(0).getFps();
if(_properties->getNbVideoStreams())
fps = _properties->getVideoProperties().at(0).getFps();
return fps;
}

Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/file/InputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AvExport InputFile
* @note require to launch analyse() before to fill the property struture
* @return structure of media metadatas
**/
const FileProperties& getProperties() const { return _properties; }
const FileProperties& getProperties() const { return *_properties; }

/**
* @brief Get stream type: video, audio, subtitle, etc.
Expand Down Expand Up @@ -121,7 +121,7 @@ class AvExport InputFile

protected:
FormatContext _formatContext;
FileProperties _properties;
FileProperties* _properties;
std::string _filename;
std::vector<InputStream*> _inputStreams; ///< Has ownership
};
Expand Down
4 changes: 4 additions & 0 deletions src/AvTranscoder/stat/AudioStat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class AvExport AudioStat
}

public:
float getDuration() const { return _duration; }
size_t getNbPackets() const { return _nbPackets; }

private:
float _duration;
size_t _nbPackets;
};
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/stat/VideoStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace avtranscoder
{

double VideoStat::psnr(const double d)
double VideoStat::toPSNR(const double mse)
{
return -10.0 * log10(d);
return -10.0 * log10(mse);
}
}
13 changes: 11 additions & 2 deletions src/AvTranscoder/stat/VideoStat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ class AvExport VideoStat
}

public:
static double psnr(const double d);
float getDuration() const { return _duration; }
size_t getNbFrames() const { return _nbFrames; }
size_t getQuality() const { return _quality; }
double getPSNR() const { return _psnr; }

public:
void setQuality(const size_t quality) { _quality = quality; }
void setPSNR(const double mse) { _psnr = VideoStat::toPSNR(mse); }

private:
static double toPSNR(const double mse);

private:
float _duration;
size_t _nbFrames;
size_t _quality; ///< Between 1 (good) and FF_LAMBDA_MAX (bad). 0 if unknown.
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/stat/stat.i
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%{
#include <AvTranscoder/stat/ProcessStat.hpp>
#include <AvTranscoder/stat/VideoStat.hpp>
#include <AvTranscoder/stat/AudioStat.hpp>
#include <AvTranscoder/stat/ProcessStat.hpp>
%}

%include <AvTranscoder/stat/ProcessStat.hpp>
%include <AvTranscoder/stat/VideoStat.hpp>
%include <AvTranscoder/stat/AudioStat.hpp>
%include <AvTranscoder/stat/ProcessStat.hpp>
6 changes: 3 additions & 3 deletions src/AvTranscoder/transcoder/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ void Transcoder::fillProcessStat(ProcessStat& processStat)
const AVCodecContext& encoderContext = encoder->getCodec().getAVCodecContext();
if(encoderContext.coded_frame && (encoderContext.flags & CODEC_FLAG_PSNR))
{
videoStat._quality = encoderContext.coded_frame->quality;
videoStat._psnr = VideoStat::psnr(encoderContext.coded_frame->error[0] /
(encoderContext.width * encoderContext.height * 255.0 * 255.0));
videoStat.setQuality(encoderContext.coded_frame->quality);
videoStat.setPSNR(encoderContext.coded_frame->error[0] /
(encoderContext.width * encoderContext.height * 255.0 * 255.0));
}
}
processStat.addVideoStat(streamIndex, videoStat);
Expand Down
42 changes: 42 additions & 0 deletions test/pyTest/testInputFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os

# Check if environment is setup to run the tests
if os.environ.get('AVTRANSCODER_TEST_VIDEO_MOV_FILE') is None:
from nose.plugins.skip import SkipTest
raise SkipTest("Need to define environment variables "
"AVTRANSCODER_TEST_VIDEO_MOV_FILE")

from nose.tools import *

from pyAvTranscoder import avtranscoder as av


@raises(IOError)
def testCreateInputFileFromUnexistingFilename():
"""
Create an InputFile from an unexisting filename.
"""
inputFileName = "testCreateInputFileFromUnexistingFilename"
av.InputFile( inputFileName )


def testInputFileAnalyseFirstGop():
"""
Analyse the first gop of an InputFile, and check if the correct attributes are filled.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
inputFile = av.InputFile( inputFileName )

# The analyse of the first GOP is not done yet
videoProperties = inputFile.getProperties().getVideoProperties()[0]
assert_equals(videoProperties.isInterlaced(), False)
assert_equals(videoProperties.isTopFieldFirst(), False)
assert_equals(videoProperties.getGopStructure(), ())

# Analyse first GOP
progress = av.NoDisplayProgress()
inputFile.analyse( progress, av.eAnalyseLevelFirstGop )

# Check properties after GOP analysis
videoProperties = inputFile.getProperties().getVideoProperties()[0]
assert_not_equals(videoProperties.getGopStructure(), ())
46 changes: 46 additions & 0 deletions test/pyTest/testProcessStat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os

# Check if environment is setup to run the tests
if os.environ.get('AVTRANSCODER_TEST_VIDEO_AVI_FILE') is None:
from nose.plugins.skip import SkipTest
raise SkipTest("Need to define environment variables "
"AVTRANSCODER_TEST_VIDEO_AVI_FILE")

from nose.tools import *

from pyAvTranscoder import avtranscoder as av


def testProcessWithStatistics():
"""
Process one video stream with a custom profile of encoding to activate statistics.
"""
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
outputFileName = "testProcessWithStatistics.mov"

ouputFile = av.OutputFile( outputFileName )
transcoder = av.Transcoder( ouputFile )

# create custom profile
customProfile = av.ProfileMap()
customProfile[av.avProfileIdentificator] = "customProfile"
customProfile[av.avProfileIdentificatorHuman] = "custom profile"
customProfile[av.avProfileType] = av.avProfileTypeVideo
customProfile[av.avProfileCodec] = "mpeg2video"
customProfile[av.avProfileProcessStat] = "processStat"

src_inputFile = av.InputFile( inputFileName )
src_properties = src_inputFile.getProperties()
src_videoStream = src_properties.getVideoProperties()[0]
videoStreamIndex = src_videoStream.getStreamIndex()
transcoder.add( inputFileName, videoStreamIndex, customProfile )

progress = av.ConsoleProgress()
processStat = transcoder.process( progress )

# check process stat returned
videoStat = processStat.getVideoStat(0)
assert_equals(videoStat.getDuration(), src_videoStream.getDuration())
assert_equals(videoStat.getNbFrames(), int(src_videoStream.getDuration() * src_videoStream.getFps()))
assert_not_equals(videoStat.getQuality(), 0)
assert_not_equals(videoStat.getPSNR(), 0)
38 changes: 26 additions & 12 deletions test/pyTest/testTranscoderRewrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def checkStream(src_stream, dst_stream):
continue
assert_equals( src_propertiesMap[key], dst_propertiesMap[key] )

def checkVideoStat(src_videoStream, dst_videoStat):
"""
Check the values of the video process stats returned after a process.
@note Because the process does not include a profile with "processStat", output quality and PSNR are not set.
"""
assert_equals(dst_videoStat.getDuration(), src_videoStream.getDuration())
assert_equals(dst_videoStat.getNbFrames(), int(src_videoStream.getDuration() * src_videoStream.getFps()))
assert_equals(dst_videoStat.getQuality(), 0)
assert_equals(dst_videoStat.getPSNR(), 0)


def testRewrapAudioStream():
"""
Expand All @@ -53,8 +63,6 @@ def testRewrapAudioStream():
# get src file of wrap
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
src_inputFile = av.InputFile( inputFileName )
progress = av.NoDisplayProgress()
src_inputFile.analyse( progress )
src_properties = src_inputFile.getProperties()
src_audioStream = src_properties.getAudioProperties()[0]

Expand All @@ -64,11 +72,15 @@ def testRewrapAudioStream():

transcoder = av.Transcoder( ouputFile )
transcoder.add( inputFileName, 0 )
transcoder.process( progress )
progress = av.NoDisplayProgress()
processStat = transcoder.process( progress )

# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())

# get dst file of wrap
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse( progress, av.eAnalyseLevelHeader )
dst_properties = dst_inputFile.getProperties()
dst_audioStream = dst_properties.getAudioProperties()[0]

Expand All @@ -86,8 +98,6 @@ def testRewrapAVIVideoStream():
# get src file of wrap
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_AVI_FILE']
src_inputFile = av.InputFile( inputFileName )
progress = av.NoDisplayProgress()
src_inputFile.analyse( progress )
src_properties = src_inputFile.getProperties()
src_videoStream = src_properties.getVideoProperties()[0]

Expand All @@ -97,11 +107,14 @@ def testRewrapAVIVideoStream():

transcoder = av.Transcoder( ouputFile )
transcoder.add( inputFileName, 0 )
transcoder.process( progress )
progress = av.NoDisplayProgress()
processStat = transcoder.process( progress )

# check process stat returned
checkVideoStat(src_videoStream, processStat.getVideoStat(0))

# get dst file of wrap
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse( progress )
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]

Expand All @@ -119,8 +132,6 @@ def testRewrapMOVVideoStream():
# get src file of wrap
inputFileName = os.environ['AVTRANSCODER_TEST_VIDEO_MOV_FILE']
src_inputFile = av.InputFile( inputFileName )
progress = av.NoDisplayProgress()
src_inputFile.analyse( progress )
src_properties = src_inputFile.getProperties()
src_videoStream = src_properties.getVideoProperties()[0]

Expand All @@ -130,11 +141,14 @@ def testRewrapMOVVideoStream():

transcoder = av.Transcoder( ouputFile )
transcoder.add( inputFileName, 1 )
transcoder.process( progress )
progress = av.NoDisplayProgress()
processStat = transcoder.process( progress )

# check process stat returned
checkVideoStat(src_videoStream, processStat.getVideoStat(0))

# get dst file of wrap
dst_inputFile = av.InputFile( outputFileName )
dst_inputFile.analyse( progress )
dst_properties = dst_inputFile.getProperties()
dst_videoStream = dst_properties.getVideoProperties()[0]

Expand Down
10 changes: 7 additions & 3 deletions test/pyTest/testTranscoderTranscodeAudioMov.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ def testTranscodeMovVariableNbSamplesPerFrame():
customProfile[av.avProfileCodec] = "pcm_s24le"

inputFile = av.InputFile( inputFileName )
audioStreamIndex = inputFile.getProperties().getAudioProperties()[0].getStreamIndex()
src_audioStream = inputFile.getProperties().getAudioProperties()[0]
audioStreamIndex = src_audioStream.getStreamIndex()
transcoder.add( inputFileName, audioStreamIndex, customProfile )

progress = av.ConsoleProgress()
transcoder.process( progress )
processStat = transcoder.process( progress )

# check process stat returned
audioStat = processStat.getAudioStat(0)
assert_equals(src_audioStream.getDuration(), audioStat.getDuration())

# get dst file of transcode
dst_inputFile = av.InputFile( outputFileName )
Expand All @@ -44,4 +49,3 @@ def testTranscodeMovVariableNbSamplesPerFrame():

assert_equals( "pcm_s24le", dst_audioStream.getCodecName() )
assert_equals( "PCM signed 24-bit little-endian", dst_audioStream.getCodecLongName() )

Loading