winlin

for #319, allow multiple ingest and transcode.

@@ -1119,6 +1119,7 @@ vhost ingest.srs.com { @@ -1119,6 +1119,7 @@ vhost ingest.srs.com {
1119 # ingest file/stream/device then push to SRS over RTMP. 1119 # ingest file/stream/device then push to SRS over RTMP.
1120 # the name/id used to identify the ingest, must be unique in global. 1120 # the name/id used to identify the ingest, must be unique in global.
1121 # ingest id is used in reload or http api management. 1121 # ingest id is used in reload or http api management.
  1122 + # @remark vhost can contains multiple ingest
1122 ingest livestream { 1123 ingest livestream {
1123 # whether enabled ingest features 1124 # whether enabled ingest features
1124 # default: off 1125 # default: off
@@ -1200,6 +1201,7 @@ vhost transcode.ingest.srs.com { @@ -1200,6 +1201,7 @@ vhost transcode.ingest.srs.com {
1200 # the main comments for transcode 1201 # the main comments for transcode
1201 vhost example.transcode.srs.com { 1202 vhost example.transcode.srs.com {
1202 # the streaming transcode configs. 1203 # the streaming transcode configs.
  1204 + # @remark vhost can contains multiple transcode
1203 transcode { 1205 transcode {
1204 # whether the transcode enabled. 1206 # whether the transcode enabled.
1205 # if off, donot transcode. 1207 # if off, donot transcode.
@@ -1214,13 +1216,14 @@ vhost example.transcode.srs.com { @@ -1214,13 +1216,14 @@ vhost example.transcode.srs.com {
1214 # whether the engine is enabled 1216 # whether the engine is enabled
1215 # default: off. 1217 # default: off.
1216 enabled on; 1218 enabled on;
1217 - # input format, can be: 1219 + # input format, "ffmpeg -i", can be:
1218 # off, do not specifies the format, ffmpeg will guess it. 1220 # off, do not specifies the format, ffmpeg will guess it.
1219 # flv, for flv or RTMP stream. 1221 # flv, for flv or RTMP stream.
1220 # other format, for example, mp4/aac whatever. 1222 # other format, for example, mp4/aac whatever.
1221 # default: flv 1223 # default: flv
1222 iformat flv; 1224 iformat flv;
1223 - # ffmpeg filters, follows the main input. 1225 + # ffmpeg filters, between "-i" and "-vcodec"
  1226 + # follows the main input.
1224 vfilter { 1227 vfilter {
1225 # the logo input file. 1228 # the logo input file.
1226 i ./doc/ffmpeg-logo.png; 1229 i ./doc/ffmpeg-logo.png;
@@ -1228,38 +1231,41 @@ vhost example.transcode.srs.com { @@ -1228,38 +1231,41 @@ vhost example.transcode.srs.com {
1228 # for filters, @see: http://ffmpeg.org/ffmpeg-filters.html 1231 # for filters, @see: http://ffmpeg.org/ffmpeg-filters.html
1229 filter_complex 'overlay=10:10'; 1232 filter_complex 'overlay=10:10';
1230 } 1233 }
1231 - # video encoder name. can be: 1234 + # video encoder name, "ffmpeg -vcodec"
  1235 + # can be:
1232 # libx264: use h.264(libx264) video encoder. 1236 # libx264: use h.264(libx264) video encoder.
1233 # copy: donot encoder the video stream, copy it. 1237 # copy: donot encoder the video stream, copy it.
1234 # vn: disable video output. 1238 # vn: disable video output.
1235 vcodec libx264; 1239 vcodec libx264;
1236 - # video bitrate, in kbps 1240 + # video bitrate, in kbps, "ffmepg -b:v"
1237 # @remark 0 to use source video bitrate. 1241 # @remark 0 to use source video bitrate.
1238 # default: 0 1242 # default: 0
1239 vbitrate 1500; 1243 vbitrate 1500;
1240 - # video framerate. 1244 + # video framerate, "ffmepg -r"
1241 # @remark 0 to use source video fps. 1245 # @remark 0 to use source video fps.
1242 # default: 0 1246 # default: 0
1243 vfps 25; 1247 vfps 25;
1244 - # video width, must be even numbers. 1248 + # video width, must be even numbers, "ffmepg -s"
1245 # @remark 0 to use source video width. 1249 # @remark 0 to use source video width.
1246 # default: 0 1250 # default: 0
1247 vwidth 768; 1251 vwidth 768;
1248 - # video height, must be even numbers. 1252 + # video height, must be even numbers, "ffmepg -s"
1249 # @remark 0 to use source video height. 1253 # @remark 0 to use source video height.
1250 # default: 0 1254 # default: 0
1251 vheight 320; 1255 vheight 320;
1252 - # the max threads for ffmpeg to used. 1256 + # the max threads for ffmpeg to used, "ffmepg -thread"
1253 # default: 1 1257 # default: 1
1254 vthreads 12; 1258 vthreads 12;
1255 - # x264 profile, @see x264 -help, can be: 1259 + # x264 profile, "ffmepg -profile:v"
  1260 + # @see x264 -help, can be:
1256 # high,main,baseline 1261 # high,main,baseline
1257 vprofile main; 1262 vprofile main;
1258 - # x264 preset, @see x264 -help, can be: 1263 + # x264 preset, "ffmpeg -preset"
  1264 + # @see x264 -help, can be:
1259 # ultrafast,superfast,veryfast,faster,fast 1265 # ultrafast,superfast,veryfast,faster,fast
1260 # medium,slow,slower,veryslow,placebo 1266 # medium,slow,slower,veryslow,placebo
1261 vpreset medium; 1267 vpreset medium;
1262 - # other x264 or ffmpeg video params 1268 + # other x264 or ffmpeg video params, between "-preset" and "-acodec"
1263 vparams { 1269 vparams {
1264 # ffmpeg options, @see: http://ffmpeg.org/ffmpeg.html 1270 # ffmpeg options, @see: http://ffmpeg.org/ffmpeg.html
1265 t 100; 1271 t 100;
@@ -1269,38 +1275,42 @@ vhost example.transcode.srs.com { @@ -1269,38 +1275,42 @@ vhost example.transcode.srs.com {
1269 bf 3; 1275 bf 3;
1270 refs 10; 1276 refs 10;
1271 } 1277 }
1272 - # audio encoder name. can be: 1278 + # audio encoder name, "ffmpeg -acodec"
  1279 + # can be:
1273 # libfdk_aac: use aac(libfdk_aac) audio encoder. 1280 # libfdk_aac: use aac(libfdk_aac) audio encoder.
1274 # copy: donot encoder the audio stream, copy it. 1281 # copy: donot encoder the audio stream, copy it.
1275 # an: disable audio output. 1282 # an: disable audio output.
1276 acodec libfdk_aac; 1283 acodec libfdk_aac;
1277 - # audio bitrate, in kbps. [16, 72] for libfdk_aac. 1284 + # audio bitrate, in kbps, "ffmpeg -b:a"
  1285 + # [16, 72] for libfdk_aac.
1278 # @remark 0 to use source audio bitrate. 1286 # @remark 0 to use source audio bitrate.
1279 # default: 0 1287 # default: 0
1280 abitrate 70; 1288 abitrate 70;
1281 - # audio sample rate. for flv/rtmp, it must be: 1289 + # audio sample rate, "ffmpeg -ar"
  1290 + # for flv/rtmp, it must be:
1282 # 44100,22050,11025,5512 1291 # 44100,22050,11025,5512
1283 # @remark 0 to use source audio sample rate. 1292 # @remark 0 to use source audio sample rate.
1284 # default: 0 1293 # default: 0
1285 asample_rate 44100; 1294 asample_rate 44100;
1286 - # audio channel, 1 for mono, 2 for stereo. 1295 + # audio channel, "ffmpeg -ac"
  1296 + # 1 for mono, 2 for stereo.
1287 # @remark 0 to use source audio channels. 1297 # @remark 0 to use source audio channels.
1288 # default: 0 1298 # default: 0
1289 achannels 2; 1299 achannels 2;
1290 - # other ffmpeg audio params 1300 + # other ffmpeg audio params, between "-ac" and "-f"/"-y"
1291 aparams { 1301 aparams {
1292 # audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders 1302 # audio params, @see: http://ffmpeg.org/ffmpeg-codecs.html#Audio-Encoders
1293 # @remark SRS supported aac profile for HLS is: aac_low, aac_he, aac_he_v2 1303 # @remark SRS supported aac profile for HLS is: aac_low, aac_he, aac_he_v2
1294 profile:a aac_low; 1304 profile:a aac_low;
1295 bsf:a aac_adtstoasc; 1305 bsf:a aac_adtstoasc;
1296 } 1306 }
1297 - # output format, can be: 1307 + # output format, "ffmpeg -f" can be:
1298 # off, do not specifies the format, ffmpeg will guess it. 1308 # off, do not specifies the format, ffmpeg will guess it.
1299 # flv, for flv or RTMP stream. 1309 # flv, for flv or RTMP stream.
1300 # other format, for example, mp4/aac whatever. 1310 # other format, for example, mp4/aac whatever.
1301 # default: flv 1311 # default: flv
1302 oformat flv; 1312 oformat flv;
1303 - # output stream. variables: 1313 + # output stream, "ffmpeg -y", variables:
1304 # [vhost] the input stream vhost. 1314 # [vhost] the input stream vhost.
1305 # [port] the intput stream port. 1315 # [port] the intput stream port.
1306 # [app] the input stream app. 1316 # [app] the input stream app.
@@ -189,7 +189,72 @@ vhost vhost.srs.com { @@ -189,7 +189,72 @@ vhost vhost.srs.com {
189 ffmpeg ./objs/ffmpeg/bin/ffmpeg; 189 ffmpeg ./objs/ffmpeg/bin/ffmpeg;
190 engine { 190 engine {
191 enabled off; 191 enabled off;
192 - output rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream; 192 + iformat flv;
  193 + vfilter {
  194 + s 30;
  195 + ss 300;
  196 + }
  197 + vcodec libx264;
  198 + vbitrate 1500;
  199 + vfps 25;
  200 + vwidth 768;
  201 + vheight 320;
  202 + vthreads 12;
  203 + vprofile main;
  204 + vpreset medium;
  205 + vparams {
  206 + t 100;
  207 + coder 1;
  208 + b_strategy 2;
  209 + bf 3;
  210 + refs 10;
  211 + }
  212 + acodec libfdk_aac;
  213 + abitrate 70;
  214 + asample_rate 44100;
  215 + achannels 2;
  216 + aparams {
  217 + profile:a aac_low;
  218 + }
  219 + oformat flv;
  220 + output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream];
  221 + }
  222 + }
  223 +
  224 + transcode live {
  225 + enabled off;
  226 + ffmpeg ./objs/ffmpeg/bin/ffmpeg;
  227 + engine ffsuper {
  228 + enabled off;
  229 + iformat flv;
  230 + vfilter {
  231 + s 30;
  232 + ss 300;
  233 + }
  234 + vcodec libx264;
  235 + vbitrate 1500;
  236 + vfps 25;
  237 + vwidth 768;
  238 + vheight 320;
  239 + vthreads 12;
  240 + vprofile main;
  241 + vpreset medium;
  242 + vparams {
  243 + t 100;
  244 + coder 1;
  245 + b_strategy 2;
  246 + bf 3;
  247 + refs 10;
  248 + }
  249 + acodec libfdk_aac;
  250 + abitrate 70;
  251 + asample_rate 44100;
  252 + achannels 2;
  253 + aparams {
  254 + profile:a aac_low;
  255 + }
  256 + oformat flv;
  257 + output rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
193 } 258 }
194 } 259 }
195 260
@@ -200,8 +265,8 @@ vhost vhost.srs.com { @@ -200,8 +265,8 @@ vhost vhost.srs.com {
200 enabled off; 265 enabled off;
201 iformat flv; 266 iformat flv;
202 vfilter { 267 vfilter {
203 - i ./doc/ffmpeg-logo.png;  
204 - filter_complex overlay=10:10; 268 + s 30;
  269 + ss 300;
205 } 270 }
206 vcodec libx264; 271 vcodec libx264;
207 vbitrate 1500; 272 vbitrate 1500;
@@ -2096,14 +2096,26 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) @@ -2096,14 +2096,26 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
2096 } 2096 }
2097 2097
2098 // transcode 2098 // transcode
2099 - if ((dir = vhost->get("transcode")) != NULL) { 2099 + SrsAmf0StrictArray* transcodes = NULL;
  2100 + for (int i = 0; i < (int)vhost->directives.size(); i++) {
  2101 + dir = vhost->directives.at(i);
  2102 + if (dir->name != "transcode") {
  2103 + continue;
  2104 + }
  2105 +
  2106 + if (!transcodes) {
  2107 + transcodes = SrsAmf0Any::strict_array();
  2108 + obj->set("transcodes", transcodes);
  2109 + }
  2110 +
2100 SrsAmf0Object* transcode = SrsAmf0Any::object(); 2111 SrsAmf0Object* transcode = SrsAmf0Any::object();
2101 - obj->set("transcode", transcode); 2112 + transcodes->append(transcode);
2102 2113
  2114 + transcode->set("apply", dir->dumps_arg0_to_str());
2103 transcode->set("enabled", SrsAmf0Any::boolean(get_transcode_enabled(dir))); 2115 transcode->set("enabled", SrsAmf0Any::boolean(get_transcode_enabled(dir)));
2104 2116
2105 SrsAmf0StrictArray* engines = SrsAmf0Any::strict_array(); 2117 SrsAmf0StrictArray* engines = SrsAmf0Any::strict_array();
2106 - obj->set("engines", engines); 2118 + transcode->set("engines", engines);
2107 2119
2108 for (int i = 0; i < (int)dir->directives.size(); i++) { 2120 for (int i = 0; i < (int)dir->directives.size(); i++) {
2109 SrsConfDirective* sdir = dir->directives.at(i); 2121 SrsConfDirective* sdir = dir->directives.at(i);
@@ -2151,7 +2163,7 @@ int SrsConfig::dumps_engine(SrsConfDirective* dir, SrsAmf0Object* engine) @@ -2151,7 +2163,7 @@ int SrsConfig::dumps_engine(SrsConfDirective* dir, SrsAmf0Object* engine)
2151 2163
2152 SrsConfDirective* conf = NULL; 2164 SrsConfDirective* conf = NULL;
2153 2165
2154 - engine->set("name", dir->dumps_arg0_to_str()); 2166 + engine->set("id", dir->dumps_arg0_to_str());
2155 engine->set("enabled", SrsAmf0Any::boolean(get_engine_enabled(dir))); 2167 engine->set("enabled", SrsAmf0Any::boolean(get_engine_enabled(dir)));
2156 2168
2157 if ((conf = dir->get("iformat")) != NULL) { 2169 if ((conf = dir->get("iformat")) != NULL) {