Skip to content

Add feature: set frame #124

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

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
30851a7
AudioCodec: refactore getters
Oct 31, 2014
01c9b19
VideoCodec: refactore getVideoFrameDesc
Oct 31, 2014
1c78636
Generators: add documentation for attributes
Oct 31, 2014
4ca6256
GeneratorVideo: throw exception if no codec
Oct 31, 2014
b91fc30
AvOutputVideo: clean encodeFrame
Oct 31, 2014
1869f4a
VideoFrame: setPixel takes a reference
Oct 31, 2014
7c885d3
Context: add typedef to manipulate options
Oct 31, 2014
2e6fd67
util: add typedef OptionArrayMap
Oct 31, 2014
afe3e4e
util: clean getPixel/Sample functions
Oct 31, 2014
00380fe
VideoTransform: clean init
Oct 31, 2014
51b0eae
Transcoder: remove add( StreamTranscoder& stream )
Oct 31, 2014
2f2e0ff
StreamTranscoder: update verbose of processTranscode with a subStream…
Oct 31, 2014
6946e6c
Transcoder: add getter to a specific stream
Oct 31, 2014
6817680
pyTest: add script to test setFrame during process
Oct 31, 2014
ed286b5
StreamTranscoder: add a more explicit messages when verbose
Nov 3, 2014
3644883
Transcoder: rename getStream to getStreamTranscoder
Nov 3, 2014
d2dd12a
pyTest: add a blanck line at the end of files
Nov 3, 2014
221e11b
AvInputStream: remove getPacketDuration
Oct 24, 2014
c90265e
Transcoder: remove _outputFps attribute
Oct 27, 2014
b323fbc
AvInputAudio: rename getNextFrame to decodeNextFrame
Oct 27, 2014
a1992c0
AvInputVideo: check decodedSize
Oct 27, 2014
abe853e
StreamTranscoder: clean documentation of attributes
Oct 27, 2014
f3989c0
AvInputVideo / Audio: add documentation for attributes
Nov 3, 2014
f0ae2a2
AvInputVideo / Audio: fix _selectedStream
Nov 3, 2014
76e9ba7
AvInputVideo / Audio: has a link to the video / audio codec (decoder)
Nov 3, 2014
41e4cec
AvInputVideo: refactore readNextFrame
Nov 3, 2014
9872976
AvInputStream: add documentation for attributes
Nov 3, 2014
fb946f2
AvOutputStream: add documentation for attributes
Nov 3, 2014
0b71d40
Generator Video / Audio: remove _codec
Nov 3, 2014
11fa67f
util: fix getFormats Long / Short Names
Nov 3, 2014
b2aded2
Transcoder: add method add( StreamTranscoder& stream )
Nov 3, 2014
5ddc7b4
IInputEssence: add documentation for setFrame
Nov 3, 2014
8de2912
Transcoder: refactore - get only one addTranscodeStream private method
Nov 3, 2014
fc4673f
Transcoder: refactore addDummyStream
Nov 3, 2014
75d054e
GeneratorVideo: remove unused _numberOfView attribute
Nov 3, 2014
c55bef7
Generator Video / Audio: add get Video / Audio FrameDesc
Nov 3, 2014
3ff6616
Option: refactore getDefaultRatio
Nov 5, 2014
e5e706e
Swig: add Generators in bindings
Nov 5, 2014
1b0235f
StreamTranscoder: constructor can take an IInputEssence
Nov 5, 2014
c4b94c8
Merge branch 'master' of https://github.com/avTranscoder/avTranscoder…
Nov 6, 2014
4a7a779
Merge branch 'master' of https://github.com/avTranscoder/avTranscoder…
Nov 20, 2014
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
1 change: 0 additions & 1 deletion app/genericProcessor/genericProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ int main( int argc, char** argv )
// set verbose of all stream
transcoder.setVerbose( verbose );
transcoder.setProcessMethod( avtranscoder::eProcessMethodLongest );
//transcoder.setOutputFps( 12 );
transcoder.init();

if( verbose )
Expand Down
2 changes: 1 addition & 1 deletion app/presetChecker/presetChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main( int argc, char** argv )
if( profile.find( avtranscoder::constants::avProfileType )->second == avtranscoder::constants::avProfileTypeAudio )
{
avtranscoder::AvOutputAudio outputAudio;
outputAudio.setProfile( profile, outputAudio.getAudioCodec().getFrameDesc() );
outputAudio.setProfile( profile, outputAudio.getAudioCodec().getAudioFrameDesc() );
}
}
catch( ... )
Expand Down
5 changes: 5 additions & 0 deletions src/AvTranscoder/avTranscoder.i
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <AvTranscoder/essenceStream/IInputEssence.hpp>
#include <AvTranscoder/essenceStream/AvInputAudio.hpp>
#include <AvTranscoder/essenceStream/AvInputVideo.hpp>
#include <AvTranscoder/essenceStream/GeneratorVideo.hpp>
#include <AvTranscoder/essenceStream/GeneratorAudio.hpp>

#include <AvTranscoder/file/InputFile.hpp>
#include <AvTranscoder/file/OutputFile.hpp>
Expand All @@ -59,6 +61,7 @@ namespace std {
%template(ChannelVector) vector< avtranscoder::Channel >;
%template(ProfileMap) map< string, string >;
%template(ProfilesVector) vector< map< string, string > >;
%template(DataBuffer) std::vector< unsigned char >;
}

%include "AvTranscoder/progress/progress.i"
Expand Down Expand Up @@ -90,6 +93,8 @@ namespace std {
%include <AvTranscoder/essenceStream/IInputEssence.hpp>
%include <AvTranscoder/essenceStream/AvInputAudio.hpp>
%include <AvTranscoder/essenceStream/AvInputVideo.hpp>
%include <AvTranscoder/essenceStream/GeneratorVideo.hpp>
%include <AvTranscoder/essenceStream/GeneratorAudio.hpp>

%include <AvTranscoder/file/InputFile.hpp>
%include <AvTranscoder/file/OutputFile.hpp>
Expand Down
20 changes: 1 addition & 19 deletions src/AvTranscoder/codec/AudioCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AudioCodec::AudioCodec( const ICodec& codec )
{
}

AudioFrameDesc AudioCodec::getFrameDesc() const
AudioFrameDesc AudioCodec::getAudioFrameDesc() const
{
assert( _codecContext != NULL );
AudioFrameDesc audioFrameDesc;
Expand All @@ -33,24 +33,6 @@ AudioFrameDesc AudioCodec::getFrameDesc() const
return audioFrameDesc;
}

const size_t AudioCodec::getSampleRate() const
{
assert( _codecContext != NULL );
return _codecContext->sample_rate;
}

const size_t AudioCodec::getChannels() const
{
assert( _codecContext != NULL );
return _codecContext->channels;
}

const AVSampleFormat AudioCodec::getAVSampleFormat() const
{
assert( _codecContext != NULL );
return _codecContext->sample_fmt;
}

void AudioCodec::setAudioParameters( const AudioFrameDesc& audioFrameDesc )
{
setAudioParameters( audioFrameDesc.getSampleRate(), audioFrameDesc.getChannels(), audioFrameDesc.getAVSampleFormat() );
Expand Down
7 changes: 2 additions & 5 deletions src/AvTranscoder/codec/AudioCodec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ class AvExport AudioCodec : public ICodec
AudioCodec( const ECodecType type, const AVCodecID codecId );
AudioCodec( const ICodec& codec );

AudioFrameDesc getFrameDesc() const;
const size_t getSampleRate() const;
const size_t getChannels() const;
const AVSampleFormat getAVSampleFormat() const;

AudioFrameDesc getAudioFrameDesc() const;

void setAudioParameters( const AudioFrameDesc& audioFrameDesc );
void setAudioParameters( const size_t sampleRate, const size_t channels, const AVSampleFormat sampleFormat );
};
Expand Down
14 changes: 8 additions & 6 deletions src/AvTranscoder/codec/VideoCodec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ VideoCodec::VideoCodec( const ICodec& codec )
VideoFrameDesc VideoCodec::getVideoFrameDesc() const
{
assert( _codecContext != NULL );
VideoFrameDesc VideoFrameDesc;

VideoFrameDesc videoFrameDesc;
videoFrameDesc.setWidth ( _codecContext->width );
videoFrameDesc.setHeight( _codecContext->height );
videoFrameDesc.setDar( _codecContext->width, _codecContext->height );

Pixel pixel( _codecContext->pix_fmt );
videoFrameDesc.setPixel( pixel );

VideoFrameDesc.setWidth ( _codecContext->width );
VideoFrameDesc.setHeight( _codecContext->height );
VideoFrameDesc.setPixel ( pixel );
VideoFrameDesc.setDar ( _codecContext->height, _codecContext->width );
return VideoFrameDesc;
return videoFrameDesc;
}

std::pair< size_t, size_t > VideoCodec::getTimeBase() const
Expand Down
7 changes: 0 additions & 7 deletions src/AvTranscoder/codedStream/AvInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ AvInputStream::AvInputStream( InputFile& inputFile, const size_t streamIndex )
: IInputStream( )
, _inputFile( &inputFile )
, _codec( NULL )
, _packetDuration( 0 )
, _streamIndex( streamIndex )
, _bufferized( false )
{
Expand Down Expand Up @@ -98,7 +97,6 @@ void AvInputStream::addPacket( AVPacket& packet )
//std::cout << "add packet for stream " << _streamIndex << std::endl;
CodedData data;
_streamCache.push_back( data );
_packetDuration = packet.duration;

if( ! _bufferized )
return;
Expand Down Expand Up @@ -166,11 +164,6 @@ double AvInputStream::getDuration() const
return 1.0 * _inputFile->getFormatContext().duration / AV_TIME_BASE;
}

double AvInputStream::getPacketDuration() const
{
return _packetDuration * av_q2d( _inputFile->getFormatContext().streams[_streamIndex]->time_base );
}

void AvInputStream::clearBuffering()
{
_streamCache.clear();
Expand Down
12 changes: 5 additions & 7 deletions src/AvTranscoder/codedStream/AvInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class AvExport AvInputStream : public IInputStream
AVMediaType getStreamType() const;

double getDuration() const;
double getPacketDuration() const;

void addPacket( AVPacket& packet );

Expand All @@ -43,14 +42,13 @@ class AvExport AvInputStream : public IInputStream
AVStream* getAVStream() const;

private:
InputFile* _inputFile;
std::vector<CodedData> _streamCache;

InputFile* _inputFile; ///< Has link (no ownership)
ICodec* _codec; ///< Has ownership

int _packetDuration;
size_t _streamIndex;
bool _bufferized;
std::vector<CodedData> _streamCache;

size_t _streamIndex; ///< Index of the stream in the input file
bool _bufferized; ///< If the stream is bufferized
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/AvTranscoder/codedStream/AvOutputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class AvExport AvOutputStream : public IOutputStream
bool wrap( const CodedData& data );

private:
OutputFile* _outputFile;
OutputFile* _outputFile; ///< Has link (no ownership)

size_t _streamIndex;
size_t _streamIndex; ///< Index of the stream in the output file
};

}
Expand Down
1 change: 0 additions & 1 deletion src/AvTranscoder/codedStream/IInputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class IInputStream
virtual AVMediaType getStreamType() const = 0;

virtual double getDuration() const = 0;
virtual double getPacketDuration() const = 0;

virtual void setBufferred( const bool bufferized ) = 0;

Expand Down
24 changes: 12 additions & 12 deletions src/AvTranscoder/essenceStream/AvInputAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace avtranscoder
AvInputAudio::AvInputAudio( AvInputStream& inputStream )
: IInputEssence()
, _inputStream ( &inputStream )
, _codec( eCodecTypeDecoder, inputStream.getAudioCodec().getCodecId() )
, _codec( &inputStream.getAudioCodec() )
, _frame ( NULL )
, _selectedStream( -1 )
, _selectedStream( inputStream.getStreamIndex() )
{
}

Expand All @@ -46,10 +46,10 @@ AvInputAudio::~AvInputAudio()

void AvInputAudio::setup()
{
AVCodecContext* avCodecContext = _codec.getAVCodecContext();
AVCodec* avCodec = _codec.getAVCodec();
AVCodecContext* avCodecContext = _codec->getAVCodecContext();
AVCodec* avCodec = _codec->getAVCodec();

avCodecContext->channels = _inputStream->getAudioCodec().getChannels();
avCodecContext->channels = _inputStream->getAudioCodec().getAudioFrameDesc().getChannels();

int ret = avcodec_open2( avCodecContext, avCodec, NULL );

Expand Down Expand Up @@ -82,10 +82,10 @@ void AvInputAudio::setup()

bool AvInputAudio::readNextFrame( Frame& frameBuffer )
{
if( ! getNextFrame() )
if( ! decodeNextFrame() )
return false;

AVCodecContext* avCodecContext = _codec.getAVCodecContext();
AVCodecContext* avCodecContext = _codec->getAVCodecContext();

size_t decodedSize = av_samples_get_buffer_size(
NULL, avCodecContext->channels,
Expand Down Expand Up @@ -116,14 +116,14 @@ bool AvInputAudio::readNextFrame( Frame& frameBuffer )

bool AvInputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex )
{
if( ! getNextFrame() )
if( ! decodeNextFrame() )
return false;

const int output_nbChannels = 1;
const int output_align = 1;
size_t decodedSize = av_samples_get_buffer_size(NULL, output_nbChannels, _frame->nb_samples, _codec.getAVCodecContext()->sample_fmt, output_align);
size_t decodedSize = av_samples_get_buffer_size(NULL, output_nbChannels, _frame->nb_samples, _codec->getAVCodecContext()->sample_fmt, output_align);

size_t nbSubStreams = _codec.getAVCodecContext()->channels;
size_t nbSubStreams = _codec->getAVCodecContext()->channels;
size_t bytePerSample = av_get_bytes_per_sample( (AVSampleFormat)_frame->format );

if( subStreamIndex > nbSubStreams - 1 )
Expand Down Expand Up @@ -156,7 +156,7 @@ bool AvInputAudio::readNextFrame( Frame& frameBuffer, const size_t subStreamInde
return true;
}

bool AvInputAudio::getNextFrame()
bool AvInputAudio::decodeNextFrame()
{
int got_frame = 0;
while( ! got_frame )
Expand All @@ -172,7 +172,7 @@ bool AvInputAudio::getNextFrame()
packet.data = data.getPtr();
packet.size = data.getSize();

int ret = avcodec_decode_audio4( _codec.getAVCodecContext(), _frame, &got_frame, &packet );
int ret = avcodec_decode_audio4( _codec->getAVCodecContext(), _frame, &got_frame, &packet );

if( ret < 0 )
{
Expand Down
10 changes: 5 additions & 5 deletions src/AvTranscoder/essenceStream/AvInputAudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class AvExport AvInputAudio : public IInputEssence
bool readNextFrame( Frame& frameBuffer, const size_t subStreamIndex );

private:
bool getNextFrame();
bool decodeNextFrame();

AvInputStream* _inputStream;
AudioCodec _codec;
AVFrame* _frame;
AvInputStream* _inputStream; ///< Stream from which we read next frames
const AudioCodec* _codec; ///< Audio decoder. Has link (no ownership)
AVFrame* _frame; ///< Libav object to store decoded data

int _selectedStream;
int _selectedStream; ///< Index of the selected stream in the input file
};

}
Expand Down
57 changes: 33 additions & 24 deletions src/AvTranscoder/essenceStream/AvInputVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ namespace avtranscoder
AvInputVideo::AvInputVideo( AvInputStream& inputStream )
: IInputEssence()
, _inputStream ( &inputStream )
, _codec( eCodecTypeDecoder, inputStream.getVideoCodec().getCodecId() )
, _codec( &inputStream.getVideoCodec() )
, _frame ( NULL )
, _selectedStream( -1 )
, _selectedStream( inputStream.getStreamIndex() )
{
}

Expand All @@ -45,8 +45,8 @@ AvInputVideo::~AvInputVideo()

void AvInputVideo::setup()
{
AVCodecContext* avCodecContext = _codec.getAVCodecContext();
AVCodec* avCodec = _codec.getAVCodec();
AVCodecContext* avCodecContext = _codec->getAVCodecContext();
AVCodec* avCodec = _codec->getAVCodec();

// if( avCodec->capabilities & CODEC_CAP_TRUNCATED )
// avCodecContext->flags |= CODEC_FLAG_TRUNCATED;
Expand Down Expand Up @@ -77,12 +77,36 @@ void AvInputVideo::setup()

bool AvInputVideo::readNextFrame( Frame& frameBuffer )
{
int got_frame = 0;
if( ! decodeNextFrame() )
return false;

VideoFrame& imageBuffer = static_cast<VideoFrame&>( frameBuffer );

size_t decodedSize = avpicture_get_size( (AVPixelFormat)_frame->format, _frame->width, _frame->height );
if( ! decodedSize )
return false;

if( imageBuffer.getBuffer().size() != decodedSize )
imageBuffer.getBuffer().resize( decodedSize );

// Copy pixel data from an AVPicture into one contiguous buffer.
avpicture_layout( (AVPicture*)_frame, (AVPixelFormat)_frame->format, _frame->width, _frame->height, &imageBuffer.getBuffer()[0], frameBuffer.getBuffer().size() );

return true;
}

bool AvInputVideo::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex )
{
return false;
}

bool AvInputVideo::decodeNextFrame()
{
int got_frame = 0;
while( ! got_frame )
{
CodedData data;
if( ! _inputStream->readNextPacket( data ) )
if( ! _inputStream->readNextPacket( data ) ) // error or end of file
return false;

AVPacket packet;
Expand All @@ -92,7 +116,7 @@ bool AvInputVideo::readNextFrame( Frame& frameBuffer )
packet.data = data.getPtr();
packet.size = data.getSize();

int ret = avcodec_decode_video2( _codec.getAVCodecContext(), _frame, &got_frame, &packet );
int ret = avcodec_decode_video2( _codec->getAVCodecContext(), _frame, &got_frame, &packet );

if( ret < 0 )
{
Expand All @@ -104,32 +128,17 @@ bool AvInputVideo::readNextFrame( Frame& frameBuffer )

av_free_packet( &packet );
}

VideoFrame& imageBuffer = static_cast<VideoFrame&>( frameBuffer );

size_t decodedSize = avpicture_get_size( (AVPixelFormat)_frame->format, _frame->width, _frame->height );
if( imageBuffer.getBuffer().size() != decodedSize )
imageBuffer.getBuffer().resize( decodedSize );

// Copy pixel data from an AVPicture into one contiguous buffer.
avpicture_layout( (AVPicture*)_frame, (AVPixelFormat)_frame->format, _frame->width, _frame->height, &imageBuffer.getBuffer()[0], frameBuffer.getBuffer().size() );

return true;
}

bool AvInputVideo::readNextFrame( Frame& frameBuffer, const size_t subStreamIndex )
{
return false;
}

void AvInputVideo::flushDecoder()
{
avcodec_flush_buffers( _codec.getAVCodecContext() );
avcodec_flush_buffers( _codec->getAVCodecContext() );
}

void AvInputVideo::setProfile( const ProfileLoader::Profile& profile )
{
Context codecContext( _codec.getAVCodecContext() );
Context codecContext( _codec->getAVCodecContext() );

for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
{
Expand Down
Loading