1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

add ffmpeg transcoding framework

This commit is contained in:
winlin 2013-11-30 18:31:07 +08:00
parent b1466c8883
commit 8d91561ca0
9 changed files with 161 additions and 1 deletions

View file

@ -20,6 +20,7 @@ vhost __defaultVhost__ {
enabled on; enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg; ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine fd{ engine fd{
enabled on;
vcodec libx264; vcodec libx264;
vbitrate 300; vbitrate 300;
vfps 20; vfps 20;
@ -47,9 +48,12 @@ vhost all.transcode.vhost.com {
enabled on; enabled on;
# the ffmpeg # the ffmpeg
ffmpeg ./objs/ffmpeg/bin/ffmpeg; ffmpeg ./objs/ffmpeg/bin/ffmpeg;
# the transcode engine for matched stream.
# all matched stream will transcoded to the following stream. # all matched stream will transcoded to the following stream.
# the transcode set name(ie. hd) is optional and not used. # the transcode set name(ie. hd) is optional and not used.
engine super{ engine super{
# whether the engine is enabled
enabled on;
# video encoder name # video encoder name
vcodec libx264; vcodec libx264;
# video bitrate, in kbps # video bitrate, in kbps
@ -92,6 +96,7 @@ vhost all.transcode.vhost.com {
output rtmp://[vhost]:[port]/[app]/[stream]_super; output rtmp://[vhost]:[port]/[app]/[stream]_super;
} }
engine hd{ engine hd{
enabled on;
vcodec libx264; vcodec libx264;
vbitrate 1200; vbitrate 1200;
vfps 25; vfps 25;
@ -111,6 +116,7 @@ vhost all.transcode.vhost.com {
output rtmp://[vhost]:[port]/[app]/[stream]_hd; output rtmp://[vhost]:[port]/[app]/[stream]_hd;
} }
engine sd{ engine sd{
enabled on;
vcodec libx264; vcodec libx264;
vbitrate 800; vbitrate 800;
vfps 25; vfps 25;
@ -130,6 +136,7 @@ vhost all.transcode.vhost.com {
output rtmp://[vhost]:[port]/[app]/[stream]_sd; output rtmp://[vhost]:[port]/[app]/[stream]_sd;
} }
engine fast{ engine fast{
enabled on;
vcodec libx264; vcodec libx264;
vbitrate 300; vbitrate 300;
vfps 20; vfps 20;
@ -150,6 +157,30 @@ vhost all.transcode.vhost.com {
} }
} }
} }
# transcode all app and stream of app
vhost app.transcode.vhost.com {
# the streaming transcode configs.
# if app specified, transcode all streams of app.
transcode live {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine fd{
enabled off;
}
}
}
# transcode specified stream.
vhost stream.transcode.vhost.com {
# the streaming transcode configs.
# if stream specified, transcode the matched stream.
transcode live/livestream {
enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
engine fd{
enabled off;
}
}
}
# the vhost which forward publish streams. # the vhost which forward publish streams.
vhost forward.vhost.com { vhost forward.vhost.com {
# forward all publish stream to the specified server. # forward all publish stream to the specified server.

2
trunk/configure vendored
View file

@ -98,7 +98,7 @@ MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server"
"srs_core_stream" "srs_core_source" "srs_core_codec" "srs_core_stream" "srs_core_source" "srs_core_codec"
"srs_core_handshake" "srs_core_pithy_print" "srs_core_handshake" "srs_core_pithy_print"
"srs_core_config" "srs_core_refer" "srs_core_reload" "srs_core_config" "srs_core_refer" "srs_core_reload"
"srs_core_hls" "srs_core_forward") "srs_core_hls" "srs_core_forward" "srs_core_encoder")
MODULE_DIR="src/core" . auto/modules.sh MODULE_DIR="src/core" . auto/modules.sh
CORE_OBJS="${MODULE_OBJS[@]}" CORE_OBJS="${MODULE_OBJS[@]}"

View file

@ -568,6 +568,17 @@ SrsConfDirective* SrsConfig::get_vhost_enabled(std::string vhost)
return conf->get("enabled"); return conf->get("enabled");
} }
SrsConfDirective* SrsConfig::get_transcode(std::string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("transcode");
}
SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost) SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);
@ -732,6 +743,7 @@ int SrsConfig::parse_file(const char* filename)
// TODO: check other config. // TODO: check other config.
// TODO: check hls. // TODO: check hls.
// TODO: check ssl. // TODO: check ssl.
// TODO: check ffmpeg.
return ret; return ret;
} }

View file

@ -114,6 +114,7 @@ public:
virtual int parse_options(int argc, char** argv); virtual int parse_options(int argc, char** argv);
virtual SrsConfDirective* get_vhost(std::string vhost); virtual SrsConfDirective* get_vhost(std::string vhost);
virtual SrsConfDirective* get_vhost_enabled(std::string vhost); virtual SrsConfDirective* get_vhost_enabled(std::string vhost);
virtual SrsConfDirective* get_transcode(std::string vhost);
virtual SrsConfDirective* get_gop_cache(std::string vhost); virtual SrsConfDirective* get_gop_cache(std::string vhost);
virtual SrsConfDirective* get_forward(std::string vhost); virtual SrsConfDirective* get_forward(std::string vhost);
virtual SrsConfDirective* get_hls(std::string vhost); virtual SrsConfDirective* get_hls(std::string vhost);

View file

@ -0,0 +1,46 @@
/*
The MIT License (MIT)
Copyright (c) 2013 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_core_encoder.hpp>
#include <srs_core_error.hpp>
#include <srs_core_log.hpp>
SrsEncoder::SrsEncoder()
{
}
SrsEncoder::~SrsEncoder()
{
}
int SrsEncoder::on_publish(std::string vhost, std::string app, std::string stream)
{
int ret = ERROR_SUCCESS;
return ret;
}
void SrsEncoder::on_unpublish()
{
}

View file

@ -0,0 +1,44 @@
/*
The MIT License (MIT)
Copyright (c) 2013 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_CORE_ENCODER_HPP
#define SRS_CORE_ENCODER_HPP
/*
#include <srs_core_encoder.hpp>
*/
#include <srs_core.hpp>
#include <string>
class SrsEncoder
{
public:
SrsEncoder();
virtual ~SrsEncoder();
public:
virtual int on_publish(std::string vhost, std::string app, std::string stream);
virtual void on_unpublish();
};
#endif

View file

@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_hls.hpp> #include <srs_core_hls.hpp>
#include <srs_core_forward.hpp> #include <srs_core_forward.hpp>
#include <srs_core_config.hpp> #include <srs_core_config.hpp>
#include <srs_core_encoder.hpp>
#define CONST_MAX_JITTER_MS 500 #define CONST_MAX_JITTER_MS 500
#define DEFAULT_FRAME_TIME_MS 10 #define DEFAULT_FRAME_TIME_MS 10
@ -354,6 +355,9 @@ SrsSource::SrsSource(std::string _stream_url)
#ifdef SRS_HLS #ifdef SRS_HLS
hls = new SrsHls(); hls = new SrsHls();
#endif #endif
#ifdef SRS_FFMPEG
encoder = new SrsEncoder();
#endif
cache_metadata = cache_sh_video = cache_sh_audio = NULL; cache_metadata = cache_sh_video = cache_sh_audio = NULL;
@ -392,6 +396,9 @@ SrsSource::~SrsSource()
#ifdef SRS_HLS #ifdef SRS_HLS
srs_freep(hls); srs_freep(hls);
#endif #endif
#ifdef SRS_FFMPEG
srs_freep(encoder);
#endif
} }
bool SrsSource::can_publish() bool SrsSource::can_publish()
@ -617,6 +624,12 @@ int SrsSource::on_publish(std::string vhost, std::string app, std::string stream
} }
#endif #endif
#ifdef SRS_FFMPEG
if ((ret = encoder->on_publish(vhost, app, stream)) != ERROR_SUCCESS) {
return ret;
}
#endif
// TODO: support reload. // TODO: support reload.
// create forwarders // create forwarders
@ -645,6 +658,10 @@ void SrsSource::on_unpublish()
hls->on_unpublish(); hls->on_unpublish();
#endif #endif
#ifdef SRS_FFMPEG
encoder->on_unpublish();
#endif
// close all forwarders // close all forwarders
std::vector<SrsForwarder*>::iterator it; std::vector<SrsForwarder*>::iterator it;
for (it = forwarders.begin(); it != forwarders.end(); ++it) { for (it = forwarders.begin(); it != forwarders.end(); ++it) {

View file

@ -42,6 +42,9 @@ class SrsForwarder;
#ifdef SRS_HLS #ifdef SRS_HLS
class SrsHls; class SrsHls;
#endif #endif
#ifdef SRS_FFMPEG
class SrsEncoder;
#endif
/** /**
* time jitter detect and correct, * time jitter detect and correct,
@ -171,6 +174,10 @@ private:
// hls handler. // hls handler.
#ifdef SRS_HLS #ifdef SRS_HLS
SrsHls* hls; SrsHls* hls;
#endif
// transcoding handler.
#ifdef SRS_FFMPEG
SrsEncoder* encoder;
#endif #endif
// gop cache for client fast startup. // gop cache for client fast startup.
SrsGopCache* gop_cache; SrsGopCache* gop_cache;

View file

@ -26,6 +26,8 @@ file
..\core\srs_core_source.cpp, ..\core\srs_core_source.cpp,
..\core\srs_core_forward.hpp, ..\core\srs_core_forward.hpp,
..\core\srs_core_forward.cpp, ..\core\srs_core_forward.cpp,
..\core\srs_core_encoder.hpp,
..\core\srs_core_encoder.cpp,
..\core\srs_core_hls.hpp, ..\core\srs_core_hls.hpp,
..\core\srs_core_hls.cpp, ..\core\srs_core_hls.cpp,
..\core\srs_core_codec.hpp, ..\core\srs_core_codec.hpp,