MistInAV X3 speedup + fixed VoD/live flag

This commit is contained in:
Thulinma 2017-05-13 22:13:52 +02:00
parent 0798a6c712
commit a178fd206d

View file

@ -94,8 +94,6 @@ namespace Mist {
if (readExistingHeader()){return true;} if (readExistingHeader()){return true;}
myMeta.tracks.clear(); myMeta.tracks.clear();
myMeta.live = false;
myMeta.vod = true;
for(unsigned int i=0; i < pFormatCtx->nb_streams; ){ for(unsigned int i=0; i < pFormatCtx->nb_streams; ){
AVStream * strm = pFormatCtx->streams[i++]; AVStream * strm = pFormatCtx->streams[i++];
myMeta.tracks[i].trackID = i; myMeta.tracks[i].trackID = i;
@ -180,25 +178,21 @@ namespace Mist {
AVPacket packet; AVPacket packet;
while(av_read_frame(pFormatCtx, &packet)>=0){ while(av_read_frame(pFormatCtx, &packet)>=0){
AVStream * strm = pFormatCtx->streams[packet.stream_index]; AVStream * strm = pFormatCtx->streams[packet.stream_index];
JSON::Value pkt; long long packTime = (packet.dts * 1000 * strm->time_base.num / strm->time_base.den);
pkt["trackid"] = (long long)packet.stream_index + 1; long long packOffset = 0;
pkt["data"] = std::string((char*)packet.data, packet.size); bool isKey = false;
pkt["time"] = (long long)(packet.dts * 1000 * strm->time_base.num / strm->time_base.den); if (packTime < 0){
if (pkt["time"].asInt() < 0){ packTime = 0;
pkt["time"] = 0ll;
} }
if (packet.flags & AV_PKT_FLAG_KEY && myMeta.tracks[(long long)packet.stream_index + 1].type != "audio"){ if (packet.flags & AV_PKT_FLAG_KEY && myMeta.tracks[(long long)packet.stream_index + 1].type != "audio"){
pkt["keyframe"] = 1ll; isKey = true;
pkt["bpos"] = (long long)packet.pos;
} }
if (packet.pts != AV_NOPTS_VALUE && packet.pts != packet.dts){ if (packet.pts != AV_NOPTS_VALUE && packet.pts != packet.dts){
pkt["offset"] = (long long)((packet.pts - packet.dts) * 1000 * strm->time_base.num / strm->time_base.den); packOffset = ((packet.pts - packet.dts) * 1000 * strm->time_base.num / strm->time_base.den);
} }
myMeta.update(pkt); myMeta.update(packTime, packOffset, packet.stream_index + 1, packet.size, packet.pos, isKey);
av_free_packet(&packet); av_free_packet(&packet);
} }
myMeta.live = false;
myMeta.vod = true;
myMeta.toFile(config->getString("input") + ".dtsh"); myMeta.toFile(config->getString("input") + ".dtsh");
@ -215,22 +209,19 @@ namespace Mist {
continue; continue;
} }
AVStream * strm = pFormatCtx->streams[packet.stream_index]; AVStream * strm = pFormatCtx->streams[packet.stream_index];
JSON::Value pkt; long long packTime = (packet.dts * 1000 * strm->time_base.num / strm->time_base.den);
pkt["trackid"] = (long long)packet.stream_index + 1; long long packOffset = 0;
pkt["data"] = std::string((char*)packet.data, packet.size); bool isKey = false;
pkt["time"] = (long long)(packet.dts * 1000 * strm->time_base.num / strm->time_base.den); if (packTime < 0){
if (pkt["time"].asInt() < 0){ packTime = 0;
pkt["time"] = 0ll;
} }
if (packet.flags & AV_PKT_FLAG_KEY && myMeta.tracks[(long long)packet.stream_index + 1].type != "audio"){ if (packet.flags & AV_PKT_FLAG_KEY && myMeta.tracks[(long long)packet.stream_index + 1].type != "audio"){
pkt["keyframe"] = 1ll; isKey = true;
pkt["bpos"] = (long long)packet.pos;
} }
if (packet.pts != AV_NOPTS_VALUE && packet.pts != packet.dts){ if (packet.pts != AV_NOPTS_VALUE && packet.pts != packet.dts){
pkt["offset"] = (long long)((packet.pts - packet.dts) * 1000 * strm->time_base.num / strm->time_base.den); packOffset = ((packet.pts - packet.dts) * 1000 * strm->time_base.num / strm->time_base.den);
} }
pkt.netPrepare(); thisPacket.genericFill(packTime, packOffset, packet.stream_index + 1, (const char*)packet.data, packet.size, 0, isKey);
thisPacket.reInit(pkt.toNetPacked().data(), pkt.toNetPacked().size());
av_free_packet(&packet); av_free_packet(&packet);
return;//success! return;//success!
} }