Skip to content

AudioReader: can specify the channel index #186

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 48 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5768d99
AudioFrame: improved exception message when cannot get data size
Dec 1, 2015
427f8e8
IReader: added default value to streamIndex parameter
Dec 1, 2015
4a6e71a
IReader: added channelIndex attribute to be able to extract a part of…
Dec 1, 2015
82321ad
VideoReader: added updateOutput method to refactore constructors
Dec 1, 2015
154bd39
VideoReader: update getters to const and define them in hpp
Dec 1, 2015
79da994
VideoReader: update name of getters and attributes
Dec 1, 2015
48bcb46
VideoReader: updated doc of constructors
Dec 1, 2015
f151b82
avplay app: added help
Dec 1, 2015
2f3a66e
avplay app: added --width / --height options
Dec 1, 2015
a07c96f
avplay app: set log level to QUIET
Dec 1, 2015
fe52243
AudioReader: added updateOutput method to refactore constructors
Dec 1, 2015
8ac68dc
VideoReader: removed unnecessary local variable in init method
Dec 1, 2015
3b099bb
AudioReader: update getters to const and define them in hpp
Dec 1, 2015
dbeebb6
AudioReader: update name of getters and attributes
Dec 1, 2015
793b0ae
Video/AudioReader: added default value to streamIndex parameter
Dec 1, 2015
98ad888
AudioReader: added channelIndex parameter in constructors
Dec 1, 2015
ebe4cab
AudioReader: renamed getOutputChannels to getOutputNbChannels
Dec 1, 2015
decb49c
AudioTransform: improved ecxception message when cannot init audio co…
Dec 1, 2015
c6bc636
readers: removed printInfo method
Dec 1, 2015
31c9d21
IReader: added getSourceProperties method
Dec 1, 2015
6e22c0a
Video/AudioReader: renamed getter to properties
Dec 1, 2015
b731e36
AudioProperties: renamed getChannels to getNbChannels
Dec 1, 2015
db709eb
decoders: renamed 'subStreamIndex' parameter to 'channelIndex'
Dec 1, 2015
1e2123c
AudioDecoder: refactore decodeNextFrame methods
Dec 1, 2015
0f415e7
AudioDecoder: improved exception message when decodeNextFrame and the…
Dec 1, 2015
3a7a040
VideoTransform: log video conversion as info
Dec 1, 2015
e3beddf
AudioTransform: added log of audio conversion as info
Dec 1, 2015
2cbc5eb
pyTest: fix tests - renamed getChannels to getNbChannels
Dec 1, 2015
1a635be
readers: return an empty frame when there is nothing to decode
Dec 2, 2015
0c3bf14
AudioReader: fix nbChannels of output when extract one channel
Dec 2, 2015
f2cc0ca
pyTest: added pyTest to check readers
Dec 2, 2015
f918ef3
Merge branch 'develop' of https://github.com/avTranscoder/avTranscode…
cchampet Dec 20, 2015
634ed10
Merge branch 'develop' of https://github.com/avTranscoder/avTranscode…
Jan 12, 2016
34bb99e
AudioFrame: renamed get/setChannels to get/setNbChannels
Jan 12, 2016
f1ad8db
AudioFrame: renamed get/setNbSamples to get/setNbSamplesPerChannel
Jan 12, 2016
43f5210
AudioTransform: renamed _nbSamplesOfPreviousFrame to _previousNbInput…
Jan 12, 2016
7493be6
Library: updated avtranscoder license value
Jan 12, 2016
d613b66
frame: split Frame and CodedData
Jan 12, 2016
8fb4004
Renamed frame folder to data
Jan 12, 2016
d60088d
util: added getPixel/SampleFormatName functions
Jan 18, 2016
37601a8
data: Frame class describes raw data with an AVFrame
Jan 19, 2016
38c91a9
OutputFile: log in debug if eWrappingWaitingForData
Jan 19, 2016
5e80e12
AudioFrameDesc: removed _fps attribute
Jan 19, 2016
99e933e
AudioGenerator: fixed name of setFrame method
Jan 19, 2016
f6467b1
Frame: fixed compilation error with gcc-4.8
Jan 19, 2016
a2c8493
Video/AudioFrame: fixed compilation error with msvc
Jan 19, 2016
28dc37c
Frame: removed getPlaneData method
Jan 19, 2016
54d4cbe
AudioDecoder: fixed memory leak when decodeNextFrame with a specific …
Jan 19, 2016
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
26 changes: 16 additions & 10 deletions app/avPlay/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "Window.hpp"

#include <AvTranscoder/properties/print.hpp>

#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
Expand Down Expand Up @@ -103,8 +104,8 @@ void loadNewTexture(const char* data, GLint internalFormat, size_t width, size_t
Window::Window(avtranscoder::VideoReader& reader)
{
_reader = &reader;
_width = _reader->getWidth();
_height = _reader->getHeight();
_width = _reader->getOutputWidth();
_height = _reader->getOutputHeight();

char* argv[2] = {(char*)"", NULL};
int argc = 1;
Expand Down Expand Up @@ -439,7 +440,9 @@ void Window::displayInformations()
std::cout << textureType << " " << _width << "x" << _height << std::endl;

// stream info
_reader->printInfo();
const avtranscoder::VideoProperties* properties = _reader->getSourceVideoProperties();
if(properties != NULL)
std::cout << *properties << std::endl;
}

void Window::move(float x, float y)
Expand Down Expand Up @@ -547,15 +550,17 @@ void Window::showAlphaChannelTexture()

void Window::displayNextFrame()
{
const char* buffer = (const char*)_reader->readNextFrame()->getData();
loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE);
const char* buffer = (const char*)_reader->readNextFrame()->getData()[0];
loadNewTexture(buffer, _reader->getOutputNbComponents(), _reader->getOutputWidth(), _reader->getOutputHeight(), GL_RGB,
GL_UNSIGNED_BYTE);
display();
}

void Window::displayPrevFrame()
{
const char* buffer = (const char*)_reader->readPrevFrame()->getData();
loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE);
const char* buffer = (const char*)_reader->readPrevFrame()->getData()[0];
loadNewTexture(buffer, _reader->getOutputNbComponents(), _reader->getOutputWidth(), _reader->getOutputHeight(), GL_RGB,
GL_UNSIGNED_BYTE);
display();
}

Expand All @@ -566,8 +571,9 @@ void Window::displayFirstFrame()

void Window::displayAtFrame(const size_t frame)
{
const char* buffer = (const char*)_reader->readFrameAt(frame)->getData();
loadNewTexture(buffer, _reader->getComponents(), _reader->getWidth(), _reader->getHeight(), GL_RGB, GL_UNSIGNED_BYTE);
const char* buffer = (const char*)_reader->readFrameAt(frame)->getData()[0];
loadNewTexture(buffer, _reader->getOutputNbComponents(), _reader->getOutputWidth(), _reader->getOutputHeight(), GL_RGB,
GL_UNSIGNED_BYTE);
display();
}

Expand Down
77 changes: 73 additions & 4 deletions app/avPlay/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,90 @@

#include "Window.hpp"

#include <cstdlib>

int main(int argc, char** argv)
{
avtranscoder::preloadCodecsAndFormats();
std::string filename;
size_t streamIndex = 0;
size_t width = 0;
size_t height = 0;

std::string help;
help += "Usage\n";
help += "\tavplay filename [streamIndex] [--width width] [--height height] [--help]\n";
help += "Command line options\n";
help += "\tstreamIndex: specify the index of the stream to read (by default 0)\n";
help += "\t--width: specify the output width (by default the same as input)\n";
help += "\t--height: specify the output height (by default the same as input)\n";
help += "\t--help: display this help\n";

// 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")
{
std::cout << help << std::endl;
return 0;
}
else if(arguments.at(argument) == "--width")
{
try
{
width = atoi(arguments.at(++argument).c_str());
}
catch(...)
{
std::cout << help << std::endl;
return 0;
}
}
else if(arguments.at(argument) == "--height")
{
try
{
height = atoi(arguments.at(++argument).c_str());
}
catch(...)
{
std::cout << help << std::endl;
return 0;
}
}
// positional arguments
if(argument == 0)
{
filename = arguments.at(argument);
}
else if(argument == 1)
{
streamIndex = atoi(arguments.at(argument).c_str());
}
}

// Check required arguments
if(argc < 2)
{
std::cout << "avplay can play the given video media file." << std::endl;
std::cout << "Provide the filename and the streamIndex (0 by default)" << std::endl;
std::cout << "Use option --help to display help" << std::endl;
return (-1);
}

const std::string filename(argv[1]);
const size_t streamIndex = argc > 2 ? atoi(argv[2]) : 0;
// Setup avtranscoder
avtranscoder::preloadCodecsAndFormats();
avtranscoder::Logger::setLogLevel(AV_LOG_QUIET);

avtranscoder::VideoReader reader(filename, streamIndex);
if(width == 0)
width = reader.getOutputWidth();
if(height == 0)
height = reader.getOutputHeight();
reader.updateOutput(width, height, "rgb24");
Window window(reader);
window.launch();
}
2 changes: 1 addition & 1 deletion src/AvTranscoder/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Libraries getLibraries()
{
Libraries libs;

libs.push_back(Library("avtranscoder", "GPL or LGPL version 3", AVTRANSCODER_VERSION_MAJOR, AVTRANSCODER_VERSION_MINOR,
libs.push_back(Library("avtranscoder", "GPL v2 or LGPL v2.1", AVTRANSCODER_VERSION_MAJOR, AVTRANSCODER_VERSION_MINOR,
AVTRANSCODER_VERSION_MICRO));
libs.push_back(
Library("avutil", avutil_license(), LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR, LIBAVUTIL_VERSION_MICRO));
Expand Down
2 changes: 1 addition & 1 deletion src/AvTranscoder/avTranscoder.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

%include "AvTranscoder/progress/progress.i"
%include "AvTranscoder/properties/properties.i"
%include "AvTranscoder/frame/frame.i"
%include "AvTranscoder/data/data.i"
%include "AvTranscoder/profile/profile.i"

%include <AvTranscoder/Library.hpp>
Expand Down
9 changes: 4 additions & 5 deletions src/AvTranscoder/codec/AudioCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ AudioCodec::AudioCodec(const ECodecType type, AVCodecContext& avCodecContext)
AudioFrameDesc AudioCodec::getAudioFrameDesc() const
{
assert(_avCodecContext != NULL);
AudioFrameDesc audioFrameDesc(_avCodecContext->sample_rate, _avCodecContext->channels, _avCodecContext->sample_fmt);
return audioFrameDesc;
return AudioFrameDesc(_avCodecContext->sample_rate, _avCodecContext->channels, _avCodecContext->sample_fmt);
}

void AudioCodec::setAudioParameters(const AudioFrameDesc& audioFrameDesc)
{
_avCodecContext->sample_rate = audioFrameDesc.getSampleRate();
_avCodecContext->channels = audioFrameDesc.getChannels();
_avCodecContext->sample_fmt = audioFrameDesc.getSampleFormat();
_avCodecContext->sample_rate = audioFrameDesc._sampleRate;
_avCodecContext->channels = audioFrameDesc._nbChannels;
_avCodecContext->sample_fmt = audioFrameDesc._sampleFormat;
}
}
2 changes: 1 addition & 1 deletion src/AvTranscoder/codec/AudioCodec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _AV_TRANSCODER_CODEC_AUDIO_CODEC_HPP_

#include "ICodec.hpp"
#include <AvTranscoder/frame/AudioFrame.hpp>
#include <AvTranscoder/data/decoded/AudioFrame.hpp>

namespace avtranscoder
{
Expand Down
10 changes: 5 additions & 5 deletions src/AvTranscoder/codec/VideoCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ VideoFrameDesc VideoCodec::getVideoFrameDesc() const
VideoFrameDesc videoFrameDesc(_avCodecContext->width, _avCodecContext->height, _avCodecContext->pix_fmt);
double fps = 1.0 * _avCodecContext->time_base.den / (_avCodecContext->time_base.num * _avCodecContext->ticks_per_frame);
if(!std::isinf(fps))
videoFrameDesc.setFps(fps);
videoFrameDesc._fps = fps;
return videoFrameDesc;
}

void VideoCodec::setImageParameters(const VideoFrameDesc& videoFrameDesc)
{
_avCodecContext->width = videoFrameDesc.getWidth();
_avCodecContext->height = videoFrameDesc.getHeight();
_avCodecContext->pix_fmt = videoFrameDesc.getPixelFormat();
_avCodecContext->width = videoFrameDesc._width;
_avCodecContext->height = videoFrameDesc._height;
_avCodecContext->pix_fmt = videoFrameDesc._pixelFormat;
_avCodecContext->time_base.num = 1;
_avCodecContext->time_base.den = videoFrameDesc.getFps();
_avCodecContext->time_base.den = videoFrameDesc._fps;
_avCodecContext->ticks_per_frame = 1;
}
}
2 changes: 1 addition & 1 deletion src/AvTranscoder/codec/VideoCodec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _AV_TRANSCODER_CODEC_VIDEO_CODEC_HPP_

#include "ICodec.hpp"
#include <AvTranscoder/frame/VideoFrame.hpp>
#include <AvTranscoder/data/decoded/VideoFrame.hpp>

namespace avtranscoder
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
#include "Frame.hpp"
#include "CodedData.hpp"

#include <cstring>

namespace avtranscoder
{

Frame::Frame()
CodedData::CodedData()
: _avStream(NULL)
{
initAVPacket();
}

Frame::Frame(const size_t dataSize)
CodedData::CodedData(const size_t dataSize)
: _avStream(NULL)
{
av_new_packet(&_packet, dataSize);
}

Frame::Frame(const AVPacket& avPacket)
CodedData::CodedData(const AVPacket& avPacket)
: _avStream(NULL)
{
copyAVPacket(avPacket);
}

Frame::Frame(const Frame& other)
CodedData::CodedData(const CodedData& other)
{
copyAVPacket(other.getAVPacket());
_avStream = other.getAVStream();
}

Frame& Frame::operator=(const Frame& other)
CodedData& CodedData::operator=(const CodedData& other)
{
copyAVPacket(other.getAVPacket());
_avStream = other.getAVStream();
return *this;
}

Frame::~Frame()
CodedData::~CodedData()
{
av_free_packet(&_packet);
}

void Frame::resize(const size_t newSize)
void CodedData::resize(const size_t newSize)
{
if((int)newSize < _packet.size)
av_shrink_packet(&_packet, newSize);
else if((int)newSize > _packet.size)
av_grow_packet(&_packet, newSize - _packet.size);
}

void Frame::refData(unsigned char* buffer, const size_t size)
void CodedData::refData(unsigned char* buffer, const size_t size)
{
_packet.data = buffer;
_packet.size = size;
}

void Frame::copyData(unsigned char* buffer, const size_t size)
void CodedData::copyData(unsigned char* buffer, const size_t size)
{
resize(size);
if(size != 0)
memcpy(_packet.data, buffer, _packet.size);
}

void Frame::refData(Frame& frame)
void CodedData::refData(CodedData& frame)
{
_packet.data = frame.getData();
_packet.size = frame.getSize();
}

void Frame::clear()
void CodedData::clear()
{
av_free_packet(&_packet);
initAVPacket();
}

void Frame::assign(const size_t size, const int value)
void CodedData::assign(const size_t size, const int value)
{
resize(size);
memset(_packet.data, value, size);
}

void Frame::initAVPacket()
void CodedData::initAVPacket()
{
av_init_packet(&_packet);
_packet.data = NULL;
_packet.size = 0;
}

void Frame::copyAVPacket(const AVPacket& avPacket)
void CodedData::copyAVPacket(const AVPacket& avPacket)
{
#if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVCODEC_VERSION_INT > AV_VERSION_INT(54, 56, 0)
// Need const_cast<AVCodec*> for libav versions from 54.56. to 55.56.
Expand Down
Loading