Skip to content

Commit

Permalink
Merge b899eab into f8b8e8f
Browse files Browse the repository at this point in the history
  • Loading branch information
valnoel committed Jan 23, 2020
2 parents f8b8e8f + b899eab commit b4945cb
Show file tree
Hide file tree
Showing 29 changed files with 501 additions and 205 deletions.
38 changes: 23 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,28 @@ env:
- DEPENDENCY_LOG_FILE=${TRAVIS_BUILD_DIR}/build-dependencies-log.txt

- YASM_VERSION=1.3.0
- LAME_VERSION=3.99.5
- FAAC_VERSION=1.28
- LAME_VERSION=3.100
# - FAAC_VERSION=1.28
- XVID_VERSION=1.3.3
- FDKAAC_VERSION=0.1.3
# - FDKAAC_VERSION=0.1.3
- OGG_VERSION=1.3.2
- VORBIS_VERSION=1.3.4
- THEORA_VERSION=1.1.1
- VORBIS_VERSION=1.3.6
# - THEORA_VERSION=1.1.1
- VPX_VERSION=1.4.0
matrix:
- DEPENDENCY_NAME=libav DEPENDENCY_VERSION=11.3 ENABLE_COVERAGE=true
- DEPENDENCY_NAME=libav DEPENDENCY_VERSION=11.3 ENABLE_COVERAGE=false
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.4.2 ENABLE_COVERAGE=true
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.4.2 ENABLE_COVERAGE=false
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.5.7 ENABLE_COVERAGE=false
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.6.8 ENABLE_COVERAGE=false
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.7.6 ENABLE_COVERAGE=false
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.8.6 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=libav DEPENDENCY_VERSION=11.12 ENABLE_COVERAGE=true
# - DEPENDENCY_NAME=libav DEPENDENCY_VERSION=11.12 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=libav DEPENDENCY_VERSION=12.3 ENABLE_COVERAGE=true
# - DEPENDENCY_NAME=libav DEPENDENCY_VERSION=12.3 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.4.2 ENABLE_COVERAGE=true
# - DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.4.2 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.5.7 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.6.8 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.7.6 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.8.6 ENABLE_COVERAGE=false
# - DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=4.0 ENABLE_COVERAGE=false
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=4.1 ENABLE_COVERAGE=false
- DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=4.2 ENABLE_COVERAGE=true

matrix:
exclude:
Expand All @@ -57,6 +62,7 @@ matrix:
env: DEPENDENCY_NAME=ffmpeg DEPENDENCY_VERSION=2.4.2 ENABLE_COVERAGE=true
allow_failures:
# build with libav
- os: osx
- env: DEPENDENCY_NAME=libav DEPENDENCY_VERSION=11.3 ENABLE_COVERAGE=true
- env: DEPENDENCY_NAME=libav DEPENDENCY_VERSION=11.3 ENABLE_COVERAGE=false
# build with ffmpeg-2.8.6
Expand All @@ -75,8 +81,10 @@ addons:
packages:
- cmake
- swig
- python-dev
- python-nose
- python3-dev
- python3
- python3-nose
- python3-coverage
- freeglut3-dev

cache:
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ cmake_minimum_required(VERSION 2.8.11)

project(AvTranscoder)

# All libraries will be put in INSTALL_PREFIX/lib
# RPATH of host points INSTALL_PREFIX/lib
# see: http://www.cmake.org/Wiki/CMake_RPATH_handling
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)


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

Expand Down
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# C++ apps
add_subdirectory(avAudioPhaseMeter)
add_subdirectory(avInfo)
add_subdirectory(avMeta)
add_subdirectory(avPlayer)
Expand Down
24 changes: 24 additions & 0 deletions app/avAudioPhaseMeter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### cpp/avProcessor

# Load custom cmake utilities
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(AvTranscoderMacros)

# Build app
add_executable(avaudiophasemeter avAudioPhaseMeter.cpp)
set_target_properties(avaudiophasemeter PROPERTIES VERSION ${AVTRANSCODER_VERSION})
target_link_libraries(avaudiophasemeter avtranscoder-shared)

# Install app
if(WIN32)
set(BINARY_FILES "${CMAKE_CURRENT_BINARY_DIR}/avaudiophasemeter.exe")
else()
set(BINARY_FILES "${CMAKE_CURRENT_BINARY_DIR}/avaudiophasemeter" "${CMAKE_CURRENT_BINARY_DIR}/avaudiophasemeter-${AVTRANSCODER_VERSION}")
endif()

install(
FILES ${BINARY_FILES}
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE
DESTINATION "bin/"
OPTIONAL
)
141 changes: 141 additions & 0 deletions app/avAudioPhaseMeter/avAudioPhaseMeter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#include <AvTranscoder/transcoder/Transcoder.hpp>
#include <AvTranscoder/file/OutputFile.hpp>
#include <AvTranscoder/progress/ConsoleProgress.hpp>

#include <iostream>
#include <iomanip>
#include <vector>
#include <fstream>
#include <sstream>
#include <cstdlib>

std::vector<avtranscoder::InputStreamDesc> parseConfigFile(const std::string& configFilename)
{
std::vector<avtranscoder::InputStreamDesc> result;

std::ifstream configFile(configFilename.c_str(), std::ifstream::in);

std::string line;
size_t countLines = 0;
while(std::getline(configFile, line))
{
if(++countLines > 2)
throw std::runtime_error("Audio phase analysis can only be done on a stereo pair, i.e. two channels (see usage).");

std::istringstream is_line(line);
std::string filename;
if(std::getline(is_line, filename, '='))
{
std::string stream;
std::getline(is_line, stream);

std::stringstream ss(stream);
size_t streamIndex = 0;
char separator;
int channelIndex = -1;
ss >> streamIndex;
ss >> separator;
if(separator == '.')
ss >> channelIndex;

bool newInputDescAdded = false;
// if we already have an input description with the same filename/streamIndex, add only the new channelIndex
for(std::vector<avtranscoder::InputStreamDesc>::iterator it = result.begin(); it != result.end(); ++it)
{
if(it->_filename == filename && it->_streamIndex == streamIndex)
{
it->_channelIndexArray.push_back(channelIndex);
newInputDescAdded = true;
break;
}
}
if(! newInputDescAdded)
result.push_back(avtranscoder::InputStreamDesc(filename, streamIndex, channelIndex));
}
}

configFile.close();

return result;
}

void displayUsage(const std::string& program)
{
std::cout << "Usage: " << program << " CONFIG OUTPUT [OPTIONS]" << std::endl << std::endl;
std::cout << "\tCONFIG: input configuration file" << std::endl;
std::cout << "\t\tEach line represents one audio stream analysed." << std::endl;
std::cout << "\t\tPattern of each line is:" << std::endl;
std::cout << "\t\t[inputFile]=STREAM_INDEX.CHANNEL_INDEX" << std::endl;
std::cout << "\t\tWARNING: audio phase analyser only support stereo layout, i.e. two lines in this configuration." << std::endl << std::endl;
std::cout << "\tOUTPUT: metadata output file" << std::endl;
std::cout << "\t\tPattern for each frame is:" << std::endl;
std::cout << "\t\t `frame:[FRAME_ID] pts:[PTS] pts_time:[PTS_TIME]" << std::endl;
std::cout << "\t\t lavfi.aphasemeter.phase=[PHASE_VALUE]`" << std::endl << std::endl;
std::cout << "\tOPTIONS:" << std::endl;
std::cout << "\t\t--info set log level to AV_LOG_INFO" << std::endl;
std::cout << "\t\t--debug set log level to AV_LOG_DEBUG" << std::endl;
std::cout << "\t\t--help display this help" << std::endl << std::endl;
}

int main(int argc, char** argv)
{
// Preload FFmpeg context
avtranscoder::preloadCodecsAndFormats();
avtranscoder::Logger::setLogLevel(AV_LOG_QUIET);

if(argc < 3) {
displayUsage(argv[0]);
}

// List command line arguments
std::vector<std::string> arguments;
for(int argument = 1; argument < argc; ++argument)
{
arguments.push_back(argv[argument]);
}
for(size_t argument = 0; argument < arguments.size(); ++argument)
{
if(arguments.at(argument) == "--help")
{
displayUsage(argv[0]);
return 0;
}
else if(arguments.at(argument) == "--debug")
{
avtranscoder::Logger::setLogLevel(AV_LOG_DEBUG);
}
else if(arguments.at(argument) == "--info")
{
avtranscoder::Logger::setLogLevel(AV_LOG_INFO);
}
}

try
{
std::string configFilePath(arguments.at(0));
std::string outputFilePath(arguments.at(1));
std::vector<avtranscoder::InputStreamDesc> inputStreamsToAnalyse = parseConfigFile(configFilePath);

avtranscoder::OutputFile outputFile(outputFilePath, "null"); // the output file will be overwritten by the extracted metadata

avtranscoder::Transcoder transcoder(outputFile);
transcoder.setProcessMethod(avtranscoder::eProcessMethodBasedOnStream, 0);
transcoder.addStream(inputStreamsToAnalyse);

avtranscoder::StreamTranscoder& streamTranscoder = transcoder.getStreamTranscoder(0);
avtranscoder::FilterGraph* filterGraph = streamTranscoder.getFilterGraph();
filterGraph->addFilter("aphasemeter", "video=0");
filterGraph->addFilter("ametadata", "mode=print:file=" + outputFilePath);

avtranscoder::ConsoleProgress progress;
transcoder.process(progress);
}
catch(std::exception& e)
{
std::cerr << "ERROR: during process, an error occured: " << e.what() << std::endl;
}
catch(...)
{
std::cerr << "ERROR: during process, an unknown error occured" << std::endl;
}
}
8 changes: 4 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ platform:
environment:
global:
DEPENDENCY_NAME: ffmpeg
DEPENDENCY_VERSION: 2.4.5
DEPENDENCY_VERSION: 4.2.1
DEPENDENCY_INSTALL_PATH: C:\ProgramData\install-dependency
AVTRANSCODER_INSTALL_PATH: C:\projects\avtranscoder\build\install-avtranscoder

Expand All @@ -25,10 +25,10 @@ install:

# Get the correct python version
- ps: if($env:platform -eq 'x86') {
$env:PYTHON = "C:\Python27";
$env:PYTHON = "C:\Python35";
}
else {
$env:PYTHON = "C:\Python27-x64";
$env:PYTHON = "C:\Python35-x64";
}
# Prepend newly installed Python to the PATH of this build
- cmd: set PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
Expand All @@ -37,7 +37,7 @@ install:
- "python --version"
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
# Upgrade to the latest version of pip to avoid it displaying warnings about it being out of date.
- pip install --disable-pip-version-check --user --upgrade pip
- "python -m pip install --disable-pip-version-check --user --upgrade pip"

# Install tests dependencies
- pip install nose
Expand Down
4 changes: 4 additions & 0 deletions src/AvTranscoder/encoder/VideoEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ void VideoEncoder::setupEncoder(const ProfileLoader::Profile& profile)
if(profile.count(constants::avProfileProcessStat))
{
LOG_INFO("SetUp video encoder to compute statistics during process")
#ifdef AV_CODEC_FLAG_PSNR
encoderFlags |= AV_CODEC_FLAG_PSNR;
#else
encoderFlags |= CODEC_FLAG_PSNR;
#endif
}
_codec.getAVCodecContext().flags |= encoderFlags;
_codec.openCodec();
Expand Down
20 changes: 14 additions & 6 deletions src/AvTranscoder/file/OutputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ IOutputStream::EWrappingStatus OutputFile::wrap(const CodedData& data, const siz
packet.dts = av_rescale_q(data.getAVPacket().dts, srcTimeBase, dstTimeBase);
}
// add stream PTS if already incremented
const int currentStreamPTS = _outputStreams.at(streamIndex)->getStreamPTS();
if(packet.pts != AV_NOPTS_VALUE && packet.pts < currentStreamPTS)
{
packet.pts += currentStreamPTS;
packet.dts += currentStreamPTS;
}
// const int currentStreamPTS = _outputStreams.at(streamIndex)->getStreamPTS();
// if(packet.pts != AV_NOPTS_VALUE && packet.pts < currentStreamPTS)
// {
// packet.pts += currentStreamPTS;
// packet.dts += currentStreamPTS;
// }
}

// copy duration of packet wrapped
Expand Down Expand Up @@ -332,11 +332,19 @@ void OutputFile::setOutputStream(AVStream& avStream, const ICodec& codec)
// depending on the format, place global headers in extradata instead of every keyframe
if(_formatContext.getAVOutputFormat().flags & AVFMT_GLOBALHEADER)
{
#ifdef AV_CODEC_FLAG_GLOBAL_HEADER
avStream.codec->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
#else
avStream.codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
#endif
}

// if the codec is experimental, allow it
#ifdef AV_CODEC_CAP_EXPERIMENTAL
if(codec.getAVCodec().capabilities & AV_CODEC_CAP_EXPERIMENTAL)
#else
if(codec.getAVCodec().capabilities & CODEC_CAP_EXPERIMENTAL)
#endif
{
LOG_WARN("This codec is considered experimental by libav/ffmpeg:" << codec.getCodecName());
avStream.codec->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/filter/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Filter::Filter(const std::string& name, const std::string& options, const std::s
, _options(options)
, _instanceName(instanceName.empty() ? name : instanceName)
{
_filter = avfilter_get_by_name(name.c_str());
_filter = (AVFilter*)avfilter_get_by_name(name.c_str());
if(!_filter)
{
std::string msg("Cannot find filter ");
Expand Down
11 changes: 10 additions & 1 deletion src/AvTranscoder/properties/StreamProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ std::string StreamProperties::getCodecName() const
if(!_codecContext || !_codec)
throw std::runtime_error("unknown codec");

#ifdef AV_CODEC_CAP_TRUNCATED
if(_codec->capabilities & AV_CODEC_CAP_TRUNCATED)
_codecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
#else
if(_codec->capabilities & CODEC_CAP_TRUNCATED)
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
#endif

if(!_codec->name)
throw std::runtime_error("unknown codec name");
Expand All @@ -107,9 +112,13 @@ std::string StreamProperties::getCodecLongName() const
if(!_codecContext || !_codec)
throw std::runtime_error("unknown codec");

#ifdef AV_CODEC_CAP_TRUNCATED
if(_codec->capabilities & AV_CODEC_CAP_TRUNCATED)
_codecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
#else
if(_codec->capabilities & CODEC_CAP_TRUNCATED)
_codecContext->flags |= CODEC_FLAG_TRUNCATED;

#endif
if(!_codec->long_name)
throw std::runtime_error("unknown codec long name");

Expand Down
8 changes: 7 additions & 1 deletion src/AvTranscoder/properties/VideoProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ std::string VideoProperties::getProfileName() const
if(!_codecContext || !_codec)
throw std::runtime_error("unknown codec");

#ifdef AV_CODEC_CAP_TRUNCATED
if(_codec->capabilities & AV_CODEC_CAP_TRUNCATED)
_codecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
#else
if(_codec->capabilities & CODEC_CAP_TRUNCATED)
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
#endif

const char* profile = NULL;
if((profile = av_get_profile_name(_codec, getProfile())) == NULL)
Expand Down Expand Up @@ -427,7 +432,8 @@ size_t VideoProperties::getDtgActiveFormat() const
{
if(!_codecContext)
throw std::runtime_error("unknown codec context");
return _codecContext->dtg_active_format;
// return _codecContext->dtg_active_format;
return 0;
}

size_t VideoProperties::getReferencesFrames() const
Expand Down

0 comments on commit b4945cb

Please sign in to comment.