Reworked existing subtitle support (sideloaded, MP4 in and srt out)
This commit is contained in:
parent
741c4755cc
commit
b9e261e1ef
7 changed files with 159 additions and 33 deletions
|
@ -35,12 +35,19 @@ namespace Mist {
|
|||
if (audioId != -1) {
|
||||
bWidth += myMeta.tracks[audioId].bps;
|
||||
}
|
||||
result << "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" << (bWidth * 8) << "\r\n";
|
||||
result << "#EXT-X-STREAM-INF:PROGRAM-ID=1,SUBTITLES=\"sub1\",BANDWIDTH=" << (bWidth * 8) << "\r\n";
|
||||
result << it->first;
|
||||
if (audioId != -1) {
|
||||
result << "_" << audioId;
|
||||
}
|
||||
result << "/index.m3u8?sessId=" << getpid() << "\r\n";
|
||||
}else if(it->second.codec == "subtitle"){
|
||||
|
||||
if(it->second.lang.empty()){
|
||||
it->second.lang = "und";
|
||||
}
|
||||
|
||||
result << "#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"sub1\",LANGUAGE=\"" << it->second.lang << "\",NAME=\"" << Encodings::ISO639::decode(it->second.lang) << "\",AUTOSELECT=NO,DEFAULT=NO,FORCED=NO,URI=\"" << it->first << "/index.m3u8\"" << "\r\n";
|
||||
}
|
||||
}
|
||||
if (!vidTracks && audioId) {
|
||||
|
@ -145,10 +152,15 @@ namespace Mist {
|
|||
duration = myMeta.tracks[tid].lastms - starttime;
|
||||
}
|
||||
char lineBuf[400];
|
||||
if (sessId.size()){
|
||||
snprintf(lineBuf, 400, "#EXTINF:%f,\r\n%lld_%lld.ts?sessId=%s\r\n", (double)duration/1000, starttime, starttime + duration, sessId.c_str());
|
||||
|
||||
if(myMeta.tracks[tid].codec == "subtitle"){
|
||||
snprintf(lineBuf, 400, "#EXTINF:%f,\r\n../../../%s.vtt?track=%d&from=%lld&to=%lld\r\n", streamName.c_str(),(double)duration/1000,tid, starttime, starttime + duration);
|
||||
}else{
|
||||
snprintf(lineBuf, 400, "#EXTINF:%f,\r\n%lld_%lld.ts\r\n", (double)duration/1000, starttime, starttime + duration);
|
||||
if (sessId.size()){
|
||||
snprintf(lineBuf, 400, "#EXTINF:%f,\r\n%lld_%lld.ts?sessId=%s\r\n", (double)duration/1000, starttime, starttime + duration, sessId.c_str());
|
||||
}else{
|
||||
snprintf(lineBuf, 400, "#EXTINF:%f,\r\n%lld_%lld.ts\r\n", (double)duration/1000, starttime, starttime + duration);
|
||||
}
|
||||
}
|
||||
durs.push_back(duration);
|
||||
total_dur += duration;
|
||||
|
|
|
@ -14,8 +14,7 @@ namespace Mist {
|
|||
capa["desc"] = "Enables HTTP protocol subtitle streaming in subrip and WebVTT formats.";
|
||||
capa["url_match"].append("/$.srt");
|
||||
capa["url_match"].append("/$.vtt");
|
||||
capa["codecs"][0u][0u].append("srt");
|
||||
capa["codecs"][0u][0u].append("TTXT");
|
||||
capa["codecs"][0u][0u].append("subtitle");
|
||||
capa["methods"][0u]["handler"] = "http";
|
||||
capa["methods"][0u]["type"] = "html5/text/plain";
|
||||
capa["methods"][0u]["priority"] = 8ll;
|
||||
|
@ -30,6 +29,7 @@ namespace Mist {
|
|||
char * dataPointer = 0;
|
||||
unsigned int len = 0;
|
||||
thisPacket.getString("data", dataPointer, len);
|
||||
// INFO_MSG("getting sub: %s", dataPointer);
|
||||
//ignore empty subs
|
||||
if (len == 0 || (len == 1 && dataPointer[0] == ' ')){
|
||||
return;
|
||||
|
@ -39,6 +39,20 @@ namespace Mist {
|
|||
tmp << lastNum++ << std::endl;
|
||||
}
|
||||
long long unsigned int time = thisPacket.getTime();
|
||||
|
||||
|
||||
//filter subtitle in specific timespan
|
||||
if(filter_from > 0 && time < filter_from){
|
||||
index++; //when using seek, the index is lost.
|
||||
seek(filter_from);
|
||||
return;
|
||||
}
|
||||
|
||||
if(filter_to > 0 && time > filter_to && filter_to > filter_from){
|
||||
config->is_active = false;
|
||||
return;
|
||||
}
|
||||
|
||||
char tmpBuf[50];
|
||||
int tmpLen = sprintf(tmpBuf, "%.2llu:%.2llu:%.2llu.%.3llu", (time / 3600000), ((time % 3600000) / 60000), (((time % 3600000) % 60000) / 1000), time % 1000);
|
||||
tmp.write(tmpBuf, tmpLen);
|
||||
|
@ -79,6 +93,18 @@ namespace Mist {
|
|||
selectedTracks.clear();
|
||||
selectedTracks.insert(JSON::Value(H.GetVar("track")).asInt());
|
||||
}
|
||||
|
||||
filter_from = 0;
|
||||
filter_to = 0;
|
||||
index = 0;
|
||||
|
||||
if (H.GetVar("from") != ""){
|
||||
filter_from = JSON::Value(H.GetVar("from")).asInt();
|
||||
}
|
||||
if (H.GetVar("to") != ""){
|
||||
filter_to = JSON::Value(H.GetVar("to")).asInt();
|
||||
}
|
||||
|
||||
H.Clean();
|
||||
H.setCORSHeaders();
|
||||
if(method == "OPTIONS" || method == "HEAD"){
|
||||
|
|
|
@ -13,6 +13,9 @@ namespace Mist {
|
|||
protected:
|
||||
bool webVTT;
|
||||
int lastNum;
|
||||
uint32_t filter_from;
|
||||
uint32_t filter_to;
|
||||
uint32_t index;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue