8 #include "HTTPLiveStreaming.h"
17 HTTPLiveStreaming::HTTPLiveStreaming()
19 DebugLog2("HTTPLiveStreaming::HTTPLiveStreaming()");
28 HTTPLiveStreaming::~HTTPLiveStreaming()
31 RELEASE(_output_path);
35 DebugLog2("HTTPLiveStreaming::~HTTPLiveStreaming()");
38 HTTPLiveStreaming *HTTPLiveStreaming::alloc()
40 DebugLog2("HTTPLiveStreaming::alloc()");
42 return new HTTPLiveStreaming();
45 HTTPLiveStreaming *HTTPLiveStreaming::init()
47 DebugLog2("HTTPLiveStreaming::init()");
49 if (FFmpeg::init() == NULL)
58 HTTPLiveStreaming *HTTPLiveStreaming::retain()
60 DebugLog2("HTTPLiveStreaming::retain()");
66 HTTPLiveStreaming *HTTPLiveStreaming::autorelease()
68 DebugLog2("HTTPLiveStreaming::autorelease()");
70 FFmpeg::autorelease();
74 void HTTPLiveStreaming::setSource(String *source)
76 DebugLog2("HTTPLiveStreaming::setSource()");
81 _source = source->retain();
85 void HTTPLiveStreaming::setOutputPath(String *output_path)
87 DebugLog2("HTTPLiveStreaming::setOutputPath()");
89 RELEASE(_output_path);
90 if (output_path != NULL)
92 _output_path = output_path->retain();
96 String *HTTPLiveStreaming::outputPath()
101 void HTTPLiveStreaming::setIndexName(String *index_name)
103 DebugLog2("HTTPLiveStreaming::setIndexName()");
105 RELEASE(_index_name);
106 if (index_name != NULL)
108 _index_name = index_name->retain();
112 bool HTTPLiveStreaming::start()
114 DebugLog2("%s", __FUNCTION__);
116 if ((_output_path == NULL) || (_source == NULL) || (_index_name == NULL))
121 DebugLog2("output path: %s", _output_path->cString());
122 DebugLog2("source: %s", _source->cString());
123 DebugLog2("index: %s", _index_name->cString());
125 String *index_path = indexPath();
126 if (index_path != NULL)
128 FileManager::defaultManager()->removeItemAtPath(index_path, NULL);
132 // %>ffmpeg -i C:\WORK\20151024_211758_086_PT2@050000-01.ts -vcodec libx264 -r 30000/1001 -aspect 16:9 -s 1280x720
133 // -bufsize 20000k -maxrate 25000k -acodec libvo_aacenc -ac
134 // 2 -ar 48000 -ab 128k -threads 2 -f segment -segment_format mpegts -segment_time 10 -segment_list index.m3u8 test%03d.ts
138 // Array *args = STR_ARRAY("-i", "C:\\WORK\\20151024_211758_086_PT2@050000-01.ts",
139 // Array *args = STR_ARRAY("-i", "udp://0.0.0.0:51027",
141 Array *arg2 = STR_ARRAY("-i", "udp://@0.0.0.0:51027?overrun_nonfatal=1&fifo_size=50000000",
142 // Array *args = STR_ARRAY("-i", "udp://@51027?overrun_nonfatal=1&fifo_size=50000000",
143 "-vcodec", "libx264",
147 "-bufsize", "20000k",
148 "-maxrate", "25000k",
149 "-acodec", "libvo_aacenc",
154 // "-programid", "1074",
156 "-segment_format", "mpegts",
157 "-segment_time", "10",
158 "-segment_list", "C:\\WORK\\www\\index.m3u8",
159 "C:\\WORK\\www\\test%03d.ts",
163 Array *args = Array::arrayWithCapacity(0);
164 args->addObject(String::stringWithUTF8String("-i"));
165 // args->addObject(String::stringWithUTF8String("udp://@0.0.0.0:51027?overrun_nonfatal=1&fifo_size=50000000"));
166 if (_source->hasPrefix("udp://"))
168 args->addObject(String::stringWithFormat("%s?overrun_nonfatal=1&fifo_size=50000000", _source->cString()));
172 args->addObject(String::stringWithUTF8String("hogehoge"));
175 args->addObject(String::stringWithUTF8String("-vcodec"));
176 args->addObject(String::stringWithUTF8String("libx264"));
177 args->addObject(String::stringWithUTF8String("-r"));
178 args->addObject(String::stringWithUTF8String("30000/1001"));
179 args->addObject(String::stringWithUTF8String("-aspect"));
180 args->addObject(String::stringWithUTF8String("16:9"));
181 // args->addObject(String::stringWithUTF8String("-s"));
182 // args->addObject(String::stringWithUTF8String("1280x720"));
183 args->addObject(String::stringWithUTF8String("-g"));
184 args->addObject(String::stringWithUTF8String("150"));
185 args->addObject(String::stringWithUTF8String("-bufsize"));
186 args->addObject(String::stringWithUTF8String("20000k"));
187 args->addObject(String::stringWithUTF8String("-maxrate"));
188 args->addObject(String::stringWithUTF8String("25000k"));
189 args->addObject(String::stringWithUTF8String("-acodec"));
190 args->addObject(String::stringWithUTF8String("libvo_aacenc"));
191 args->addObject(String::stringWithUTF8String("-ac"));
192 args->addObject(String::stringWithUTF8String("2"));
193 args->addObject(String::stringWithUTF8String("-ar"));
194 args->addObject(String::stringWithUTF8String("48000"));
195 args->addObject(String::stringWithUTF8String("-ab"));
196 args->addObject(String::stringWithUTF8String("128k"));
197 args->addObject(String::stringWithUTF8String("-threads"));
198 args->addObject(String::stringWithUTF8String("2"));
199 args->addObject(String::stringWithUTF8String("-f"));
200 args->addObject(String::stringWithUTF8String("segment"));
201 args->addObject(String::stringWithUTF8String("-segment_format"));
202 args->addObject(String::stringWithUTF8String("mpegts"));
203 args->addObject(String::stringWithUTF8String("-segment_time"));
204 args->addObject(String::stringWithUTF8String("10"));
206 args->addObject(String::stringWithUTF8String("-segment_list"));
207 args->addObject(_output_path->stringByAppendingPathComponent(String::stringWithFormat("%s.m3u8", _index_name->cString())));
209 args->addObject(_output_path->stringByAppendingPathComponent(String::stringWithUTF8String("streaming-%05d.ts")));
213 return FFmpeg::start();
216 String * HTTPLiveStreaming::indexPath()
218 if ((_output_path == NULL) || (_index_name == NULL))
222 return _output_path->stringByAppendingPathComponent(String::stringWithFormat("%s.m3u8", _index_name->cString()));
226 bool HTTPLiveStreaming::readLine(String *line)
230 // DebugLog3("ffmpeg: %s", line->cString());
235 const char *HTTPLiveStreaming::className()
237 return "HTTPLiveStreaming";