Skip to content

Fix thumbnail of image #232

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 8 commits into from
Mar 1, 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 app/pyRewrap/pyrewrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
exit(1)

# setup avtranscoder
logger = av.Logger().setLogLevel(av.AV_LOG_QUIET)
av.Logger().setLogLevel(av.AV_LOG_QUIET)
av.preloadCodecsAndFormats()

# create input file
Expand Down
12 changes: 6 additions & 6 deletions app/pyThumbnail/pythumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@


# setup avtranscoder
logger = av.Logger().setLogLevel(av.AV_LOG_QUIET)
av.Logger().setLogLevel(av.AV_LOG_QUIET)
av.preloadCodecsAndFormats()

# create input file
Expand Down Expand Up @@ -97,10 +97,10 @@

# create transcoder
transcoder = av.Transcoder( outputFile )
transcoder.add( outputStream );
transcoder.add( outputStream )

# launch process
outputFile.beginWrap();
transcoder.preProcessCodecLatency();
transcoder.processFrame();
outputFile.endWrap();
outputFile.beginWrap()
transcoder.preProcessCodecLatency()
transcoder.processFrame()
outputFile.endWrap()
4 changes: 3 additions & 1 deletion src/AvTranscoder/decoder/AudioDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ bool AudioDecoder::decodeNextFrame(Frame& frameBuffer)

const bool nextPacketRead = _inputStream->readNextPacket(data);
// if error or end of file
if(!nextPacketRead)
if(!nextPacketRead && !decodeNextFrame)
{
data.clear();
return false;
}

// decoding
// @note could be called several times to return the remaining frames (last call with an empty packet)
// @see CODEC_CAP_DELAY
int ret = avcodec_decode_audio4(&_inputStream->getAudioCodec().getAVCodecContext(), &frameBuffer.getAVFrame(),
&got_frame, &data.getAVPacket());
if(ret < 0)
Expand Down
4 changes: 3 additions & 1 deletion src/AvTranscoder/decoder/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ bool VideoDecoder::decodeNextFrame(Frame& frameBuffer)

const bool nextPacketRead = _inputStream->readNextPacket(data);
// if error or end of file
if(!nextPacketRead)
if(!nextPacketRead && !decodeNextFrame)
{
data.clear();
return false;
}

// decoding
// @note could be called several times to return the remaining frames (last call with an empty packet)
// @see CODEC_CAP_DELAY
const int ret = avcodec_decode_video2(&_inputStream->getVideoCodec().getAVCodecContext(), &frameBuffer.getAVFrame(),
&got_frame, &data.getAVPacket());
if(ret < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/file/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool InputFile::readNextPacket(CodedData& data, const size_t streamIndex)
const int packetStreamIndex = data.getAVPacket().stream_index;
if(packetStreamIndex == (int)streamIndex)
{
LOG_DEBUG("Get a packet data of the stream " << streamIndex)
LOG_DEBUG("Get a packet from stream " << streamIndex)
nextPacketFound = true;
}
// else add the packet data to the stream cache
Expand Down
26 changes: 26 additions & 0 deletions src/AvTranscoder/properties/util.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "util.hpp"

extern "C" {
#include <libavutil/avutil.h>
}

#include <sstream>

namespace avtranscoder
Expand All @@ -8,6 +12,28 @@ namespace avtranscoder
namespace detail
{

template <>
void add(PropertyVector& propertyVector, const std::string& key, const size_t& value)
{
std::stringstream ss;
if(value == (size_t)AV_NOPTS_VALUE)
ss << "N/A";
else
ss << value;
add(propertyVector, key, ss.str());
}

template <>
void add(PropertyVector& propertyVector, const std::string& key, const float& value)
{
std::stringstream ss;
if(value <= AV_NOPTS_VALUE || value >= AV_NOPTS_VALUE)
ss << "N/A";
else
ss << value;
add(propertyVector, key, ss.str());
}

template <>
void add(PropertyVector& propertyVector, const std::string& key, const std::string& value)
{
Expand Down
6 changes: 6 additions & 0 deletions src/AvTranscoder/properties/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ void add(PropertyVector& propertyVector, const std::string& key, const T& value)
add(propertyVector, key, ss.str());
}

template <>
void add(PropertyVector& propertyVector, const std::string& key, const size_t& value);

template <>
void add(PropertyVector& propertyVector, const std::string& key, const float& value);

template <>
void add(PropertyVector& propertyVector, const std::string& key, const std::string& value);

Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/stream/InputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ bool InputStream::readNextPacket(CodedData& data)
// if packet is already cached
if(!_streamCache.empty())
{
LOG_DEBUG("Get packet data of stream " << _streamIndex << " from the cache")
LOG_DEBUG("Get packet of '" << _inputFile->getFilename() << "' (stream " << _streamIndex << ") from the cache")
data.copyData(_streamCache.front().getData(), _streamCache.front().getSize());
_streamCache.pop();
}
// else read next packet
else
{
LOG_DEBUG("Read next packet")
LOG_DEBUG("Read next packet of '" << _inputFile->getFilename() << "' (stream " << _streamIndex << ")")
return _inputFile->readNextPacket(data, _streamIndex) && _streamCache.empty();
}

Expand Down
8 changes: 4 additions & 4 deletions src/AvTranscoder/transcoder/Transcoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ ProcessStat Transcoder::process(IProgress& progress)
bool frameProcessed = true;
while(frameProcessed)
{
LOG_DEBUG("Process frame " << frame)
frameProcessed = processFrame();
++frame;

const float progressDuration = getCurrentOutputDuration();

// check if JobStatusCancel
Expand All @@ -306,10 +310,6 @@ ProcessStat Transcoder::process(IProgress& progress)
<< progressDuration << "s) is equal or upper than " << expectedOutputDuration << "s.")
break;
}

LOG_DEBUG("Process frame " << frame)
frameProcessed = processFrame();
++frame;
}

_outputFile.endWrap();
Expand Down
75 changes: 75 additions & 0 deletions test/pyTest/testTranscoderTranscodeImage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import os

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

from nose.tools import *

from pyAvTranscoder import avtranscoder as av


def testTranscodePngToMjpeg():
"""
Transcode one image (to mjpeg).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_IMAGE_PNG_FILE']
outputFileName = "testTranscodePngToMjpeg.jpg"

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

inputFile = av.InputFile( inputFileName )
src_videoStream = inputFile.getProperties().getVideoProperties()[0]
videoStreamIndex = src_videoStream.getStreamIndex()
transcoder.add( inputFileName, videoStreamIndex, "mjpeg" )

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

# check process stat returned
videoStat = processStat.getVideoStat(0)
assert_equals(1, videoStat.getNbFrames())

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

assert_equals( "mjpeg", dst_videoStream.getCodecName() )
assert_equals( "yuvj420p", dst_videoStream.getPixelProperties().getPixelName() )


def testTranscodeJpgToMjpeg():
"""
Transcode one image (to mjpeg).
"""
inputFileName = os.environ['AVTRANSCODER_TEST_IMAGE_JPG_FILE']
outputFileName = "testTranscodeJpgToMjpeg.jpg"

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

inputFile = av.InputFile( inputFileName )
src_videoStream = inputFile.getProperties().getVideoProperties()[0]
videoStreamIndex = src_videoStream.getStreamIndex()
transcoder.add( inputFileName, videoStreamIndex, "mjpeg" )

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

# check process stat returned
videoStat = processStat.getVideoStat(0)
assert_equals(1, videoStat.getNbFrames())

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

assert_equals( "mjpeg", dst_videoStream.getCodecName() )
assert_equals( "yuvj420p", dst_videoStream.getPixelProperties().getPixelName() )
2 changes: 2 additions & 0 deletions tools/appveyor/python.nosetests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ set AVTRANSCODER_TEST_VIDEO_MP4_FILE=%PWD%\avTranscoder-data\video\BigBuckBunny\
set AVTRANSCODER_TEST_VIDEO_MOV_FILE=%PWD%\avTranscoder-data\video\BigBuckBunny\BigBuckBunny_640p_h264.mov
set AVTRANSCODER_TEST_AUDIO_WAVE_FILE=%PWD%\avTranscoder-data\audio\frequenciesPerChannel.wav
set AVTRANSCODER_TEST_AUDIO_MOV_FILE=%PWD%\avTranscoder-data\video\BigBuckBunny\BigBuckBunny_1080p_5_1.mov
set AVTRANSCODER_TEST_IMAGE_PNG_FILE=%PWD%\avTranscoder-data\image\BigBuckBunny\bbb-splash.thumbnail.png
set AVTRANSCODER_TEST_IMAGE_JPG_FILE=%PWD%\avTranscoder-data\image\BigBuckBunny\title_anouncement.thumbnail.jpg

:: Launch tests
cd test\pyTest
Expand Down
2 changes: 2 additions & 0 deletions tools/travis/python.nosetests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export AVTRANSCODER_TEST_VIDEO_MP4_FILE=`pwd`/avTranscoder-data/video/BigBuckBun
export AVTRANSCODER_TEST_VIDEO_MOV_FILE=`pwd`/avTranscoder-data/video/BigBuckBunny/BigBuckBunny_640p_h264.mov
export AVTRANSCODER_TEST_AUDIO_WAVE_FILE=`pwd`/avTranscoder-data/audio/frequenciesPerChannel.wav
export AVTRANSCODER_TEST_AUDIO_MOV_FILE=`pwd`/avTranscoder-data/video/BigBuckBunny/BigBuckBunny_1080p_5_1.mov
export AVTRANSCODER_TEST_IMAGE_PNG_FILE=`pwd`/avTranscoder-data/image/BigBuckBunny/bbb-splash.thumbnail.png
export AVTRANSCODER_TEST_IMAGE_JPG_FILE=`pwd`/avTranscoder-data/image/BigBuckBunny/title_anouncement.thumbnail.jpg

# Launch tests
nosetests ${TRAVIS_BUILD_DIR}/test/pyTest --with-coverage