diff --git a/CMakeLists.txt b/CMakeLists.txt index c98e874..3b4ea29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,6 @@ link_directories(${FFMPEG_LIBRARY_DIRS}) #message(FATAL_ERROR ${FFMPEG_LIBRARIES}) -set(SOURCE_FILES main.cpp ffcpp/MediaFile.cpp ffcpp/MediaFile.h ffcpp/ffcpp.cpp ffcpp/ffcpp.h ffcpp/Stream.cpp ffcpp/Stream.h ffcpp/Codec.cpp ffcpp/Codec.h ffcpp/Packet.cpp ffcpp/Packet.h ffcpp/Frame.cpp ffcpp/Frame.h ffcpp/FifoQueue.cpp ffcpp/FifoQueue.h ffcpp/Scaler.cpp ffcpp/Scaler.h) +set(SOURCE_FILES main.cpp ffcpp/MediaFile.cpp ffcpp/MediaFile.h ffcpp/ffcpp.cpp ffcpp/ffcpp.h ffcpp/Stream.cpp ffcpp/Stream.h ffcpp/Codec.cpp ffcpp/Codec.h ffcpp/Packet.cpp ffcpp/Packet.h ffcpp/Frame.cpp ffcpp/Frame.h ffcpp/FifoQueue.cpp ffcpp/FifoQueue.h ffcpp/Scaler.cpp ffcpp/Scaler.h ffcpp/Resampler.cpp ffcpp/Resampler.h) add_executable(ffConv ${SOURCE_FILES}) target_link_libraries(ffConv ${FFMPEG_LIBRARIES}) \ No newline at end of file diff --git a/ffcpp/Frame.cpp b/ffcpp/Frame.cpp index 59e9405..6653d93 100644 --- a/ffcpp/Frame.cpp +++ b/ffcpp/Frame.cpp @@ -20,16 +20,6 @@ namespace ffcpp { } Frame::Frame(int width, int height, AVPixelFormat pixelFormat): Frame() { - - /* - _frame->width = width; - _frame->height = height; - _frame->format = pixelFormat; - - int res = av_frame_get_buffer(_frame, 0); - throwIfError(res, "cannot initialize buffer in video frame"); - */ - _frame->width = width; _frame->height = height; _frame->format = pixelFormat; diff --git a/ffcpp/Resampler.cpp b/ffcpp/Resampler.cpp new file mode 100644 index 0000000..9ed9e75 --- /dev/null +++ b/ffcpp/Resampler.cpp @@ -0,0 +1,39 @@ +#include "Resampler.h" +#include "ffcpp.h" +#include + +extern "C" { + #include +} + +namespace ffcpp { + + Resampler::Resampler(int inChannelLayout, int inSampleRate, AVSampleFormat inSampleFormat, int outChannelLayout, + int outSampleRate, AVSampleFormat outSampleFormat) { + _swrContext = swr_alloc(); + if(!_swrContext) { + throw new std::runtime_error("cannot create resampler"); + } + + av_opt_set_int(_swrContext, "in_channel_layout", inChannelLayout, 0); + av_opt_set_int(_swrContext, "in_sample_rate", inSampleRate, 0); + av_opt_set_sample_fmt(_swrContext, "in_sample_fmt", inSampleFormat, 0); + + av_opt_set_int(_swrContext, "out_channel_layout", outChannelLayout, 0); + av_opt_set_int(_swrContext, "out_sample_rate", outSampleRate, 0); + av_opt_set_sample_fmt(_swrContext, "out_sample_fmt", outSampleFormat, 0); + + int res = swr_init(_swrContext); + throwIfError(res, "cannot init resampler"); + } + + Resampler::~Resampler() { + if(_swrContext) { + swr_free(&_swrContext); + } + } + + Frame Resampler::Resample(Frame& inFrame) { + return Frame(); + } +} diff --git a/ffcpp/Resampler.h b/ffcpp/Resampler.h new file mode 100644 index 0000000..ab08691 --- /dev/null +++ b/ffcpp/Resampler.h @@ -0,0 +1,26 @@ +#ifndef FFCONV_RESAMPLER_H +#define FFCONV_RESAMPLER_H + +#include "Frame.h" + +extern "C" { + #include +} + +namespace ffcpp { + + class Resampler { + private: + SwrContext* _swrContext; + + public: + Resampler(int inChannelLayout, int inSampleRate, AVSampleFormat inSampleFormat, + int outChannelLayout, int outSampleRate, AVSampleFormat outSampleFormat); + ~Resampler(); + + Frame Resample(Frame& inFrame); + }; + +} + +#endif //FFCONV_RESAMPLER_H diff --git a/main.cpp b/main.cpp index d6443f2..42d78e6 100644 --- a/main.cpp +++ b/main.cpp @@ -59,7 +59,6 @@ int main(int argc, char** argv) { while(auto packet = input.readPacket()) { AVMediaType packetType = input.packetType(packet); if(packetType == AVMEDIA_TYPE_AUDIO) { - continue; auto frame = aDecoder.decode(packet); fifo.addSamples(frame); if(!fifo.enoughSamples()) continue; @@ -88,7 +87,7 @@ int main(int argc, char** argv) { } flushEncoder(output, vEncoder, vStream, outVStream, VIDEO_STREAM_INDEX); - //flushEncoder(output, aEncoder, aStream, outAStream, AUDIO_STREAM_INDEX); + flushEncoder(output, aEncoder, aStream, outAStream, AUDIO_STREAM_INDEX); output.writeTrailer(); return 0;