Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ CMakeCache.txt
*.bak
/.devcontainer/.bash_history.d
/.devcontainer/.vscode-server
/.devcontainer/.claude
/.devcontainer/.local
.devcontainer/.gdb/__pycache__
/ws
/ws2
Expand Down
19 changes: 13 additions & 6 deletions fpsdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@ function main
local volume_args=
local docker_args=
local dochecks=1
while getopts ":hduxti:v:" opt; do
local hwaccel=0
while getopts ":hduxtai:v:" opt; do
case $opt in
h)
echo
echo "Run Fixposition SDK apps"
echo
echo "This uses Docker images with pre-built binaries of the Fixposition SDK apps."
echo
echo "Usage: $0 [-d] [-u] [-x] [-i <image>] [-v <volume> ...] <command> ..."
echo "Usage: $0 [-d] [-u] [-x] [-t] [-a] [-i <image>] [-v <volume> ...] <command> ..."
echo
echo "Where:"
echo
echo " -d Enable debug output (of this script)"
echo " -x Bypass checks (check for running in Docker, running as root, ...)"
echo " -u Update (pull) the necessary Docker <image>"
echo " -t Executes <command> with docker run --tty"
echo " -a Try to enable hw acceleration for video decoding"
echo " -i <image> Specifies which Docker image to use (default: trixie). Available images are:"
echo " trixie -- Debian Trixie (no ROS, some functionality not available)"
echo " noetic -- ROS1 Noetic (additional ROS1 functionality available)"
Expand Down Expand Up @@ -91,6 +93,9 @@ function main
t)
docker_args="--tty"
;;
a)
hwaccel=1
;;
i)
image=${OPTARG}
;;
Expand Down Expand Up @@ -183,10 +188,12 @@ function main
args="${args} --user $(id -u):$(id -g) --volume /etc/passwd:/etc/passwd:ro --volume /etc/group:/etc/group:ro"
# - Allow FFmpeg vaapi access on some systems. Note: this doesn't work with "-i noetic" (Ubuntu 20).
# Related: https://github.com/joedefen/ffmpeg-vaapi-docker
if [ -r /dev/dri ]; then
args="${args} --device=/dev/dri"
rendergid=$(awk -F: '/^render:/ { print $3 }' /etc/group)
args="${args} --group-add ${rendergid}"
if [ ${hwaccel} -gt 0 ]; then
if [ -r /dev/dri ]; then
args="${args} --device=/dev/dri"
rendergid=$(awk -F: '/^render:/ { print $3 }' /etc/group)
args="${args} --group-add ${rendergid}"
fi
fi

[ ${DEBUG} -gt 0 ] && set -x
Expand Down
51 changes: 31 additions & 20 deletions fpsdk_apps/fpltool/fpltool_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ bool FplToolExtract::Run()
return false;
}

// Check which output formats we want
// Check which output formats we want. Keep defaults in sync with help screen!
do_jsonl_ = opts_.formats_.empty();
do_raw_ = opts_.formats_.empty();
do_file_ = opts_.formats_.empty();
do_ros_ = opts_.formats_.empty();
do_cam_ = opts_.formats_.empty();
do_ros_ = false;
do_cam_ = false;
for (auto& fmt : opts_.formats_) { // clang-format off
if (fmt == opts_.FORMAT_JSONL) { do_jsonl_ = true; }
else if (fmt == opts_.FORMAT_RAW) { do_raw_ = true; }
Expand All @@ -111,31 +111,37 @@ bool FplToolExtract::Run()
return false;
}

DEBUG("do_jsonl=%s do_raw=%s do_file=%s do_ros=%s do_cam=%s", ToStr(do_jsonl_), ToStr(do_raw_), ToStr(do_file_),
ToStr(do_ros_), ToStr(do_cam_));

NOTICE("Extracting from %s to %s_...", input_fpl.c_str(), output_prefix_.c_str());
TicToc tt;

std::string output_bag;
if (do_ros_) {
#if FPSDK_USE_ROS2
const auto output_bag = output_prefix_ + "_bag"; // Directory! (even for single-file .mcap)
output_bag = output_prefix_ + "_bag"; // Directory! (even for single-file .mcap)
#else
const auto output_bag = output_prefix_ + ".bag"; // File
output_bag = output_prefix_ + ".bag"; // File
#endif
if (PathExists(output_bag)) {
if (!opts_.overwrite_) {
WARNING("Output bag %s already exists", output_bag.c_str());
return false;
} else {
RemoveAll(output_bag);
if (PathExists(output_bag)) {
if (!opts_.overwrite_) {
WARNING("Output bag %s already exists", output_bag.c_str());
return false;
} else {
RemoveAll(output_bag);
}
}
}
#if FPSDK_USE_ROS2
if (do_ros_ && !bag_.Open(output_bag, opts_.mcap_, opts_.compress_)) {
if (do_ros_ && !bag_.Open(output_bag, opts_.mcap_, opts_.compress_)) {
#else
if (do_ros_ && !bag_.Open(output_bag, opts_.compress_)) {
if (do_ros_ && !bag_.Open(output_bag, opts_.compress_)) {
#endif
return false;
}
return false;
}

NOTICE("Extracting to %s", output_bag.c_str());
NOTICE("Extracting to %s", output_bag.c_str());
}

// Handle SIGINT (C-c) to abort nicely
SigIntHelper sig_int;
Expand Down Expand Up @@ -508,8 +514,9 @@ FplToolExtract::ProcRes FplToolExtract::ProcessCamData(const FplMessage& fpl_msg
}

// Decode this frame
fut = std::async(std::launch::async,
[&dec, /*copy!*/ camdata]() -> AsyncDecData { return { camdata, dec->DecodeFrame(camdata.data_) }; });
fut = std::async(std::launch::async, [&dec, /*copy!*/ camdata]() -> AsyncDecData {
return { camdata, dec->DecodeFrame(camdata.data_), dec->IsOkay() };
});

break;
}
Expand All @@ -526,7 +533,11 @@ FplToolExtract::ProcRes FplToolExtract::ProcessAsyncDecData(const FplToolExtract
auto& camdata = decdata.camdata_;
if (!decdata.img_) {
WARNING("No image from CAMDATA %s", camdata.info_.c_str());
return ProcRes::ERROR;
if (!decdata.dec_is_okay_) {
return ProcRes::FATAL;
} else {
return ProcRes::ERROR;
}
}
auto& img = *decdata.img_;
TRACE("CAMDATA decoded %s -> %dx%d %s", camdata.info_.c_str(), img.width_, img.height_, PixelFmtToStr(img.fmt_));
Expand Down
1 change: 1 addition & 0 deletions fpsdk_apps/fpltool/fpltool_extract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class FplToolExtract
{
common::fpl::CamData camdata_;
std::optional<common::video::ImageData> img_;
bool dec_is_okay_ = true;
};
struct AsyncDecState
{
Expand Down
14 changes: 9 additions & 5 deletions fpsdk_apps/fpltool/fpltool_opts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class FplToolOptions : public common::app::ProgramOptions
" -o, --output <out> -- Output file prefix <out> (default: derive from <fpl-file> name)\n"
" -S, --skip <sec> -- Skip <sec> seconds from start of log (default: 0, i.e. no skip)\n"
" -D, --duration <sec> -- Process <sec> seconds of log (default: everything)\n"
" -e, --formats <fmts> -- Comma-separated list of output formats for the extract <command> (default: all)\n"
" -e, --formats <fmts> -- Comma-separated list of output formats for the extract <command> (default: jsonl,raw,file)\n"
" -s, --scale <fact> -- Scale factor for decoded video frames: 0.1 - 1.0 (default: 1.0)\n"
" -t, --pixelfmt <fmt> -- Pixel format for decoded video frames: Y8, RGB24, GBRP (default: RGB24)\n"
" <command> -- The command, see below\n"
Expand Down Expand Up @@ -240,10 +240,14 @@ class FplToolOptions : public common::app::ProgramOptions
"\n"
" fpltool -x dump some.fpl > some.txt\n"
"\n"
" Extract all data from a .fpl file:\n"
" Extract some data from a .fpl file:\n"
"\n"
" fpltool extract some.fpl\n"
"\n"
" Extract all data from a .fpl file:\n"
"\n"
" fpltool extract -e jsonl,raw,file,ros,cam some.fpl\n"
"\n"
" Create a ROS some.bag file (ROS1) resp. some_bag directory (ROS2) from a .fpl file:\n"
"\n"
" fpltool extract -e ros,cam some.fpl\n"
Expand All @@ -252,13 +256,13 @@ class FplToolOptions : public common::app::ProgramOptions
" Create another.bag (ROS1, another_bag/ for ROS2) with 2 minutes of data starting 60 seconds\n"
" into some.fpl:\n"
"\n"
" fpltool rosbag some.fpl -c -c -o another.bag -S 60 -D 120\n"
" fpltool rosbag some.fpl -o another.bag -S 60 -D 120\n"
"\n"
" Check what is in the extracted ROS bag:\n"
"\n"
" rosbag info some.bag # ROS 1\n"
" ros2 bag info some_bag # ROS 2 (default, see above)\n"
" mcap info some_bag/some.mcap # ROS 2 (with -m, see above)\n"
" ros2 bag info some_bag # ROS 2 (default bag format)\n"
" mcap info some_bag/some.mcap # ROS 2 (with -m, mcap bag format)\n"
"\n"
" Create a ROS bag, convert encoded video (e.g. from PBx-A1 sensor) to greyscale images of half size:\n"
"\n"
Expand Down
7 changes: 4 additions & 3 deletions fpsdk_common/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,11 @@ void ProgramOptions::PrintVersion() const

void ProgramOptions::LogVersion() const
{
INFO("%s%s%s (fpsdk: %s%s%s%s%s, %s)\n%s\n%s\n", app_name_.c_str(), version_str_.empty() ? "" : " ",
INFO("%s%s%s (fpsdk: %s%s%s%s%s, %s)", app_name_.c_str(), version_str_.empty() ? "" : " ",
version_str_.empty() ? "" : version_str_.c_str(), BUILDSTR, ROSSTR, PROJSTR, FFMPEGSTR, BZ2STR,
utils::GetVersionString(), copy_str_.empty() ? utils::GetCopyrightString() : copy_str_.c_str(),
lic_str_.empty() ? utils::GetLicenseString() : lic_str_.c_str());
utils::GetVersionString());
INFO("%s", copy_str_.empty() ? utils::GetCopyrightString() : copy_str_.c_str());
INFO("%s", lic_str_.empty() ? utils::GetLicenseString() : lic_str_.c_str());
}

/* ****************************************************************************************************************** */
Expand Down
Loading