Permalink
Browse files

transcode: added initial implementation of the transcoding, so far on…

…ly mp3->mp4(aac) has been tested
  • Loading branch information...
bioothod committed Jun 7, 2016
1 parent 62a778a commit 2c378e8644176fde220bb6689ceed4f38d4832a1
View
@@ -14,38 +14,56 @@ string(REGEX MATCH "([0-9]+\\.[0-9]+$)" NULLA_VERSION_MINOR "${DEBFULLVERSION}")
include(cmake/locate_library.cmake)
+LOCATE_LIBRARY(AVCODEC "libavcodec/avcodec.h" "avcodec" "ffmpeg")
+LOCATE_LIBRARY(AVFORMAT "libavformat/avformat.h" "avformat" "ffmpeg")
+LOCATE_LIBRARY(AVFILTER "libavfilter/avfilter.h" "avfilter" "ffmpeg")
+LOCATE_LIBRARY(AVUTIL "libavutil/error.h" "avutil" "ffmpeg")
LOCATE_LIBRARY(CRYPTOPP "cryptopp/cryptlib.h" "cryptopp" "crypto++")
LOCATE_HEADERS(EBUCKET "ebucket/bucket.hpp")
LOCATE_LIBRARY(MSGPACK "msgpack.hpp" "msgpack")
LOCATE_LIBRARY(SWARM "swarm/http_response.hpp" "swarm")
+LOCATE_LIBRARY(SWRESAMPLE "libswresample/swresample.h" "swresample" "ffmpeg")
LOCATE_LIBRARY(THEVOID "thevoid/server.hpp" "thevoid")
find_package(Boost COMPONENTS system thread filesystem program_options REQUIRED)
find_package(Elliptics REQUIRED)
find_package(Greylock REQUIRED)
+find_package(Nulla REQUIRED)
find_package(Ribosome REQUIRED)
include_directories(
"${CMAKE_CURRENT_SOURCE_DIR}/include"
+ ${AVCODEC_INCLUDE_DIRS}
+ ${AVFORMAT_INCLUDE_DIRS}
+ ${AVFILTER_INCLUDE_DIRS}
+ ${AVUTIL_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${CRYPTOPP_INCLUDE_DIRS}
${EBUCKET_INCLUDE_DIRS}
${ELLIPTICS_INCLUDE_DIRS}
${GREYLOCK_INCLUDE_DIRS}
${MSGPACK_INCLUDE_DIRS}
+ ${NULLA_INCLUDE_DIRS}
${RIBOSOME_INCLUDE_DIRS}
${SWARM_INCLUDE_DIRS}
+ ${SWRESAMPLE_INCLUDE_DIRS}
${THEVOID_INCLUDE_DIRS}
)
link_directories(
+ ${AVCODEC_LIBRARY_DIRS}
+ ${AVFORMAT_LIBRARY_DIRS}
+ ${AVFILTER_LIBRARY_DIRS}
+ ${AVUTIL_LIBRARY_DIRS}
${Boost_LIBRARY_DIRS}
${CRYPTOPP_LIBRARY_DIRS}
${EBUCKET_LIBRARY_DIRS}
${ELLIPTICS_LIBRARY_DIRS}
${GREYLOCK_LIBRARY_DIRS}
- ${RIBOSOME_LIBRARY_DIRS}
${MSGPACK_LIBRARY_DIRS}
+ ${NULLA_LIBRARY_DIRS}
+ ${SWRESAMPLE_LIBRARY_DIRS}
+ ${RIBOSOME_LIBRARY_DIRS}
${THEVOID_LIBRARY_DIRS}
)
View
@@ -48,6 +48,7 @@
"meta_bucket": "b1",
"static_root_dir": "/home/zbr/awork/web/broadcast/frontend",
"mime_file": "/etc/mime.types",
- "tmp_dir": "/tmp/nullx_tmp_dir"
+ "tmp_dir": "/tmp/nullx_tmp_dir",
+ "transcoding_workers": 16
}
}
View
@@ -12,6 +12,7 @@ Build-Depends:
libboost-filesystem-dev,
elliptics-dev,
elliptics-client,
+ nulla-dev,
libcrypto++-dev,
libmsgpack-dev,
libswarm3-dev,
@@ -0,0 +1,80 @@
+#pragma once
+
+#include <ribosome/fpool.hpp>
+
+#include <string>
+
+extern "C" {
+#include <libavfilter/avfilter.h>
+#include <libavformat/avformat.h>
+#include <libavutil/audio_fifo.h>
+#include <libswresample/swresample.h>
+}
+
+namespace ioremap { namespace nullx {
+
+class transcoder {
+public:
+ transcoder();
+ ~transcoder();
+
+ int transcode(const std::string &input_file, const std::string &output_file);
+
+private:
+ AVFormatContext *m_ifmt_ctx = NULL;
+ AVFormatContext *m_ofmt_ctx = NULL;
+
+ struct filtering_context {
+ AVFilterContext *buffersink_ctx = NULL;
+ AVFilterContext *buffersrc_ctx = NULL;
+ AVFilterGraph *filter_graph = NULL;
+
+ SwrContext *resample_ctx = NULL;
+ AVAudioFifo *fifo;
+ } *m_filter_ctx = NULL;
+
+ uint64_t pts = 0;
+
+ int open_input_file(const std::string &filename);
+ int open_output_file(const std::string &filename);
+
+ int init_audio_filter(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVFilterGraph *filter_graph,
+ AVFilterContext **buffersrc_ctx, AVFilterContext **buffersink_ctx);
+ int init_video_filter(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVFilterGraph *filter_graph,
+ AVFilterContext **buffersrc_ctx, AVFilterContext **buffersink_ctx);
+
+ int init_resampler(AVCodecContext *input_codec_context, AVCodecContext *output_codec_context, SwrContext **resample_context);
+ int init_fifo(AVAudioFifo **fifo, AVCodecContext *output_codec_context);
+
+ int init_filter(filtering_context* fctx, AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, const char *filter_spec);
+ int init_filters(void);
+
+ int init_converted_samples(uint8_t ***converted_input_samples,
+ AVCodecContext *output_codec_context,
+ int frame_size);
+ int init_output_audio_frame(AVFrame **frame, AVCodecContext *output_codec_context, int frame_size);
+ int convert_and_send_samples(AVFrame *frame, AVCodecContext *output_codec_context, unsigned int stream_index);
+ int read_frame_from_fifo(AVAudioFifo *fifo,
+ AVCodecContext *output_codec_context,
+ AVFrame **frame_ptr);
+
+ int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index);
+ int encode_write_frame(AVFrame *filt_frame, unsigned int stream_index, int *got_frame);
+ int process_frames();
+
+ int flush_encoder(unsigned int stream_index);
+ int flush_filters();
+ int finish();
+};
+
+class transcode_controller {
+public:
+ transcode_controller(int num_workers);
+
+private:
+ ribosome::fpool::controller m_ctl;
+
+ ribosome::fpool::message transcode(const ribosome::fpool::message &msg);
+};
+
+}} // namespace ioremap::nullx
Oops, something went wrong.

0 comments on commit 2c378e8

Please sign in to comment.