Skip to content

Commit 9a0d885

Browse files
committed
support ffmpeg filter
1 parent f85b709 commit 9a0d885

8 files changed

+281
-86
lines changed

README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,16 @@ Supported operating systems and hardware:
6969
14. support forward publish stream to build active-standby cluster.<br/>
7070
15. support broadcast by forward the stream to other servers(origin/edge).<br/>
7171
16. support live stream transcoding by ffmpeg.<br/>
72-
17. [plan] support full http callback api.<br/>
73-
18. [plan] support network based cli and json result.<br/>
74-
19. [plan] support bandwidth test api and flash client.<br/>
75-
20. [plan] support adobe flash refer/token/swf verification.<br/>
76-
21. [plan] support adobe amf3 codec.<br/>
77-
22. [plan] support dvr(record live to vod file)<br/>
78-
23. [plan] support FMS edge protocol<br/>
79-
24. [plan] support encryption: RTMPE/RTMPS, HLS DRM<br/>
80-
25. [plan] support RTMPT, http to tranverse firewalls<br/>
72+
17. support live stream transcoding by ffmpeg.<br/>
73+
18. support ffmpeg filters(logo/overlay/crop), x264 params.<br/>
74+
19. [plan] support network based cli and json result.<br/>
75+
20. [plan] support bandwidth test api and flash client.<br/>
76+
21. [plan] support adobe flash refer/token/swf verification.<br/>
77+
22. [plan] support adobe amf3 codec.<br/>
78+
23. [plan] support dvr(record live to vod file)<br/>
79+
24. [plan] support FMS edge protocol<br/>
80+
25. [plan] support encryption: RTMPE/RTMPS, HLS DRM<br/>
81+
26. [plan] support RTMPT, http to tranverse firewalls<br/>
8182

8283
### Performance
8384
1. 300 connections, 150Mbps, 500kbps, CPU 18.8%, 5956KB.

trunk/auto/build_ffmpeg.sh

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ else
8484
--extra-ldflags='-L${ffmpeg_exported_release_dir}/lib -lm -ldl' \
8585
--disable-ffplay --disable-ffprobe --disable-ffserver --disable-doc \
8686
--enable-postproc --enable-bzlib --enable-zlib --enable-parsers \
87+
--enable-libfreetype \
8788
--enable-libx264 --enable-libmp3lame --enable-libaacplus \
8889
--enable-pthreads --extra-libs=-lpthread --enable-encoders --enable-decoders --enable-avfilter --enable-muxers --enable-demuxers &&
8990
make && make install

trunk/conf/srs.conf

+119-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ vhost __defaultVhost__ {
1515
hls_path ./objs/nginx/html;
1616
hls_fragment 5;
1717
hls_window 30;
18-
#forward 127.0.0.1:1936;
18+
forward 127.0.0.1:1936;
1919
transcode {
2020
enabled on;
2121
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
2222
#ffmpeg ./research/ffempty/ffempty;
2323
engine fast{
2424
enabled on;
25+
vfilter {
26+
vf 'drawtext=text=SRS';
27+
#vf 'crop=in_w-20:in_h-160:10:80';
28+
#i ./doc/ffmpeg-logo.png;
29+
#filter_complex 'overlay=10:10';
30+
}
2531
vcodec libx264;
2632
vbitrate 300;
2733
vfps 20;
@@ -37,11 +43,15 @@ vhost __defaultVhost__ {
3743
asample_rate 44100;
3844
achannels 2;
3945
aparams {
46+
profile:a aac_low;
4047
}
4148
output rtmp://[vhost]:[port]/[app]/[stream]_fast;
4249
}
4350
engine sd{
44-
enabled on;
51+
enabled off;
52+
vfilter {
53+
vf 'split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2';
54+
}
4555
vcodec libx264;
4656
vbitrate 500;
4757
vfps 20;
@@ -79,6 +89,14 @@ vhost all.transcode.vhost.com {
7989
# whether the engine is enabled
8090
# default: off.
8191
enabled on;
92+
# ffmpeg filters, follows the main input.
93+
vfilter {
94+
# the logo input file.
95+
i ./doc/ffmpeg-logo.png;
96+
# the ffmpeg complex filter.
97+
# for filters, @see: http://ffmpeg.org/ffmpeg-filters.html
98+
filter_complex 'overlay=10:10';
99+
}
82100
# video encoder name
83101
vcodec libx264;
84102
# video bitrate, in kbps
@@ -100,6 +118,13 @@ vhost all.transcode.vhost.com {
100118
vpreset medium;
101119
# other x264 or ffmpeg video params
102120
vparams {
121+
# ffmpeg options, @see: http://ffmpeg.org/ffmpeg.html
122+
t 100;
123+
# 264 params, @see: http://ffmpeg.org/ffmpeg-codecs.html#libx264
124+
coder 1;
125+
b_strategy 2;
126+
bf 3;
127+
refs 10;
103128
}
104129
# audio encoder name
105130
acodec libaacplus;
@@ -182,12 +207,102 @@ vhost all.transcode.vhost.com {
182207
}
183208
}
184209
}
210+
# the mirror filter of ffmpeg, @see: http://ffmpeg.org/ffmpeg-filters.html#Filtering-Introduction
211+
vhost mirror.transcode.vhost.com {
212+
transcode {
213+
enabled on;
214+
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
215+
engine mirror{
216+
enabled on;
217+
vfilter {
218+
vf 'split [main][tmp]; [tmp] crop=iw:ih/2:0:0, vflip [flip]; [main][flip] overlay=0:H/2';
219+
}
220+
vcodec libx264;
221+
vbitrate 300;
222+
vfps 20;
223+
vwidth 480;
224+
vheight 320;
225+
vthreads 2;
226+
vprofile baseline;
227+
vpreset superfast;
228+
vparams {
229+
}
230+
acodec libaacplus;
231+
abitrate 30;
232+
asample_rate 44100;
233+
achannels 2;
234+
aparams {
235+
}
236+
output rtmp://[vhost]:[port]/[app]/[stream]_mirror;
237+
}
238+
}
239+
}
240+
# the logo filter of ffmpeg, @see: http://ffmpeg.org/ffmpeg-filters.html#crop
241+
vhost crop.transcode.vhost.com {
242+
transcode {
243+
enabled on;
244+
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
245+
engine crop{
246+
enabled on;
247+
vfilter {
248+
vf 'crop=in_w-20:in_h-160:10:80';
249+
}
250+
vcodec libx264;
251+
vbitrate 300;
252+
vfps 20;
253+
vwidth 480;
254+
vheight 320;
255+
vthreads 2;
256+
vprofile baseline;
257+
vpreset superfast;
258+
vparams {
259+
}
260+
acodec libaacplus;
261+
abitrate 30;
262+
asample_rate 44100;
263+
achannels 2;
264+
aparams {
265+
}
266+
output rtmp://[vhost]:[port]/[app]/[stream]_crop;
267+
}
268+
}
269+
}
270+
# the crop filter of ffmpeg, @see: http://ffmpeg.org/ffmpeg-filters.html#crop
271+
vhost logo.transcode.vhost.com {
272+
transcode {
273+
enabled on;
274+
ffmpeg ./objs/ffmpeg/bin/ffmpeg;
275+
engine logo{
276+
enabled on;
277+
vfilter {
278+
vf 'crop=200:100:10:10';
279+
}
280+
vcodec libx264;
281+
vbitrate 300;
282+
vfps 20;
283+
vwidth 480;
284+
vheight 320;
285+
vthreads 2;
286+
vprofile baseline;
287+
vpreset superfast;
288+
vparams {
289+
}
290+
acodec libaacplus;
291+
abitrate 30;
292+
asample_rate 44100;
293+
achannels 2;
294+
aparams {
295+
}
296+
output rtmp://[vhost]:[port]/[app]/[stream]_logo;
297+
}
298+
}
299+
}
185300
# transcode all stream using the empty ffmpeg demo, donothing.
186301
vhost ffempty.transcode.vhost.com {
187302
transcode {
188303
enabled on;
189304
ffmpeg ./research/ffempty/ffempty;
190-
engine fd{
305+
engine empty{
191306
enabled on;
192307
vcodec libx264;
193308
vbitrate 300;
@@ -205,7 +320,7 @@ vhost ffempty.transcode.vhost.com {
205320
achannels 2;
206321
aparams {
207322
}
208-
output rtmp://[vhost]:[port]/[app]/[stream]_fast;
323+
output rtmp://[vhost]:[port]/[app]/[stream]_empty;
209324
}
210325
}
211326
}

trunk/doc/ffmpeg-logo.png

8.52 KB
Loading

trunk/src/core/srs_core_config.cpp

+31-17
Original file line numberDiff line numberDiff line change
@@ -768,30 +768,48 @@ std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine)
768768
return conf->arg0();
769769
}
770770

771-
std::string SrsConfig::get_engine_vparams(SrsConfDirective* engine)
771+
void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams)
772772
{
773773
if (!engine) {
774-
return "";
774+
return;
775775
}
776776

777777
SrsConfDirective* conf = engine->get("vparams");
778778
if (!conf) {
779-
return "";
779+
return;
780780
}
781781

782-
std::string avparams;
783782
for (int i = 0; i < (int)conf->directives.size(); i++) {
784783
SrsConfDirective* p = conf->directives[i];
785784
if (!p) {
786785
continue;
787786
}
788787

789-
avparams += p->name;
790-
avparams += " ";
791-
avparams += p->arg0();
788+
vparams.push_back("-" + p->name);
789+
vparams.push_back(p->arg0());
790+
}
791+
}
792+
793+
void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter)
794+
{
795+
if (!engine) {
796+
return;
797+
}
798+
799+
SrsConfDirective* conf = engine->get("vfilter");
800+
if (!conf) {
801+
return;
792802
}
793803

794-
return avparams;
804+
for (int i = 0; i < (int)conf->directives.size(); i++) {
805+
SrsConfDirective* p = conf->directives[i];
806+
if (!p) {
807+
continue;
808+
}
809+
810+
vfilter.push_back("-" + p->name);
811+
vfilter.push_back(p->arg0());
812+
}
795813
}
796814

797815
std::string SrsConfig::get_engine_acodec(SrsConfDirective* engine)
@@ -850,30 +868,26 @@ int SrsConfig::get_engine_achannels(SrsConfDirective* engine)
850868
return ::atoi(conf->arg0().c_str());
851869
}
852870

853-
std::string SrsConfig::get_engine_aparams(SrsConfDirective* engine)
871+
void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams)
854872
{
855873
if (!engine) {
856-
return "";
874+
return;
857875
}
858876

859877
SrsConfDirective* conf = engine->get("aparams");
860878
if (!conf) {
861-
return "";
879+
return;
862880
}
863881

864-
std::string avparams;
865882
for (int i = 0; i < (int)conf->directives.size(); i++) {
866883
SrsConfDirective* p = conf->directives[i];
867884
if (!p) {
868885
continue;
869886
}
870887

871-
avparams += p->name;
872-
avparams += " ";
873-
avparams += p->arg0();
888+
aparams.push_back("-" + p->name);
889+
aparams.push_back(p->arg0());
874890
}
875-
876-
return avparams;
877891
}
878892

879893
std::string SrsConfig::get_engine_output(SrsConfDirective* engine)

trunk/src/core/srs_core_config.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ class SrsConfig
128128
virtual int get_engine_vthreads(SrsConfDirective* engine);
129129
virtual std::string get_engine_vprofile(SrsConfDirective* engine);
130130
virtual std::string get_engine_vpreset(SrsConfDirective* engine);
131-
virtual std::string get_engine_vparams(SrsConfDirective* engine);
131+
virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams);
132+
virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter);
132133
virtual std::string get_engine_acodec(SrsConfDirective* engine);
133134
virtual int get_engine_abitrate(SrsConfDirective* engine);
134135
virtual int get_engine_asample_rate(SrsConfDirective* engine);
135136
virtual int get_engine_achannels(SrsConfDirective* engine);
136-
virtual std::string get_engine_aparams(SrsConfDirective* engine);
137+
virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
137138
virtual std::string get_engine_output(SrsConfDirective* engine);
138139
virtual SrsConfDirective* get_gop_cache(std::string vhost);
139140
virtual SrsConfDirective* get_forward(std::string vhost);

0 commit comments

Comments
 (0)