Skip to content

Pull develop branch of MIK fork #146

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 37 commits into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b428c88
OutputFile: fix AVCodecContext of stream when addAudioStream
Oct 9, 2015
08e7575
Merge pull request #250 from cchampet/fix_outputFileRewrapAudio
cchampet Oct 12, 2015
97207e0
CMake: get AvTranscoder versions from headers
Oct 12, 2015
b4129f8
CMake: clean
Oct 12, 2015
89dd123
CMake: print info to check AvTranscoder version
Oct 12, 2015
a7d54b5
Merge pull request #251 from cchampet/cmake_defineVersionInCode
cchampet Oct 12, 2015
11af7c1
Up to v0.5.11
Oct 12, 2015
d4f2d8f
OutputFile: copy channel_layout for each audio stream added
Oct 19, 2015
2d06c07
pyTest: check channel_layout when rewrap an audio stream
Oct 19, 2015
e947d9e
pyTest: check video bitrate when transcode to dnxhd
Oct 19, 2015
15c22fd
pyTest: check bitrate with a relative delta when rewrap
Oct 19, 2015
e71368c
pyTest: do not check channel_layout when transcode audio
Oct 19, 2015
68ee58c
Merge pull request #254 from cchampet/fix_OuputFileAddAudioStreamChan…
valnoel Oct 19, 2015
7ad91b9
Up to v0.5.12
Oct 19, 2015
b59b050
log: add private attribute to set header of logs only once
Oct 20, 2015
e9dbd42
Merge pull request #256 from cchampet/dev_optimizationLog
valnoel Oct 20, 2015
2298b62
InputStream: move doc to based class
Oct 29, 2015
87c29ab
IOuputFile: clean doc
Oct 29, 2015
88af4f6
InputStream: add getProperties method
Oct 29, 2015
7341a7a
StreamProperties: add getStreamType method
Oct 29, 2015
10b5a09
IInputStream: remove getStreamType
Oct 29, 2015
447392a
IInputStream: remove getDuration
Oct 29, 2015
e41021a
IInputStream: add doc
Oct 29, 2015
cf8619f
OuputFile: rename streamId argument to streamIndex
Oct 29, 2015
38b5d8b
IOutputStream: add doc to wrap method
Oct 29, 2015
5adc732
IInputStream: move doc of buffering methods to based class
Oct 29, 2015
5c7573e
StreamProperties: getAVFormatContext is a const method
Oct 29, 2015
f757baf
Merge pull request #260 from cchampet/dev_InputStreamGetProperties
valnoel Nov 2, 2015
da40efd
FormatContext: log info when seek
Nov 4, 2015
8e5671e
encoders/decoders: do not log empty profile when setup
Nov 4, 2015
3e8472b
wrap/unwrap: do not log empty profile when setup
Nov 4, 2015
bd41951
IReader: added assert to check not NULL
Nov 4, 2015
9b78c0e
FormatContext: do not add stream start time before each seek
Nov 4, 2015
384841b
pyTest offset: check output nbSamples/nbFrames when rewrap
Nov 4, 2015
e4aa404
pyTest offset: check duration of all stream when testMultipleOffsetFr…
Nov 4, 2015
6331f3c
pyTest offset: add testMultipleOffsetFromSameStream
Nov 4, 2015
c391609
Merge pull request #263 from cchampet/fix_negativeOffset
valnoel Nov 5, 2015
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
13 changes: 2 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ cmake_minimum_required(VERSION 2.8.11)

project(AvTranscoder)

# Set AvTranscoder versions
set(AVTRANSCODER_VERSION_MAJOR "0")
set(AVTRANSCODER_VERSION_MINOR "5")
set(AVTRANSCODER_VERSION_MICRO "10")
set(AVTRANSCODER_VERSION ${AVTRANSCODER_VERSION_MAJOR}.${AVTRANSCODER_VERSION_MINOR}.${AVTRANSCODER_VERSION_MICRO})

# Define AvTranscoder versions
add_definitions(-DAVTRANSCODER_VERSION_MAJOR=${AVTRANSCODER_VERSION_MAJOR})
add_definitions(-DAVTRANSCODER_VERSION_MINOR=${AVTRANSCODER_VERSION_MINOR})
add_definitions(-DAVTRANSCODER_VERSION_MICRO=${AVTRANSCODER_VERSION_MICRO})

# Define AvTranscoder default path to profiles
add_definitions(-DAVTRANSCODER_DEFAULT_AVPROFILES="${CMAKE_INSTALL_PREFIX}/share/avprofiles")

Expand All @@ -37,8 +26,10 @@ if(AVTRANSCODER_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif()

# Build library
add_subdirectory(src)

# Build apps
if(AVTRANSCODER_DISABLE_APPS)
message("Apps disabled, will not build applications.")
else()
Expand Down
21 changes: 21 additions & 0 deletions cmake/AvTranscoderMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,24 @@
set(AVTRANSCODER_APP_PATH "${PROJECT_SOURCE_DIR}/app")
set(AVTRANSCODER_SRC_PATH "${PROJECT_SOURCE_DIR}/src")
file(GLOB_RECURSE AVTRANSCODER_SRC_FILES "AvTranscoder/*.cpp" "AvTranscoder/*.hpp")

# Get AvTranscoder versions
# AVTRANSCODER_VERSION_MAJOR
# AVTRANSCODER_VERSION_MINOR
# AVTRANSCODER_VERSION_MICRO
# AVTRANSCODER_VERSION
file(STRINGS "${AVTRANSCODER_SRC_PATH}/AvTranscoder/common.hpp" _avtranscoder_VERSION_HPP_CONTENTS REGEX "#define AVTRANSCODER_VERSION_")
foreach(v MAJOR MINOR MICRO)
if("${_avtranscoder_VERSION_HPP_CONTENTS}" MATCHES "#define AVTRANSCODER_VERSION_${v} ([0-9]+)")
set(AVTRANSCODER_VERSION_${v} "${CMAKE_MATCH_1}")
else()
set(AVTRANSCODER_RETRIEVE_VERSION_FAILED 1)
endif()
endforeach()
unset(_avtranscoder_VERSION_HPP_CONTENTS)

set(AVTRANSCODER_VERSION "${AVTRANSCODER_VERSION_MAJOR}.${AVTRANSCODER_VERSION_MINOR}.${AVTRANSCODER_VERSION_MICRO}")

if(AVTRANSCODER_RETRIEVE_VERSION_FAILED)
message(SEND_ERROR "Failed to retrieve AvTranscoder version: ${AVTRANSCODER_VERSION}")
endif()
4 changes: 4 additions & 0 deletions src/AvTranscoder/common.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef _AV_TRANSCODER_COMMON_HPP_
#define _AV_TRANSCODER_COMMON_HPP_

#define AVTRANSCODER_VERSION_MAJOR 0
#define AVTRANSCODER_VERSION_MINOR 5
#define AVTRANSCODER_VERSION_MICRO 12

#include <AvTranscoder/system.hpp>

extern "C" {
Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/decoder/AudioDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ void AudioDecoder::setupDecoder( const ProfileLoader::Profile& profile )
throw std::runtime_error( msg );
}

LOG_INFO( "Setup audio decoder with:\n" << profile )
if( ! profile.empty() )
{
LOG_INFO( "Setup audio decoder with:\n" << profile )
}

AudioCodec& codec = _inputStream->getAudioCodec();

Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/decoder/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ void VideoDecoder::setupDecoder( const ProfileLoader::Profile& profile )
throw std::runtime_error( msg );
}

LOG_INFO( "Setup video decoder with:\n" << profile )
if( ! profile.empty() )
{
LOG_INFO( "Setup video decoder with:\n" << profile )
}

VideoCodec& codec = _inputStream->getVideoCodec();

Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/encoder/AudioEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ AudioEncoder::~AudioEncoder()

void AudioEncoder::setupAudioEncoder( const AudioFrameDesc& frameDesc, const ProfileLoader::Profile& profile )
{
LOG_INFO( "Setup audio encoder with:\n" << profile )
if( ! profile.empty() )
{
LOG_INFO( "Setup audio encoder with:\n" << profile )
}

// set sampleRate, number of channels, sample format
_codec.setAudioParameters( frameDesc );
Expand Down
5 changes: 4 additions & 1 deletion src/AvTranscoder/encoder/VideoEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ VideoEncoder::~VideoEncoder()

void VideoEncoder::setupVideoEncoder( const VideoFrameDesc& frameDesc, const ProfileLoader::Profile& profile )
{
LOG_INFO( "Setup video encoder with:\n" << profile )
if( ! profile.empty() )
{
LOG_INFO( "Setup video encoder with:\n" << profile )
}

// set width, height, pixel format, fps
_codec.setImageParameters( frameDesc );
Expand Down
6 changes: 2 additions & 4 deletions src/AvTranscoder/file/FormatContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,9 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec )
return *stream;
}

bool FormatContext::seek( uint64_t position, const int flag )
bool FormatContext::seek( const uint64_t position, const int flag )
{
if( (int)getStartTime() != AV_NOPTS_VALUE )
position += getStartTime();

LOG_INFO( "Seek in '" << _avFormatContext->filename << "' at " << position << " (in AV_TIME_BASE units)" )
int err = av_seek_frame( _avFormatContext, -1, position, flag );
if( err < 0 )
{
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/file/FormatContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class AvExport FormatContext
* @brief Seek at a specific position
* @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value
* @param flag: seeking mode (AVSEEK_FLAG_xxx)
* @note before seek, add offset of start time
* @return seek status
* @see flushDecoder
*/
bool seek( uint64_t position, const int flag );
bool seek( const uint64_t position, const int flag );

size_t getNbStreams() const { return _avFormatContext->nb_streams; }
/// Get duration of the program, in seconds
Expand Down
9 changes: 4 additions & 5 deletions src/AvTranscoder/file/IOutputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AvExport IOutputFile

/**
* @brief Add a video output stream
* @note call setup() before adding any stream
* @param videoCodec description of output stream
**/
virtual IOutputStream& addVideoStream( const VideoCodec& videoCodec )
Expand All @@ -36,7 +35,6 @@ class AvExport IOutputFile

/**
* @brief Add an audio output stream
* @note call setup() before adding any stream
* @param audioCodec description of output stream
**/
virtual IOutputStream& addAudioStream( const AudioCodec& audioCodec )
Expand All @@ -46,7 +44,6 @@ class AvExport IOutputFile

/**
* @brief Add a data output stream
* @note call setup() before adding any stream
* @param dataCodec description of output stream
**/
virtual IOutputStream& addDataStream( const DataCodec& dataCodec )
Expand All @@ -62,7 +59,9 @@ class AvExport IOutputFile
/**
* @brief Wrap a packet of data in the output ressource
* @param data coded packet information for the current stream
* @param streamId refers to the stream in output ressource
* @param streamIndex refers to the stream in output ressource
* @return the wrapping status after wrapping
* @see EWrappingStatus
**/
virtual IOutputStream::EWrappingStatus wrap( const CodedData& data, const size_t streamIndex ) = 0;

Expand All @@ -73,7 +72,7 @@ class AvExport IOutputFile

/**
* @brief Get the output stream
* @param streamId select the output stream
* @param streamIndex select the output stream
* @return the output stream reference
**/
virtual IOutputStream& getStream( const size_t streamIndex ) = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/AvTranscoder/file/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ void InputFile::setupUnwrapping( const ProfileLoader::Profile& profile )
throw std::runtime_error( msg );
}

// set profile
LOG_INFO( "Setup unwrapping with:\n" << profile )
if( ! profile.empty() )
{
LOG_INFO( "Setup unwrapping with:\n" << profile )
}

for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
Expand Down
23 changes: 14 additions & 9 deletions src/AvTranscoder/file/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ IOutputStream& OutputFile::addAudioStream( const AudioCodec& audioDesc )

stream.codec->sample_rate = audioDesc.getAVCodecContext().sample_rate;
stream.codec->channels = audioDesc.getAVCodecContext().channels;
stream.codec->channel_layout = audioDesc.getAVCodecContext().channel_layout;
stream.codec->sample_fmt = audioDesc.getAVCodecContext().sample_fmt;
stream.codec->frame_size = audioDesc.getAVCodecContext().frame_size;

// need to set the time_base on the AVCodecContext of the AVStream
av_reduce(
Expand All @@ -99,11 +101,11 @@ IOutputStream& OutputFile::addDataStream( const DataCodec& dataDesc )
return *outputStream;
}

IOutputStream& OutputFile::getStream( const size_t streamId )
IOutputStream& OutputFile::getStream( const size_t streamIndex )
{
if( streamId >= _outputStreams.size() )
if( streamIndex >= _outputStreams.size() )
throw std::runtime_error( "unable to get output stream (out of range)" );
return *_outputStreams.at( streamId );
return *_outputStreams.at( streamIndex );
}

std::string OutputFile::getFilename() const
Expand Down Expand Up @@ -157,16 +159,16 @@ bool OutputFile::beginWrap( )
return true;
}

IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const size_t streamId )
IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const size_t streamIndex )
{
if( ! data.getSize() )
return IOutputStream::eWrappingSuccess;

LOG_DEBUG( "Wrap on stream " << streamId << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamId ) << ")" )
LOG_DEBUG( "Wrap on stream " << streamIndex << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamIndex ) << ")" )

AVPacket packet;
av_init_packet( &packet );
packet.stream_index = streamId;
packet.stream_index = streamIndex;
packet.data = (uint8_t*)data.getData();
packet.size = data.getSize();

Expand All @@ -175,15 +177,15 @@ IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const si
// free packet.side_data, set packet.data to NULL and packet.size to 0
av_free_packet( &packet );

const double currentStreamDuration = _outputStreams.at( streamId )->getStreamDuration();
const double currentStreamDuration = _outputStreams.at( streamIndex )->getStreamDuration();
if( currentStreamDuration < _previousProcessedStreamDuration )
{
// if the current stream is strictly shorter than the previous, wait for more data
return IOutputStream::eWrappingWaitingForData;
}

_previousProcessedStreamDuration = currentStreamDuration;
_frameCount.at( streamId )++;
_frameCount.at( streamIndex )++;

return IOutputStream::eWrappingSuccess;
}
Expand Down Expand Up @@ -221,7 +223,10 @@ void OutputFile::setupWrapping( const ProfileLoader::Profile& profile )
throw std::runtime_error( msg );
}

LOG_INFO( "Setup wrapping with:\n" << profile )
if( ! profile.empty() )
{
LOG_INFO( "Setup wrapping with:\n" << profile )
}

// check if output format indicated is valid with the filename extension
if( ! matchFormat( profile.find( constants::avProfileFormat )->second, getFilename() ) )
Expand Down
6 changes: 3 additions & 3 deletions src/AvTranscoder/file/OutputFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class AvExport OutputFile : public IOutputFile
* @brief Open ressource, write header, and setup specific wrapping options given when call setupWrapping.
* @note Need to add the streams to mux before calling this method.
* @note After this call, a new list of AVOption, relative to the format choosen, will be available for the OutputFile.
*/
*/
bool beginWrap();

IOutputStream::EWrappingStatus wrap( const CodedData& data, const size_t streamId );
IOutputStream::EWrappingStatus wrap( const CodedData& data, const size_t streamIndex );

/**
* @brief Close ressource and write trailer.
Expand All @@ -54,7 +54,7 @@ class AvExport OutputFile : public IOutputFile
void addMetadata( const PropertyVector& data );
void addMetadata( const std::string& key, const std::string& value );

IOutputStream& getStream( const size_t streamId );
IOutputStream& getStream( const size_t streamIndex );

std::string getFilename() const;

Expand Down
22 changes: 12 additions & 10 deletions src/AvTranscoder/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace avtranscoder
{

std::string Logger::logHeaderMessage = "";

void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )
{
std::ofstream outputFile;
Expand All @@ -23,13 +25,10 @@ void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )

void Logger::setLogLevel( const int level )
{
// set ffmpeg log level
av_log_set_level( level );
}

void Logger::log( const int level, const std::string& msg )
{
std::string avTranscoderMsg( "[avTranscoder - " );

// set avtranscoder header message
std::string levelStr;
switch( level )
{
Expand All @@ -48,12 +47,15 @@ void Logger::log( const int level, const std::string& msg )
default:
break;
}
Logger::logHeaderMessage = "[avTranscoder - " + levelStr + "] ";
}

avTranscoderMsg += levelStr;
avTranscoderMsg += "] ";
avTranscoderMsg += msg;
avTranscoderMsg += "\n";
av_log( NULL, level, avTranscoderMsg.c_str() );
void Logger::log( const int level, const std::string& msg )
{
std::string logMessage = Logger::logHeaderMessage;
logMessage += msg;
logMessage += "\n";
av_log( NULL, level, logMessage.c_str() );
}

void Logger::logInFile()
Expand Down
3 changes: 3 additions & 0 deletions src/AvTranscoder/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class AvExport Logger
* @note log filename is avtranscoder.log
*/
static void logInFile();

private:
static std::string logHeaderMessage; ///< First caracters present for each logging message
};

}
Expand Down
7 changes: 7 additions & 0 deletions src/AvTranscoder/mediaProperty/StreamProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ float StreamProperties::getDuration() const
return ( timeBase.num / (float) timeBase.den ) * _formatContext->streams[_streamIndex]->duration;
}

AVMediaType StreamProperties::getStreamType() const
{
if( ! _formatContext )
throw std::runtime_error( "unknown format context" );
return _formatContext->streams[_streamIndex]->codec->codec_type;
}

PropertyVector StreamProperties::getPropertiesAsVector() const
{
PropertyVector data;
Expand Down
3 changes: 2 additions & 1 deletion src/AvTranscoder/mediaProperty/StreamProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class AvExport StreamProperties
size_t getStreamId() const;
Rational getTimeBase() const;
float getDuration() const; ///< in seconds
AVMediaType getStreamType() const;
const PropertyVector& getMetadatas() const { return _metadatas; }

#ifndef SWIG
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
const AVFormatContext& getAVFormatContext() const { return *_formatContext; }
#endif

PropertyMap getPropertiesAsMap() const; ///< Return all properties as a map (name of property, value)
Expand Down
Loading