提交 b61a8ea5 authored 作者: blu's avatar blu

bugfix: correctly handling video streams with extra data

上级 77e6d3d8
...@@ -369,16 +369,18 @@ protected: ...@@ -369,16 +369,18 @@ protected:
// find all video & audio streams for remuxing // find all video & audio streams for remuxing
int i = 0, streamIdx = 0; int i = 0, streamIdx = 0;
vector<int> ids;
for (; i < pAVFormatInput->nb_streams; i++) { for (; i < pAVFormatInput->nb_streams; i++) {
AVStream *in_stream = pAVFormatInput->streams[i]; AVStream *in_stream = pAVFormatInput->streams[i];
AVCodecParameters *in_codecpar = in_stream->codecpar; AVCodecParameters *in_codecpar = in_stream->codecpar;
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO && if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO && in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO /* &&
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) { in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE */) {
streamList[i] = -1; streamList[i] = -1;
continue; continue;
} }
streamList[i] = streamIdx++; streamList[i] = streamIdx++;
ids.push_back(i);
} }
bool bStopSig = false; bool bStopSig = false;
...@@ -423,7 +425,7 @@ protected: ...@@ -423,7 +425,7 @@ protected:
// be attention to the scope of lock guard! // be attention to the scope of lock guard!
{ {
lock_guard<mutex> lock(this->mutMsg); lock_guard<mutex> lock(this->mutMsg);
lenAVFmtCtxBytes = AVFormatCtxSerializer::encode(pAVFormatInput, &pAVFmtCtxBytes); lenAVFmtCtxBytes = AVFormatCtxSerializer::encode(pAVFormatInput, &pAVFmtCtxBytes, ids);
if(lenAVFmtCtxBytes <= 0 || pAVFmtCtxBytes == nullptr) { if(lenAVFmtCtxBytes <= 0 || pAVFmtCtxBytes == nullptr) {
spdlog::error("evpuller {} failed to pull packet from {}. exiting...", selfId, urlIn); spdlog::error("evpuller {} failed to pull packet from {}. exiting...", selfId, urlIn);
// TODO: message report to cloud // TODO: message report to cloud
......
...@@ -205,7 +205,7 @@ namespace AVFormatCtxSerializer ...@@ -205,7 +205,7 @@ namespace AVFormatCtxSerializer
* */ * */
int encode(AVFormatContext *ctx, char **bytes) int encode(AVFormatContext *ctx, char **bytes, vector<int> ids = vector<int>())
{ {
int wholeSize = 0; int wholeSize = 0;
int got = 0; int got = 0;
...@@ -214,7 +214,16 @@ int encode(AVFormatContext *ctx, char **bytes) ...@@ -214,7 +214,16 @@ int encode(AVFormatContext *ctx, char **bytes)
// num streams // num streams
wholeSize += sizeof(ctx->nb_streams); wholeSize += sizeof(ctx->nb_streams);
spdlog::debug("encode num of streams: {:d}", ctx->nb_streams); spdlog::debug("encode num of streams: {:d}", ctx->nb_streams);
for (int i = 0; i < ctx->nb_streams; i++) int numStreams = ctx->nb_streams;
if(ids.size() != 0) {
numStreams = ids.size();
}else{
for(int i = 0; i < numStreams; i++){
ids.push_back(i);
}
}
for (int i = 0; i < numStreams; i++)
{ {
wholeSize += sizeof(AVStream); wholeSize += sizeof(AVStream);
wholeSize += sizeof(AVCodecParameters); wholeSize += sizeof(AVCodecParameters);
...@@ -232,9 +241,9 @@ int encode(AVFormatContext *ctx, char **bytes) ...@@ -232,9 +241,9 @@ int encode(AVFormatContext *ctx, char **bytes)
// populate // populate
memcpy((*bytes) + got, PS_MARK_S, strlen(PS_MARK_S)); memcpy((*bytes) + got, PS_MARK_S, strlen(PS_MARK_S));
got += strlen(PS_MARK_S); got += strlen(PS_MARK_S);
memcpy((*bytes) + got, (void *)&(ctx->nb_streams), sizeof(ctx->nb_streams)); memcpy((*bytes) + got, (void *)&(numStreams), sizeof(ctx->nb_streams));
got += sizeof(ctx->nb_streams); got += sizeof(ctx->nb_streams);
for (int i = 0; i < ctx->nb_streams; i++) for (auto i: ids)
{ {
// //
memcpy((*bytes) + got, ctx->streams[i], sizeof(AVStream)); memcpy((*bytes) + got, ctx->streams[i], sizeof(AVStream));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论