Commit 9c31e87b authored by André Anjos's avatar André Anjos 💬

Initial push

parents
*~
*.swp
*.pyc
*.so
*.dylib
bin
eggs
parts
.installed.cfg
.mr.developer.cfg
*.egg-info
develop-eggs
sphinx
dist
.nfs*
.gdb_history
build
*.egg
src/
language: python
env:
global:
- secure: TquyIDtjrxz3d9SkrNTP59OuG1/JIEozqUI/tQLHS/3SyYe5ZLjCBhzr0Ay0UmqLQpcoCTp+RSfNzIfHxCqwGqu9+GndXiuHZQAG9FB1gyjBovsHyUki1PAbNSBl/glenNShIFtgpOxKUaYqQ0JjDBdxywOjoqKVJgV27Vk0K0Y=
- secure: IVEbgKYaWUwNapbnioa3rrkLbNLe8pZqJIo9YWmO4EHI58qHyVahb1K9KSM0aNIN2gMZY2i5h00w64w9VxFsTJEwse/Cup3UBMVSufT5r+zVpRwXlEmc62BiRgD4PRXkDN74PsZvPYFs0GGFtpZWsg8oqxwZXBBYygHYxcmKN5A=
- BOB_UPLOAD_WHEEL=1
matrix:
include:
- python: 2.6
- python: 2.7
env:
- BOB_DOCUMENTATION_SERVER=https://www.idiap.ch/software/bob/docs/latest/bioidiap/%s/master
- python: 3.3
- python: 3.4
before_install:
- sudo add-apt-repository -y ppa:biometrics/bob
- sudo apt-get update -qq
- sudo apt-get install -qq --force-yes libboost-all-dev libblitz1-dev libsox-dev libhdf5-serial-dev texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
- pip install --find-links https://www.idiap.ch/software/bob/wheels/travis/ --use-wheel sphinx nose coverage cpp-coveralls pillow
- pip install --find-links https://www.idiap.ch/software/bob/wheels/travis/ --use-wheel --pre -r requirements.txt coveralls
install:
- python bootstrap-buildout.py
- CPPFLAGS=--coverage LDFLAGS=--coverage ./bin/buildout buildout:debug=false buildout:develop=. buildout:extensions=bob.buildout buildout:auto-checkout=
script:
- ./bin/python -c 'import pkg_resources; from bob.io.audio import get_config; print(get_config())'
- ./bin/coverage run --source=bob.io.audio ./bin/nosetests -sv
- ./bin/sphinx-build -b doctest doc sphinx
- ./bin/sphinx-build -b html doc sphinx
after_success:
- cpp-coveralls --build-root=`pwd` --exclude=src --exclude-pattern=".*Compiler.*" --dump=cpp_cov.json
- coveralls --merge=cpp_cov.json
- wget https://raw.githubusercontent.com/bioidiap/bob.extension/master/scripts/upload-{sphinx,wheel}.sh
- chmod a+x upload-sphinx.sh upload-wheel.sh
- ./upload-sphinx.sh
- ./upload-wheel.sh
This diff is collapsed.
include LICENSE README.rst bootstrap-buildout.py buildout.cfg requirements.txt version.txt
recursive-include doc conf.py *.rst
recursive-include bob *.cpp *.h
recursive-include bob/io/video/data *.*
recursive-include bob/io/video/fonts *.txt *.ttf
.. vim: set fileencoding=utf-8 :
.. Andre Anjos <andre.anjos@idiap.ch>
.. Thu 29 Aug 2013 16:07:57 CEST
.. image:: http://img.shields.io/badge/docs-stable-yellow.png
:target: http://pythonhosted.org/bob.io.video/index.html
.. image:: http://img.shields.io/badge/docs-latest-orange.png
:target: https://www.idiap.ch/software/bob/docs/latest/bioidiap/bob.io.video/master/index.html
.. image:: https://travis-ci.org/bioidiap/bob.io.video.svg?branch=master
:target: https://travis-ci.org/bioidiap/bob.io.video?branch=master
.. image:: https://coveralls.io/repos/bioidiap/bob.io.video/badge.png?branch=master
:target: https://coveralls.io/r/bioidiap/bob.io.video?branch=master
.. image:: https://img.shields.io/badge/github-master-0000c0.png
:target: https://github.com/bioidiap/bob.io.video/tree/master
.. image:: http://img.shields.io/pypi/v/bob.io.video.png
:target: https://pypi.python.org/pypi/bob.io.video
.. image:: http://img.shields.io/pypi/dm/bob.io.video.png
:target: https://pypi.python.org/pypi/bob.io.video
===========================
Video I/O Support for Bob
===========================
This package contains support for Video I/O in Bob.
Video reading and writing is implemented using either FFmpeg or LibAV, whichever is installed.
By importing this package, you activate a transparent plugin that makes possible reading and writing video files using ``bob.io.base`` functionalities.
Installation
------------
To install this package -- alone or together with other `Packages of Bob <https://github.com/idiap/bob/wiki/Packages>`_ -- please read the `Installation Instructions <https://github.com/idiap/bob/wiki/Installation>`_.
For Bob_ to be able to work properly, some dependent packages are required to be installed.
Please make sure that you have read the `Dependencies <https://github.com/idiap/bob/wiki/Dependencies>`_ for your operating system.
Documentation
-------------
For further documentation on this package, please read the `Stable Version <http://pythonhosted.org/bob.io.video/index.html>`_ or the `Latest Version <https://www.idiap.ch/software/bob/docs/latest/bioidiap/bob.io.video/master/index.html>`_ of the documentation.
For a list of tutorials on this or the other packages ob Bob_, or information on submitting issues, asking questions and starting discussions, please visit its website.
.. _bob: https://www.idiap.ch/software/bob
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# import Libraries of other lib packages
import bob.io.base
# import our own Library
import bob.extension
bob.extension.load_bob_library('bob.io.audio', __file__)
from ._library import *
from . import version
from .version import module as __version__
def get_config():
"""Returns a string containing the configuration information.
"""
return bob.extension.get_config(__name__, version.externals)
# gets sphinx autodoc done right - don't remove it
__all__ = [_ for _ in dir() if not _.startswith('_')]
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Wed 6 Nov 07:57:57 2013
*
* @brief Implementation of our bobskin class
*/
#include "bobskin.h"
#include <stdexcept>
bobskin::bobskin(PyArrayObject* array, bob::io::base::array::ElementType eltype) {
m_type.set<npy_intp>(eltype, PyArray_NDIM((PyArrayObject*)array),
PyArray_DIMS((PyArrayObject*)array),
PyArray_STRIDES((PyArrayObject*)array));
m_ptr = PyArray_DATA((PyArrayObject*)array);
}
bobskin::~bobskin() { }
void bobskin::set(const interface&) {
PyErr_SetString(PyExc_NotImplementedError, "setting C++ bobskin with (const interface&) is not implemented - DEBUG ME!");
throw std::runtime_error("error is already set");
}
void bobskin::set(boost::shared_ptr<interface>) {
PyErr_SetString(PyExc_NotImplementedError, "setting C++ bobskin with (boost::shared_ptr<interface>) is not implemented - DEBUG ME!");
throw std::runtime_error("error is already set");
}
void bobskin::set (const bob::io::base::array::typeinfo&) {
PyErr_SetString(PyExc_NotImplementedError, "setting C++ bobskin with (const typeinfo&) implemented - DEBUG ME!");
throw std::runtime_error("error is already set");
}
boost::shared_ptr<void> bobskin::owner() {
PyErr_SetString(PyExc_NotImplementedError, "acquiring non-const owner from C++ bobskin is not implemented - DEBUG ME!");
throw std::runtime_error("error is already set");
}
boost::shared_ptr<const void> bobskin::owner() const {
PyErr_SetString(PyExc_NotImplementedError, "acquiring const owner from C++ bobskin is not implemented - DEBUG ME!");
throw std::runtime_error("error is already set");
}
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Tue 5 Nov 22:09:07 2013
*
* @brief A pythonic version of bob::io::base::array::interface, with minimal
* functionality.
*/
#ifndef PYTHON_BOB_IO_BOBSKIN_H
#define PYTHON_BOB_IO_BOBSKIN_H
#include <Python.h>
#include <bob.io.base/array.h>
extern "C" {
#include <bob.blitz/capi.h>
}
/**
* Wraps a PyArrayObject such that we can access it from bob::io
*/
class bobskin: public bob::io::base::array::interface {
public: //api
/**
* @brief Builds a new skin from a numpy array object
*/
bobskin(PyArrayObject* array, bob::io::base::array::ElementType eltype);
/**
* @brief By default, the interface is never freed. You must override
* this method to do something special for your class type.
*/
virtual ~bobskin();
/**
* @brief Copies the data from another interface.
*/
virtual void set(const interface& other);
/**
* @brief Refers to the data of another interface.
*/
virtual void set(boost::shared_ptr<interface> other);
/**
* @brief Re-allocates this interface taking into consideration new
* requirements. The internal memory should be considered uninitialized.
*/
virtual void set (const bob::io::base::array::typeinfo& req);
/**
* @brief Type information for this interface.
*/
virtual const bob::io::base::array::typeinfo& type() const { return m_type; }
/**
* @brief Borrows a reference from the underlying memory. This means
* this object continues to be responsible for deleting the memory and
* you should make sure that it outlives the usage of the returned
* pointer.
*/
virtual void* ptr() { return m_ptr; }
virtual const void* ptr() const { return m_ptr; }
/**
* @brief Returns a representation of the internal cache using shared
* pointers.
*/
virtual boost::shared_ptr<void> owner();
virtual boost::shared_ptr<const void> owner() const;
private: //representation
bob::io::base::array::typeinfo m_type; ///< type information
void* m_ptr; ///< pointer to the data
};
#endif /* PYTHON_BOB_IO_BOBSKIN_H */
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @author Elie Khoury <elie.khoury@idiap.ch>
* @date Tue Nov 12 11:54:30 CET 2013
*
* @brief A class to help you read audio. This code is based on Sox
*/
#include "utils.h"
#include "reader.h"
#include <stdexcept>
#include <boost/format.hpp>
#include <boost/filesystem.hpp>
bob::io::audio::Reader::Reader(const char* filename) {
open(filename);
}
void bob::io::audio::Reader::open(const char* filename) {
m_filename = filename;
if (!boost::filesystem::exists(filename)) {
boost::format m("file '%s' is not readable");
m % filename;
throw std::runtime_error(m.str());
}
//reset previously open file
m_file.reset();
sox_format_t* f = sox_open_read(filename, 0, 0, 0);
if (!f) {
boost::format m("file '%s' is not readable by SoX");
m % filename;
throw std::runtime_error(m.str());
}
//protects file pointer
m_file = boost::shared_ptr<sox_format_t>(f, std::ptr_fun(bob::io::audio::close_sox_file));
m_offset = m_file->tell_off; ///< start of stream
// Set typeinfo variables
m_typeinfo.dtype = bob::core::array::t_float64;
m_typeinfo.nd = 2;
m_typeinfo.shape[0] = this->numberOfChannels();
m_typeinfo.shape[1] = this->numberOfSamples();
m_typeinfo.update_strides();
// Pointer to a single sample that is re-used for readouts
m_buffer = boost::shared_array<sox_sample_t>(new sox_sample_t[m_typeinfo.shape[0]]);
}
bob::io::audio::Reader::~Reader() {
}
size_t bob::io::audio::Reader::load(blitz::Array<double,2>& data) {
bob::core::array::blitz_array tmp(data);
return load(tmp);
}
void bob::io::audio::Reader::reset() {
sox_seek(this->m_file.get(), this->m_offset, SOX_SEEK_SET);
//force re-open if necessary
if ((size_t)m_file->tell_off != m_offset) open(m_filename.c_str());
}
size_t bob::io::audio::Reader::load(bob::io::base::array::interface& b) const {
//checks if the output array shape conforms to the audio specifications,
//otherwise, throw.
if (!m_typeinfo.is_compatible(b.type())) {
boost::format s("input buffer (%s) does not conform to the audio stream size specifications (%s)");
s % b.type().str() % m_typeinfo_video.str();
throw std::runtime_error(s.str());
}
//now we copy from one container to the other, using our Blitz++ technique
blitz::TinyVector<int,2> shape;
blitz::TinyVector<int,2> stride;
shape = m_typeinfo.shape[0], m_typeinfo.shape[1];
stride = m_typeinfo.stride[0], m_typeinfo.stride[1];
blitz::Array<double,2> dst(static_cast<double*>(buffer.ptr()), shape, stride, blitz::neverDeleteData);
auto nchan = this->numberOfChannels();
auto nsamp = this->numberOfSamples()
for (int i=0; i<nsamp; ++i) {
sox_read(m_file.get(), m_buffer.get(), nchan);
for (int j=0; j<nchan; ++j) dst(j,i) = m_buffer[j] / bob::io::audio::SOX_CONVERSION_COEF;
}
this->reset();
return nsamp;
}
/**
* @date Wed 20 Jan 2016 11:23:10 CET
* @author Elie Khoury <elie.khoury@idiap.ch>
* @author Andre Anjos <andre.anjos@idiap.ch>
*
* Copyright (C) Idiap Research Institute, Martigny, Switzerland
*/
#ifndef BOB_IO_AUDIO_READER_H
#define BOB_IO_AUDIO_READER_H
#include <string>
#include <blitz/array.h>
#include <boost/shared_ptr.hpp>
#include <boost/shared_array.hpp>
#include <bob.io.base/array.h>
extern "C" {
#include <sox.h>
}
namespace bob { namespace io { namespace video {
/**
* Reader objects can read data from audio files. The current implementation
* uses SOX which is a stable freely available implementation for these
* tasks. You can read an entire audio in memory by using the "load()"
* method.
*/
class Reader {
public:
/**
* Opens a new SOX stream for reading. The audio will be loaded if the
* combination of format and codec are known to work and have been
* tested, otherwise an exception is raised. If you set 'check' to
* 'false', though, we will ignore this check.
*/
Reader(const char* filename);
/**
* Destructor virtualization
*/
virtual ~Reader();
/**
* Returns the name of the file I'm reading
*/
inline const char* filename() const { return m_filename.c_str(); }
/**
* Returns the sampling rate of the audio stream.
*/
inline double rate() const { return m_file->signal.rate; }
/**
* Returns the number of channels.
*/
inline size_t numberOfChannels() const {
return m_file->signal.channels;
}
/**
* Returns the number of channels.
*/
inline size_t bitsPerSample() const {
return m_file->signal.precision;
}
/**
* Returns the number of samples.
*/
inline size_t numberOfSamples() const {
return m_file->signal.length/this->numberOfChannels();
}
/**
* Duration of the audio stream, in seconds
*/
inline double duration() const {
return this->numberOfSamples()/this->rate();
}
/**
* Returns the encoding name
*/
inline sox_encoding_t encoding() const {
return m_file->encoding.encoding;
}
/**
* Returns the compression factor
*/
inline double compressionFactor() const {
return m_file->encoding.compression;
}
/**
* Returns the typing information for this audio file
*/
inline const bob::io::base::array::typeinfo& type() const
{ return m_typeinfo; }
/**
* Loads all of the audio stream in a blitz array organized in this way:
* (rate, samples). The 'data' parameter will be
* resized if required.
*/
size_t load(blitz::Array<double,2>& data) const;
/**
* Loads all of the video stream in a buffer. Resizes the buffer if
* the space and type are not good.
*/
size_t load(bob::io::base::array::interface& b) const;
/**
* Closes the file
*/
void reset();
private: //methods
/**
* Not implemented
*/
Reader(const Reader& other);
/**
* Not implemented
*/
Reader& operator=(const Reader& other);
/**
* Opens the previously set up SOX stream for the reader
*/
void open(const char* filename);
private: //our representation
std::string m_filename; ///< the name of the file we are manipulating
bob::core::array::typeinfo m_typeinfo; ///< read the audio type
boost::shared_ptr<sox_format_t> m_file; ///< input file
boost::shared_array<sox_sample_t> m_buffer; ///< buffer for readout
uint64_t m_offset; ///< start of stream
};
}}
#endif /* BOB_IO_AUDIO_READER_H */
/**
* @date Thu Nov 14 20:46:52 CET 2013
* @author Andre Anjos <andre.anjos@idiap.ch>
*
* @brief A class for some utilities using sox.
*/
#include "utils.h"
#include <map>
const double bob::io::audio::SOX_CONVERSION_COEF=2147483648.;
void bob::io::audio::close_sox_file(sox_format_t* f) {
sox_close(f);
}
//requires c++11 for compiling
static const std::map<sox_encoding_t, std::string> ENC2STR = {
{SOX_ENCODING_SIGN2, "SIGN2"},
{SOX_ENCODING_UNSIGNED, "UNSIGNED"},
{SOX_ENCODING_FLOAT, "FLOAT"},
{SOX_ENCODING_FLOAT_TEXT, "FLOAT_TEXT"},
{SOX_ENCODING_FLAC, "FLAC"},
{SOX_ENCODING_HCOM, "HCOM"},
{SOX_ENCODING_WAVPACK, "WAVPACK"},
{SOX_ENCODING_WAVPACKF, "WAVPACKF"},
{SOX_ENCODING_ULAW, "ULAW"},
{SOX_ENCODING_ALAW, "ALAW"},
{SOX_ENCODING_G721, "G721"},
{SOX_ENCODING_G723, "G723"},
{SOX_ENCODING_CL_ADPCM, "CL_ADPCM"},
{SOX_ENCODING_CL_ADPCM16, "CL_ADPCM16"},
{SOX_ENCODING_MS_ADPCM, "MS_ADPCM"},
{SOX_ENCODING_IMA_ADPCM, "IMA_ADPCM"},
{SOX_ENCODING_OKI_ADPCM, "OKI_ADPCM"},
{SOX_ENCODING_DPCM, "DPCM"},
{SOX_ENCODING_DWVW, "DWVW"},
{SOX_ENCODING_DWVWN, "DWVWN"},
{SOX_ENCODING_GSM, "GSM"},
{SOX_ENCODING_MP3, "MP3"},
{SOX_ENCODING_VORBIS, "VORBIS"},
{SOX_ENCODING_AMR_WB, "AMR_WB"},
{SOX_ENCODING_AMR_NB, "AMR_NB"},
{SOX_ENCODING_CVSD, "CVSD"},
{SOX_ENCODING_LPC10, "LPC10"},
{SOX_ENCODING_UNKNOWN, "UNKNOWN"}
};
const char* bob::io::audio::encoding2string(sox_encoding_t e) {
auto it = ENC2STR.find(e);
if (e != ENC2STR.end()) return it->second;
return ENC2STR.rbegin()->second; //last entry: UNKNOWN
}
//requires c++11 for compiling
static const std::map<sox_encoding_t, std::string> STR2ENC = {
{"SIGN2", SOX_ENCODING_SIGN2},
{"UNSIGNED", SOX_ENCODING_UNSIGNED},
{"FLOAT", SOX_ENCODING_FLOAT},
{"FLOAT_TEXT", SOX_ENCODING_FLOAT_TEXT},
{"FLAC", SOX_ENCODING_FLAC},
{"HCOM", SOX_ENCODING_HCOM},
{"WAVPACK", SOX_ENCODING_WAVPACK},
{"WAVPACKF", SOX_ENCODING_WAVPACKF},
{"ULAW", SOX_ENCODING_ULAW},
{"ALAW", SOX_ENCODING_ALAW},
{"G721", SOX_ENCODING_G721},
{"G723", SOX_ENCODING_G723},
{"CL_ADPCM", SOX_ENCODING_CL_ADPCM},
{"CL_ADPCM16", SOX_ENCODING_CL_ADPCM16},
{"MS_ADPCM", SOX_ENCODING_MS_ADPCM},
{"IMA_ADPCM", SOX_ENCODING_IMA_ADPCM},
{"OKI_ADPCM", SOX_ENCODING_OKI_ADPCM},
{"DPCM", SOX_ENCODING_DPCM},
{"DWVW", SOX_ENCODING_DWVW},
{"DWVWN", SOX_ENCODING_DWVWN},
{"GSM", SOX_ENCODING_GSM},
{"MP3", SOX_ENCODING_MP3},
{"VORBIS", SOX_ENCODING_VORBIS},
{"AMR_WB", SOX_ENCODING_AMR_WB},
{"AMR_NB", SOX_ENCODING_AMR_NB},
{"CVSD", SOX_ENCODING_CVSD},
{"LPC10", SOX_ENCODING_LPC10},
{"UNKNOWN", SOX_ENCODING_UNKNOWN}
};
sox_encoding_t bob::io::audio::string2encoding(const char* s) {
auto it = STR2ENC.find(e);
if (e != STR2ENC.end()) return it->second;
return STR2ENC.rbegin()->second; //last entry: UNKNOWN
}
/**
* @author Elie Khoury <elie.khoury@idiap.ch>
* @author Andre Anjos <andre.anjos@idiap.ch>
* @date Wed 20 Jan 2016 11:19:53 CET
*
* Copyright (C) Idiap Research Institute, Martigny, Switzerland
*/
#ifndef BOB_IO_AUDIO_UTILS_H
#define BOB_IO_AUDIO_UTILS_H
#include <string>
extern "C" {
#include <sox.h>
}
namespace bob { namespace io { namespace audio {
const double SOX_CONVERSION_COEF;
void close_sox_file(sox_format_t* f);
const char* encoding2string(sox_encoding_t encoding);
sox_encoding_t string2encoding(const char* encoding);
}}}
#endif /* BOB_IO_AUDIO_UTILS_H */
/**
* @author Andre Anjos <andre.anjos@idiap.ch>
* @author Elie Khoury <elie.khoury@idiap.ch>
* @date Wed 20 Jan 2016 17:18:05 CET
*
* @brief A class to help you write audio.
*/
#include "utils.h"
#include "writer.h"
#include <stdexcept>
#include <boost/format.hpp>
bob::io::audio::Writer::Writer(const char* filename, double rate,
sox_encoding_t encoding, size_t bits_per_sample):
m_filename(filename),
m_opened(false)
{
sox_signalinfo_t siginfo;
siginfo.rate = rate;
siginfo.precision = bits_per_sample;
siginfo.channels = 0;
siginfo.length = 0;
sox_encodinginfo_t encoding_info;
encoding_info.encoding = encoding;
encoding_info.bits_per_sample = bits_per_sample;
encoding_info.compression = HUGE_VAL;
#if SOX_LIB_VERSION_CODE >= SOX_LIB_VERSION(14,4,0)
encoding_info.reverse_bytes = sox_option_default;
encoding_info.reverse_nibbles = sox_option_default;
encoding_info.reverse_bits = sox_option_default;
#else
encoding_info.reverse_bytes = SOX_OPTION_DEFAULT;
encoding_info.reverse_nibbles = SOX_OPTION_DEFAULT;
encoding_info.reverse_bits = SOX_OPTION_DEFAULT;
#endif
sox_format_t* f = 0;
if (encoding == SOX_ENCODING_UNKNOWN) f = sox_open_write(filename, &siginfo, 0, lsx_find_file_extension(filename), 0, 0);
else f = sox_open_write(filename, &siginfo, &encoding_info, 0, 0, 0);
if (!f) {
boost::format m("file '%s' is not writeable by SoX");
m % filename;
throw std::runtime_error(m.str());
}
m_file = boost::shared_ptr<sox_format_t>(f, std::ptr_fun(bob::io::audio::close_sox_file));
m_typeinfo.dtype = bob::core::array::t_float64;
m_typeinfo.nd = 2;
m_typeinfo.shape[0] = 0;
m_typeinfo.shape[1] = 0;
m_typeinfo.update_strides();
m_buffer = boost::shared_array<sox_sample_t>(new sox_sample_t[m_typeinfo.shape[0]]);
m_opened = true; ///< file is now considered opened for business
}
void bob::io::audio::Writer::append(const blitz::Array<double,1>& data) {
if (!m_opened) {
boost::format m("audio writer for file `%s' is closed and cannot be written to");
m % m_filename;