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

Feature/improve prober and compile gcc13 #11

Merged
merged 2 commits into from
May 2, 2024
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
118 changes: 105 additions & 13 deletions src/app/FileProber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@

using namespace libffmpeg;

const auto FILE_NAME = std::string("testFile.webm");
void showUsage()
{
std::cout << "FileProber usage:\n";
std::cout << " FileProber <filename> [options]\n";
std::cout << "\n";
std::cout << "Options:\n";
std::cout << " -showAllPackets Print all parsed packets\n";
std::cout << " -loglevelDebug Set log level to debug output\n";
std::cout << " -loglevelInfo Set log level to info output\n";
std::cout << " -loglevelWarning Set log level to warning output\n";
std::cout << " -libPath Set a search path for the ffmpeg libraries\n";
}

std::string to_string(const avcodec::CodecDescriptorProperties &properties)
{
Expand Down Expand Up @@ -57,19 +68,58 @@ std::string to_string(const ByteVector &bytes)
return stream.str();
}

template <typename T1, typename T2> std::string to_string(const std::map<T1, T2> &map)
{
std::ostringstream stream;
auto isFirst = false;
for (const auto [key, value] : map)
{
if (!isFirst)
stream << ", ";
stream << "[" << key << ", " << value << "]";
isFirst = false;
}
return stream.str();
}

struct Settings
{
std::string filename{};
bool showPackets{};
std::filesystem::path libraryPath{};
libffmpeg::LogLevel logLevel{libffmpeg::LogLevel::Error};
};

Settings parseCommandLineArguments(int argc, char const *argv[])
bool checkIfFileExists(std::string_view filename)
{
if (std::filesystem::exists(filename))
return true;

std::cout << "Given file " << filename << " not found.";
return false;
}

std::optional<Settings> parseCommandLineArguments(int argc, char const *argv[])
{
Settings settings;

if (1 == argc)
{
std::cout << "Not enough arguemnts. File name must be given";
return {};
}

for (int i = 1; i < argc; ++i)
{
const auto argument = std::string(argv[i]);

if (1 == i)
{
if (checkIfFileExists(argument))
settings.filename = argument;
else
return {};
}
if (argument == "-showAllPackets")
settings.showPackets = true;
if (argument == "-loglevelDebug")
Expand All @@ -93,7 +143,10 @@ Settings parseCommandLineArguments(int argc, char const *argv[])
settings.libraryPath = path;
}
else
{
std::cout << "Missing argument for parameter -libPath";
return {};
}
}
}
return settings;
Expand All @@ -112,9 +165,14 @@ void loggingFunction(const LogLevel logLevel, const std::string &message)
int main(int argc, char const *argv[])
{
const auto settings = parseCommandLineArguments(argc, argv);
if (!settings)
{
showUsage();
return 1;
}

const auto loadingResult = FFmpegLibrariesBuilder()
.withLoggingFunction(&loggingFunction, LogLevel::Debug)
.withLoggingFunction(&loggingFunction, settings->logLevel)
.tryLoadingOfLibraries();

if (!loadingResult.ffmpegLibraries)
Expand All @@ -135,12 +193,12 @@ int main(int argc, char const *argv[])
}

Demuxer demuxer(loadingResult.ffmpegLibraries);
if (!demuxer.openFile(FILE_NAME))
if (!demuxer.openFile(settings->filename))
{
std::cout << "Error when opening input file : " + FILE_NAME + "\n ";
std::cout << "Error when opening input file : " + settings->filename + "\n ";
return 1;
}
std::cout << "Successfully opened file " + FILE_NAME + ".\n";
std::cout << "Successfully opened file " + settings->filename + ".\n";

const auto formatContext = demuxer.getFormatContext();
const auto inputFormat = formatContext->getInputFormat();
Expand Down Expand Up @@ -184,14 +242,39 @@ int main(int argc, char const *argv[])
}
}

std::map<int, int> streamPacketCounters;
int packetIndex = 0;
struct StreamCounters
{
int packetCount{0};
std::map<int, int> packetCountPerDuration{};
std::map<int, int> packetCountPerPtsIncrease{};
std::map<int, int> packetCountPerDtsIncrease{};
};

std::map<int, StreamCounters> streamPacketCounters;
int packetIndex = 0;
std::map<int, int64_t> lastDTSPerStream;
std::map<int, int64_t> lastPTSPerStream;

while (auto packet = demuxer.getNextPacket())
{
const auto streamIndex = packet->getStreamIndex();
streamPacketCounters[streamIndex]++;

if (settings.showPackets)
if (lastDTSPerStream.count(streamIndex) > 0 && lastPTSPerStream.count(streamIndex) > 0)
{
const auto ptsIncrease = packet->getPTS().value() - lastPTSPerStream.at(streamIndex);
const auto dtsIncrease = packet->getDTS() - lastDTSPerStream.at(streamIndex);

streamPacketCounters[streamIndex].packetCountPerPtsIncrease[ptsIncrease]++;
streamPacketCounters[streamIndex].packetCountPerDtsIncrease[dtsIncrease]++;
}

lastPTSPerStream[streamIndex] = packet->getPTS().value();
lastDTSPerStream[streamIndex] = packet->getDTS();

streamPacketCounters[streamIndex].packetCount++;
streamPacketCounters[streamIndex].packetCountPerDuration[packet->getDuration()]++;

if (settings->showPackets)
{
auto ptsString = packet->getPTS() ? std::to_string(packet->getPTS().value()) : "No-PTS";
std::cout << " Packet " << packetIndex << ": StreamIndex " << packet->getStreamIndex()
Expand All @@ -205,9 +288,18 @@ int main(int argc, char const *argv[])
packetIndex++;
}

std::cout << " Packet counts:\n";
for (const auto [streamIndex, count] : streamPacketCounters)
std::cout << " Stream " << streamIndex << " : " << count << "\n";
std::cout << " Stream counts:\n";
for (const auto [streamIndex, counters] : streamPacketCounters)
{
std::cout << " Stream " << streamIndex << " : \n";
std::cout << " Packet count: " << counters.packetCount << "\n";
std::cout << " Packet per duration: " << to_string(counters.packetCountPerDuration)
<< "\n";
std::cout << " Packet per PTS increase: " << to_string(counters.packetCountPerPtsIncrease)
<< "\n";
std::cout << " Packet per DTS increase: " << to_string(counters.packetCountPerDtsIncrease)
<< "\n";
}

return 0;
}
1 change: 1 addition & 0 deletions src/lib/AVUtil/wrappers/AVMotionVectorConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <common/Version.h>

#include <stdint.h>
#include <vector>

namespace libffmpeg::avutil
Expand Down
2 changes: 2 additions & 0 deletions src/lib/AVUtil/wrappers/AVPixFmtDescriptorConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "AVPixFmtDescriptorConversionInternal.h"
#include "CastUtilClasses.h"

#include <utility>

using namespace std::rel_ops;

namespace libffmpeg::avutil
Expand Down