正在显示
9 个修改的文件
包含
161 行增加
和
1 行删除
| @@ -20,6 +20,7 @@ vhost __defaultVhost__ { | @@ -20,6 +20,7 @@ vhost __defaultVhost__ { | ||
| 20 | enabled on; | 20 | enabled on; |
| 21 | ffmpeg ./objs/ffmpeg/bin/ffmpeg; | 21 | ffmpeg ./objs/ffmpeg/bin/ffmpeg; |
| 22 | engine fd{ | 22 | engine fd{ |
| 23 | + enabled on; | ||
| 23 | vcodec libx264; | 24 | vcodec libx264; |
| 24 | vbitrate 300; | 25 | vbitrate 300; |
| 25 | vfps 20; | 26 | vfps 20; |
| @@ -47,9 +48,12 @@ vhost all.transcode.vhost.com { | @@ -47,9 +48,12 @@ vhost all.transcode.vhost.com { | ||
| 47 | enabled on; | 48 | enabled on; |
| 48 | # the ffmpeg | 49 | # the ffmpeg |
| 49 | ffmpeg ./objs/ffmpeg/bin/ffmpeg; | 50 | ffmpeg ./objs/ffmpeg/bin/ffmpeg; |
| 51 | + # the transcode engine for matched stream. | ||
| 50 | # all matched stream will transcoded to the following stream. | 52 | # all matched stream will transcoded to the following stream. |
| 51 | # the transcode set name(ie. hd) is optional and not used. | 53 | # the transcode set name(ie. hd) is optional and not used. |
| 52 | engine super{ | 54 | engine super{ |
| 55 | + # whether the engine is enabled | ||
| 56 | + enabled on; | ||
| 53 | # video encoder name | 57 | # video encoder name |
| 54 | vcodec libx264; | 58 | vcodec libx264; |
| 55 | # video bitrate, in kbps | 59 | # video bitrate, in kbps |
| @@ -92,6 +96,7 @@ vhost all.transcode.vhost.com { | @@ -92,6 +96,7 @@ vhost all.transcode.vhost.com { | ||
| 92 | output rtmp://[vhost]:[port]/[app]/[stream]_super; | 96 | output rtmp://[vhost]:[port]/[app]/[stream]_super; |
| 93 | } | 97 | } |
| 94 | engine hd{ | 98 | engine hd{ |
| 99 | + enabled on; | ||
| 95 | vcodec libx264; | 100 | vcodec libx264; |
| 96 | vbitrate 1200; | 101 | vbitrate 1200; |
| 97 | vfps 25; | 102 | vfps 25; |
| @@ -111,6 +116,7 @@ vhost all.transcode.vhost.com { | @@ -111,6 +116,7 @@ vhost all.transcode.vhost.com { | ||
| 111 | output rtmp://[vhost]:[port]/[app]/[stream]_hd; | 116 | output rtmp://[vhost]:[port]/[app]/[stream]_hd; |
| 112 | } | 117 | } |
| 113 | engine sd{ | 118 | engine sd{ |
| 119 | + enabled on; | ||
| 114 | vcodec libx264; | 120 | vcodec libx264; |
| 115 | vbitrate 800; | 121 | vbitrate 800; |
| 116 | vfps 25; | 122 | vfps 25; |
| @@ -130,6 +136,7 @@ vhost all.transcode.vhost.com { | @@ -130,6 +136,7 @@ vhost all.transcode.vhost.com { | ||
| 130 | output rtmp://[vhost]:[port]/[app]/[stream]_sd; | 136 | output rtmp://[vhost]:[port]/[app]/[stream]_sd; |
| 131 | } | 137 | } |
| 132 | engine fast{ | 138 | engine fast{ |
| 139 | + enabled on; | ||
| 133 | vcodec libx264; | 140 | vcodec libx264; |
| 134 | vbitrate 300; | 141 | vbitrate 300; |
| 135 | vfps 20; | 142 | vfps 20; |
| @@ -150,6 +157,30 @@ vhost all.transcode.vhost.com { | @@ -150,6 +157,30 @@ vhost all.transcode.vhost.com { | ||
| 150 | } | 157 | } |
| 151 | } | 158 | } |
| 152 | } | 159 | } |
| 160 | +# transcode all app and stream of app | ||
| 161 | +vhost app.transcode.vhost.com { | ||
| 162 | + # the streaming transcode configs. | ||
| 163 | + # if app specified, transcode all streams of app. | ||
| 164 | + transcode live { | ||
| 165 | + enabled on; | ||
| 166 | + ffmpeg ./objs/ffmpeg/bin/ffmpeg; | ||
| 167 | + engine fd{ | ||
| 168 | + enabled off; | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | +} | ||
| 172 | +# transcode specified stream. | ||
| 173 | +vhost stream.transcode.vhost.com { | ||
| 174 | + # the streaming transcode configs. | ||
| 175 | + # if stream specified, transcode the matched stream. | ||
| 176 | + transcode live/livestream { | ||
| 177 | + enabled on; | ||
| 178 | + ffmpeg ./objs/ffmpeg/bin/ffmpeg; | ||
| 179 | + engine fd{ | ||
| 180 | + enabled off; | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | +} | ||
| 153 | # the vhost which forward publish streams. | 184 | # the vhost which forward publish streams. |
| 154 | vhost forward.vhost.com { | 185 | vhost forward.vhost.com { |
| 155 | # forward all publish stream to the specified server. | 186 | # forward all publish stream to the specified server. |
| @@ -98,7 +98,7 @@ MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" | @@ -98,7 +98,7 @@ MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" | ||
| 98 | "srs_core_stream" "srs_core_source" "srs_core_codec" | 98 | "srs_core_stream" "srs_core_source" "srs_core_codec" |
| 99 | "srs_core_handshake" "srs_core_pithy_print" | 99 | "srs_core_handshake" "srs_core_pithy_print" |
| 100 | "srs_core_config" "srs_core_refer" "srs_core_reload" | 100 | "srs_core_config" "srs_core_refer" "srs_core_reload" |
| 101 | - "srs_core_hls" "srs_core_forward") | 101 | + "srs_core_hls" "srs_core_forward" "srs_core_encoder") |
| 102 | MODULE_DIR="src/core" . auto/modules.sh | 102 | MODULE_DIR="src/core" . auto/modules.sh |
| 103 | CORE_OBJS="${MODULE_OBJS[@]}" | 103 | CORE_OBJS="${MODULE_OBJS[@]}" |
| 104 | 104 |
| @@ -568,6 +568,17 @@ SrsConfDirective* SrsConfig::get_vhost_enabled(std::string vhost) | @@ -568,6 +568,17 @@ SrsConfDirective* SrsConfig::get_vhost_enabled(std::string vhost) | ||
| 568 | return conf->get("enabled"); | 568 | return conf->get("enabled"); |
| 569 | } | 569 | } |
| 570 | 570 | ||
| 571 | +SrsConfDirective* SrsConfig::get_transcode(std::string vhost) | ||
| 572 | +{ | ||
| 573 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 574 | + | ||
| 575 | + if (!conf) { | ||
| 576 | + return NULL; | ||
| 577 | + } | ||
| 578 | + | ||
| 579 | + return conf->get("transcode"); | ||
| 580 | +} | ||
| 581 | + | ||
| 571 | SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost) | 582 | SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost) |
| 572 | { | 583 | { |
| 573 | SrsConfDirective* conf = get_vhost(vhost); | 584 | SrsConfDirective* conf = get_vhost(vhost); |
| @@ -732,6 +743,7 @@ int SrsConfig::parse_file(const char* filename) | @@ -732,6 +743,7 @@ int SrsConfig::parse_file(const char* filename) | ||
| 732 | // TODO: check other config. | 743 | // TODO: check other config. |
| 733 | // TODO: check hls. | 744 | // TODO: check hls. |
| 734 | // TODO: check ssl. | 745 | // TODO: check ssl. |
| 746 | + // TODO: check ffmpeg. | ||
| 735 | 747 | ||
| 736 | return ret; | 748 | return ret; |
| 737 | } | 749 | } |
| @@ -114,6 +114,7 @@ public: | @@ -114,6 +114,7 @@ public: | ||
| 114 | virtual int parse_options(int argc, char** argv); | 114 | virtual int parse_options(int argc, char** argv); |
| 115 | virtual SrsConfDirective* get_vhost(std::string vhost); | 115 | virtual SrsConfDirective* get_vhost(std::string vhost); |
| 116 | virtual SrsConfDirective* get_vhost_enabled(std::string vhost); | 116 | virtual SrsConfDirective* get_vhost_enabled(std::string vhost); |
| 117 | + virtual SrsConfDirective* get_transcode(std::string vhost); | ||
| 117 | virtual SrsConfDirective* get_gop_cache(std::string vhost); | 118 | virtual SrsConfDirective* get_gop_cache(std::string vhost); |
| 118 | virtual SrsConfDirective* get_forward(std::string vhost); | 119 | virtual SrsConfDirective* get_forward(std::string vhost); |
| 119 | virtual SrsConfDirective* get_hls(std::string vhost); | 120 | virtual SrsConfDirective* get_hls(std::string vhost); |
trunk/src/core/srs_core_encoder.cpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#include <srs_core_encoder.hpp> | ||
| 25 | + | ||
| 26 | +#include <srs_core_error.hpp> | ||
| 27 | +#include <srs_core_log.hpp> | ||
| 28 | + | ||
| 29 | +SrsEncoder::SrsEncoder() | ||
| 30 | +{ | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +SrsEncoder::~SrsEncoder() | ||
| 34 | +{ | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +int SrsEncoder::on_publish(std::string vhost, std::string app, std::string stream) | ||
| 38 | +{ | ||
| 39 | + int ret = ERROR_SUCCESS; | ||
| 40 | + return ret; | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +void SrsEncoder::on_unpublish() | ||
| 44 | +{ | ||
| 45 | +} | ||
| 46 | + |
trunk/src/core/srs_core_encoder.hpp
0 → 100644
| 1 | +/* | ||
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_CORE_ENCODER_HPP | ||
| 25 | +#define SRS_CORE_ENCODER_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_core_encoder.hpp> | ||
| 29 | +*/ | ||
| 30 | +#include <srs_core.hpp> | ||
| 31 | + | ||
| 32 | +#include <string> | ||
| 33 | + | ||
| 34 | +class SrsEncoder | ||
| 35 | +{ | ||
| 36 | +public: | ||
| 37 | + SrsEncoder(); | ||
| 38 | + virtual ~SrsEncoder(); | ||
| 39 | +public: | ||
| 40 | + virtual int on_publish(std::string vhost, std::string app, std::string stream); | ||
| 41 | + virtual void on_unpublish(); | ||
| 42 | +}; | ||
| 43 | + | ||
| 44 | +#endif |
| @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | #include <srs_core_hls.hpp> | 33 | #include <srs_core_hls.hpp> |
| 34 | #include <srs_core_forward.hpp> | 34 | #include <srs_core_forward.hpp> |
| 35 | #include <srs_core_config.hpp> | 35 | #include <srs_core_config.hpp> |
| 36 | +#include <srs_core_encoder.hpp> | ||
| 36 | 37 | ||
| 37 | #define CONST_MAX_JITTER_MS 500 | 38 | #define CONST_MAX_JITTER_MS 500 |
| 38 | #define DEFAULT_FRAME_TIME_MS 10 | 39 | #define DEFAULT_FRAME_TIME_MS 10 |
| @@ -354,6 +355,9 @@ SrsSource::SrsSource(std::string _stream_url) | @@ -354,6 +355,9 @@ SrsSource::SrsSource(std::string _stream_url) | ||
| 354 | #ifdef SRS_HLS | 355 | #ifdef SRS_HLS |
| 355 | hls = new SrsHls(); | 356 | hls = new SrsHls(); |
| 356 | #endif | 357 | #endif |
| 358 | +#ifdef SRS_FFMPEG | ||
| 359 | + encoder = new SrsEncoder(); | ||
| 360 | +#endif | ||
| 357 | 361 | ||
| 358 | cache_metadata = cache_sh_video = cache_sh_audio = NULL; | 362 | cache_metadata = cache_sh_video = cache_sh_audio = NULL; |
| 359 | 363 | ||
| @@ -392,6 +396,9 @@ SrsSource::~SrsSource() | @@ -392,6 +396,9 @@ SrsSource::~SrsSource() | ||
| 392 | #ifdef SRS_HLS | 396 | #ifdef SRS_HLS |
| 393 | srs_freep(hls); | 397 | srs_freep(hls); |
| 394 | #endif | 398 | #endif |
| 399 | +#ifdef SRS_FFMPEG | ||
| 400 | + srs_freep(encoder); | ||
| 401 | +#endif | ||
| 395 | } | 402 | } |
| 396 | 403 | ||
| 397 | bool SrsSource::can_publish() | 404 | bool SrsSource::can_publish() |
| @@ -617,6 +624,12 @@ int SrsSource::on_publish(std::string vhost, std::string app, std::string stream | @@ -617,6 +624,12 @@ int SrsSource::on_publish(std::string vhost, std::string app, std::string stream | ||
| 617 | } | 624 | } |
| 618 | #endif | 625 | #endif |
| 619 | 626 | ||
| 627 | +#ifdef SRS_FFMPEG | ||
| 628 | + if ((ret = encoder->on_publish(vhost, app, stream)) != ERROR_SUCCESS) { | ||
| 629 | + return ret; | ||
| 630 | + } | ||
| 631 | +#endif | ||
| 632 | + | ||
| 620 | // TODO: support reload. | 633 | // TODO: support reload. |
| 621 | 634 | ||
| 622 | // create forwarders | 635 | // create forwarders |
| @@ -645,6 +658,10 @@ void SrsSource::on_unpublish() | @@ -645,6 +658,10 @@ void SrsSource::on_unpublish() | ||
| 645 | hls->on_unpublish(); | 658 | hls->on_unpublish(); |
| 646 | #endif | 659 | #endif |
| 647 | 660 | ||
| 661 | +#ifdef SRS_FFMPEG | ||
| 662 | + encoder->on_unpublish(); | ||
| 663 | +#endif | ||
| 664 | + | ||
| 648 | // close all forwarders | 665 | // close all forwarders |
| 649 | std::vector<SrsForwarder*>::iterator it; | 666 | std::vector<SrsForwarder*>::iterator it; |
| 650 | for (it = forwarders.begin(); it != forwarders.end(); ++it) { | 667 | for (it = forwarders.begin(); it != forwarders.end(); ++it) { |
| @@ -42,6 +42,9 @@ class SrsForwarder; | @@ -42,6 +42,9 @@ class SrsForwarder; | ||
| 42 | #ifdef SRS_HLS | 42 | #ifdef SRS_HLS |
| 43 | class SrsHls; | 43 | class SrsHls; |
| 44 | #endif | 44 | #endif |
| 45 | +#ifdef SRS_FFMPEG | ||
| 46 | +class SrsEncoder; | ||
| 47 | +#endif | ||
| 45 | 48 | ||
| 46 | /** | 49 | /** |
| 47 | * time jitter detect and correct, | 50 | * time jitter detect and correct, |
| @@ -172,6 +175,10 @@ private: | @@ -172,6 +175,10 @@ private: | ||
| 172 | #ifdef SRS_HLS | 175 | #ifdef SRS_HLS |
| 173 | SrsHls* hls; | 176 | SrsHls* hls; |
| 174 | #endif | 177 | #endif |
| 178 | + // transcoding handler. | ||
| 179 | +#ifdef SRS_FFMPEG | ||
| 180 | + SrsEncoder* encoder; | ||
| 181 | +#endif | ||
| 175 | // gop cache for client fast startup. | 182 | // gop cache for client fast startup. |
| 176 | SrsGopCache* gop_cache; | 183 | SrsGopCache* gop_cache; |
| 177 | // to forward stream to other servers | 184 | // to forward stream to other servers |
| @@ -26,6 +26,8 @@ file | @@ -26,6 +26,8 @@ file | ||
| 26 | ..\core\srs_core_source.cpp, | 26 | ..\core\srs_core_source.cpp, |
| 27 | ..\core\srs_core_forward.hpp, | 27 | ..\core\srs_core_forward.hpp, |
| 28 | ..\core\srs_core_forward.cpp, | 28 | ..\core\srs_core_forward.cpp, |
| 29 | + ..\core\srs_core_encoder.hpp, | ||
| 30 | + ..\core\srs_core_encoder.cpp, | ||
| 29 | ..\core\srs_core_hls.hpp, | 31 | ..\core\srs_core_hls.hpp, |
| 30 | ..\core\srs_core_hls.cpp, | 32 | ..\core\srs_core_hls.cpp, |
| 31 | ..\core\srs_core_codec.hpp, | 33 | ..\core\srs_core_codec.hpp, |
-
请 注册 或 登录 后发表评论