Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2gb report xml limit on Windows #861

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions Source/Core/AudioStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,28 @@ void AudioStats::TimeStampFromFrame (const QAVFrame& frame, size_t FramePos)

std::string AudioStats::StatsToXML (const activefilters& filters)
{
std::stringstream Data;
std::string Data;

// Per frame (note: the XML header and footer are not created here)
for (size_t x_Pos=0; x_Pos<x_Current; ++x_Pos)
{
std::stringstream Frame;
std::stringstream pkt_pts_time; pkt_pts_time<<std::fixed<<std::setprecision(7)<<(x[1][x_Pos]+FirstTimeStamp);
std::stringstream pkt_duration_time; pkt_duration_time<<std::fixed<<std::setprecision(7)<<durations[x_Pos];
std::stringstream key_frame; key_frame<< (key_frames[x_Pos]? '1' : '0');

Data<<" <frame media_type=\"audio\"";
Data << " stream_index=\"" << streamIndex << "\"";
Frame<<" <frame media_type=\"audio\"";
Frame << " stream_index=\"" << streamIndex << "\"";

Data<<" key_frame=\"" << key_frame.str() << "\"";
Data << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
Data<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
Frame<<" key_frame=\"" << key_frame.str() << "\"";
Frame << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
Frame<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
if (pkt_duration_time)
Data<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
Data << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
Data << " pkt_size=\"" << pkt_size[x_Pos] << "\"";
Frame<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
Frame << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
Frame << " pkt_size=\"" << pkt_size[x_Pos] << "\"";

Data << ">\n";
Frame << ">\n";

for (size_t Plot_Pos=0; Plot_Pos<Item_AudioMax; Plot_Pos++)
{
Expand All @@ -338,13 +339,14 @@ std::string AudioStats::StatsToXML (const activefilters& filters)
const std::string& key = PerItem[Plot_Pos].FFmpeg_Name;
auto value = std::to_string(y[Plot_Pos][x_Pos]);

Data<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
Frame<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
}

writeAdditionalStats(Data, x_Pos);
writeAdditionalStats(Frame, x_Pos);

Data<<" </frame>\n";
Frame<<" </frame>\n";
Data+=Frame.str();
}

return Data.str();
return Data;
}
54 changes: 27 additions & 27 deletions Source/Core/FileInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,19 +1256,21 @@ void FileInformation::startExport(const QString &exportFileName)
//---------------------------------------------------------------------------
void FileInformation::Export_XmlGz (const QString &ExportFileName, const activefilters& filters)
{
std::stringstream Data;
std::string Data;

// Header
Data<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Data<<"<!-- Created by QCTools " << Version << " -->\n";
Data<<"<ffprobe:ffprobe xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'>\n";
Data<<" <program_version version=\"" << FFmpeg_Version() << "\" copyright=\"Copyright (c) 2007-" << FFmpeg_Year() << " the FFmpeg developers\" build_date=\"" __DATE__ "\" build_time=\"" __TIME__ "\" compiler_ident=\"" << FFmpeg_Compiler() << "\" configuration=\"" << FFmpeg_Configuration() << "\"/>\n";
Data<<"\n";
Data<<" <library_versions>\n";
Data<<FFmpeg_LibsVersion();
Data<<" </library_versions>\n";

Data<<" <frames>\n";
std::stringstream Header;
Header<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
Header<<"<!-- Created by QCTools " << Version << " -->\n";
Header<<"<ffprobe:ffprobe xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ffprobe='http://www.ffmpeg.org/schema/ffprobe' xsi:schemaLocation='http://www.ffmpeg.org/schema/ffprobe ffprobe.xsd'>\n";
Header<<" <program_version version=\"" << FFmpeg_Version() << "\" copyright=\"Copyright (c) 2007-" << FFmpeg_Year() << " the FFmpeg developers\" build_date=\"" __DATE__ "\" build_time=\"" __TIME__ "\" compiler_ident=\"" << FFmpeg_Compiler() << "\" configuration=\"" << FFmpeg_Configuration() << "\"/>\n";
Header<<"\n";
Header<<" <library_versions>\n";
Header<<FFmpeg_LibsVersion();
Header<<" </library_versions>\n";

Header<<" <frames>\n";
Data+=Header.str();

// From stats
for (size_t Pos=0; Pos<Stats.size(); Pos++)
Expand All @@ -1281,12 +1283,13 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
videoStats->setWidth(m_mediaParser->availableVideoStreams()[0].stream()->codecpar->width);
videoStats->setHeight(m_mediaParser->availableVideoStreams()[0].stream()->codecpar->height);
}
Data<<Stats[Pos]->StatsToXML(filters);
Data+=Stats[Pos]->StatsToXML(filters);
}
}

// Footer
Data<<" </frames>";
std::stringstream Footer;
Footer<<" </frames>";

QString streamsAndFormats;
QXmlStreamWriter writer(&streamsAndFormats);
Expand All @@ -1305,9 +1308,10 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
splitted[i] = QString(qAbs(writer.autoFormattingIndent()), writer.autoFormattingIndent() > 0 ? ' ' : '\t') + splitted[i];
streamsAndFormats = splitted.join("\n");

Data<<streamsAndFormats.toStdString() << "\n\n";
Footer<<streamsAndFormats.toStdString() << "\n\n";

Data<<"</ffprobe:ffprobe>";
Footer<<"</ffprobe:ffprobe>";
Data+=Footer.str();

SharedFile file;
QString name;
Expand All @@ -1323,23 +1327,21 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
name = info.fileName();
}

std::string DataS=Data.str();
uLongf Buffer_Size=65536;

if(file->open(QIODevice::ReadWrite))
{
if (name.endsWith(".qctools.xml"))
if (name.endsWith(".xml"))
{
auto bytesLeft = Data.str().size();
auto writePtr = DataS.c_str();
auto bytesLeft = Data.size();
auto writePtr = Data.c_str();
auto totalBytesWritten = 0;

while (bytesLeft) {
auto bytesToWrite = std::min(size_t(Buffer_Size), bytesLeft);
auto bytesWritten = file->write(writePtr, bytesToWrite);
totalBytesWritten += bytesWritten;

Q_EMIT statsFileGenerationProgress(totalBytesWritten, DataS.size());
Q_EMIT statsFileGenerationProgress(totalBytesWritten, Data.size());

writePtr += bytesToWrite;
bytesLeft -= bytesWritten;
Expand All @@ -1348,14 +1350,12 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
break;
}
}
else if (name.endsWith(".xml"))
else
{
file->write(DataS.c_str(), DataS.length());
} else {
char* Buffer=new char[Buffer_Size];
z_stream strm;
strm.next_in = (Bytef *) DataS.c_str();
strm.avail_in = DataS.size() ;
strm.next_in = (Bytef *) Data.c_str();
strm.avail_in = Data.size() ;
strm.total_out = 0;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
Expand All @@ -1369,7 +1369,7 @@ void FileInformation::Export_XmlGz (const QString &ExportFileName, const activef
break;
file->write(Buffer, Buffer_Size-strm.avail_out);

Q_EMIT statsFileGenerationProgress((char*) strm.next_in - DataS.c_str(), DataS.size());
Q_EMIT statsFileGenerationProgress((char*) strm.next_in - Data.c_str(), Data.size());
}
while (strm.avail_out == 0);
deflateEnd (&strm);
Expand Down
38 changes: 20 additions & 18 deletions Source/Core/VideoStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,31 +439,32 @@ void VideoStats::setHeight(int height)
//---------------------------------------------------------------------------
std::string VideoStats::StatsToXML (const activefilters& filters)
{
std::stringstream Data;
std::string Data;

// Per frame (note: the XML header and footer are not created here)
std::stringstream widthStream; widthStream<<width; // Note: we use the same value for all frame, we should later use the right value per frame
std::stringstream heightStream; heightStream<<height; // Note: we use the same value for all frame, we should later use the right value per frame
for (size_t x_Pos=0; x_Pos<x_Current; ++x_Pos)
{
std::stringstream Frame;
std::stringstream pkt_pts_time; pkt_pts_time<<std::fixed<<std::setprecision(7)<<(x[1][x_Pos]+FirstTimeStamp);
std::stringstream pkt_duration_time; pkt_duration_time<<std::fixed<<std::setprecision(7)<<durations[x_Pos];
std::stringstream key_frame; key_frame<<key_frames[x_Pos]?'1':'0';
Data<<" <frame media_type=\"video\"";
Data << " stream_index=\"" << streamIndex << "\"";
Frame<<" <frame media_type=\"video\"";
Frame << " stream_index=\"" << streamIndex << "\"";

Data<<" key_frame=\"" << key_frame.str() << "\"";
Data << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
Data<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
Frame<<" key_frame=\"" << key_frame.str() << "\"";
Frame << " pkt_pts=\"" << pkt_pts[x_Pos] << "\"";
Frame<<" pkt_pts_time=\"" << pkt_pts_time.str() << "\"";
if (pkt_duration_time)
Data<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
Data << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
Data << " pkt_size=\"" << pkt_size[x_Pos] << "\"";
Data<<" width=\"" << widthStream.str() << "\" height=\"" << heightStream.str() <<"\"";
Data << " pix_fmt=\"" << av_get_pix_fmt_name((AVPixelFormat) pix_fmt[x_Pos]) << "\"";
Data << " pict_type=\"" << pict_type_char[x_Pos] << "\"";
Frame<<" pkt_duration_time=\"" << pkt_duration_time.str() << "\"";
Frame << " pkt_pos=\"" << pkt_pos[x_Pos] << "\"";
Frame << " pkt_size=\"" << pkt_size[x_Pos] << "\"";
Frame<<" width=\"" << widthStream.str() << "\" height=\"" << heightStream.str() <<"\"";
Frame << " pix_fmt=\"" << av_get_pix_fmt_name((AVPixelFormat) pix_fmt[x_Pos]) << "\"";
Frame << " pict_type=\"" << pict_type_char[x_Pos] << "\"";

Data << ">\n";
Frame << ">\n";

for (size_t Plot_Pos=0; Plot_Pos<Item_VideoMax; Plot_Pos++)
{
Expand Down Expand Up @@ -493,16 +494,17 @@ std::string VideoStats::StatsToXML (const activefilters& filters)
value = std::to_string(y[Plot_Pos][x_Pos]);
}

Data<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
Frame<<" <tag key=\""+key+"\" value=\""+value+"\"/>\n";
}

writeAdditionalStats(Data, x_Pos);
writeAdditionalStats(Frame, x_Pos);

if(comments[x_Pos])
Data<<" <tag key=\"qctools.comment\" value=\"" << comments[x_Pos] << "\"/>\n";
Frame<<" <tag key=\"qctools.comment\" value=\"" << comments[x_Pos] << "\"/>\n";

Data<<" </frame>\n";
Frame<<" </frame>\n";
Data+=Frame.str();
}

return Data.str();
return Data;
}
Loading