Skip to content
Open
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 .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
.dockerignore
95 changes: 95 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# -*- mode: sh -*-
# vi: set ft=bash :

FROM ubuntu:latest AS builder

WORKDIR /home/ubuntu

RUN apt-get update && apt-get install -y build-essential \
cmake \
g++ \
git \
xorg-dev \
cimg-dev \
pkg-config \
libgl-dev \
libglu1-mesa-dev \
mesa-common-dev \
mesa-utils \
curl \
libva-dev \
libjpeg-dev \
libtiff-dev \
libpng++-dev \
libimath-dev \
libopencv-dev \
libopencolorio-dev \
libopentimelineio-dev

# Clone, compile and install feather-tk library
RUN mkdir feather-tk
RUN cd feather-tk; git clone https://github.com/grizzlypeak3d/feather-tk.git
# We revert feather-tk to the last date matching version to the current toucan main branch date.
# This is only needed until the toucan codebase and feather-tk library are synchronised in their APIs.
RUN cd feather-tk/feather-tk; git checkout 3cee68ec
RUN cd feather-tk; sh feather-tk/sbuild-linux.sh feather-tk
# TODO replace with cmake --target install
RUN tar -C feather-tk/install-feather-tk -c -f - . | tar -C /usr/local -x -f -

# Add the pipx installation location:
ENV PATH=/root/.local/share/pipx/venvs/conan/bin:$PATH

# TODO Unable to get the release because of github blocking automation.
# curl -O https://github.com/AcademySoftwareFoundation/openfx/releases/download/OFX_Release_1.5.1/openfx-linux-ubuntu-1.5.1.tar.gz
RUN git clone https://github.com/AcademySoftwareFoundation/openfx.git
# Must turn off the plugins building with BUILD_EXAMPLE_PLUGINS=FALSE to avoid issues from cmake being unable to find OpenGL and CImg.
# Also, remove `--target install` from cmake because the generated Makefile doesn't have an install rule, for some reason?
# TODO this doesn't build on arm64 Linux currently, can't find the architecture.
# RUN cd openfx; scripts/build-cmake.sh -v Release -DBUILD_EXAMPLE_PLUGINS=FALSE -DPLUGIN_INSTALLDIR=./build/Install
# TODO need to find a better installation method, cmake --target install
RUN mkdir /usr/local/include/OpenFX
RUN tar -C openfx/include -c -f - . | tar -C /usr/local/include/OpenFX -x -f -

# RUN git clone https://github.com/OpenTimelineIO/toucan.git
# RUN git clone https://github.com/leighsmith/toucan.git
COPY . /home/ubuntu/toucan

# Build the toucan CLI tools.
RUN sh toucan/sbuild-linux.sh

# TODO Don't use the sbuild-linux.sh, install directly into /usr/local on the container.
# RUN cmake \
# -S toucan/cmake/SuperBuild \
# -B sbuild-Release \
# -DCMAKE_INSTALL_PREFIX=/usr/local \
# -DCMAKE_PREFIX_PATH=/usr/local \
# -DCMAKE_BUILD_TYPE=Release \
# -Dtoucan_FFmpeg_MINIMAL=OFF
# RUN cmake --build sbuild-Release -j 4 --config Release

# RUN cmake \
# -S toucan \
# -B build-Release \
# -DCMAKE_INSTALL_PREFIX=/usr/local \
# -DCMAKE_PREFIX_PATH=/usr/local \
# -DCMAKE_BUILD_TYPE=Release
# RUN cmake --build build-Release -j 4 --config Release
# RUN cmake --build build-Release --config Release --target install

# Install the tools & libraries into a clean container.
FROM ubuntu:latest

# Copy just the libraries and resources needed to operate the CLI tools.
COPY --from=builder /usr/lib/aarch64-linux-gnu/ /usr/lib/aarch64-linux-gnu/
COPY --from=builder /usr/local/ /usr/local/
COPY --from=builder /home/ubuntu/install-Release/ /usr/local/

# Define the locations to search for libraries to include local libraries.
ENV LD_LIBRARY_PATH=/usr/local/lib
WORKDIR /home/ubuntu

# TODO for some reason, running toucan-render from the command line, using PATH to find
# it, without an absolute path causes the tool to hang, while running it as
# /usr/local/bin/toucan-render properly runs. It seems that argv[0] is used, and an
# unspecified path then causes the command to hang. The current work-around is to simply
# run it with the full path specified.
40 changes: 34 additions & 6 deletions bin/toucan-render/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ extern "C"

} // extern "C"

#include <algorithm>
#include <cmath>
#include <stdio.h>

namespace toucan
Expand Down Expand Up @@ -70,6 +72,12 @@ namespace toucan
"",
"MJPEG",
ftk::join(ffmpeg::getVideoCodecStrings(), ", "));
_cmdLine.scale = ftk::CmdLineValueOption<float>::create(
std::vector<std::string>{ "-scale" },
"Scale the rendered image size by the given factor, for example 0.5 to render "
"at half resolution. Must be greater than zero.",
"",
1.F);
_cmdLine.printStart = ftk::CmdLineFlagOption::create(
std::vector<std::string>{ "-print_start" },
"Print the timeline start time and exit.");
Expand Down Expand Up @@ -106,6 +114,7 @@ namespace toucan
{ _cmdLine.input, _cmdLine.output },
{
_cmdLine.videoCodec,
_cmdLine.scale,
_cmdLine.printStart,
_cmdLine.printDuration,
_cmdLine.printRate,
Expand All @@ -119,6 +128,11 @@ namespace toucan
{
_cmdLine.outputRaw = true;
}

if (_cmdLine.scale->getValue() <= 0.F)
{
throw std::runtime_error("The -scale value must be greater than zero.");
}
}

App::App()
Expand Down Expand Up @@ -171,7 +185,11 @@ namespace toucan
_context,
inputPath.parent_path(),
_timelineWrapper);
const IMATH_NAMESPACE::V2d imageSize = _graph->getImageSize();
const IMATH_NAMESPACE::V2i nativeImageSize = _graph->getImageSize();
const float scale = _cmdLine.scale->getValue();
const IMATH_NAMESPACE::V2i imageSize(
std::max(1, static_cast<int>(std::round(nativeImageSize.x * scale))),
std::max(1, static_cast<int>(std::round(nativeImageSize.y * scale))));

// Print information.
if (_cmdLine.printStart->found())
Expand Down Expand Up @@ -217,7 +235,7 @@ namespace toucan
// Render the timeline frames.
if (_cmdLine.y4m->hasValue())
{
_writeY4mHeader();
_writeY4mHeader(imageSize);
}
for (OTIO_NS::RationalTime time = timeRange.start_time();
time <= timeRange.end_time_inclusive();
Expand All @@ -232,7 +250,17 @@ namespace toucan
if (auto node = _graph->exec(_host, time))
{
// Execute the graph.
const auto buf = node->exec();
auto buf = node->exec();

// Scale the image, if requested.
if (imageSize.x != nativeImageSize.x || imageSize.y != nativeImageSize.y)
{
buf = OIIO::ImageBufAlgo::resize(
buf,
"",
0.0,
OIIO::ROI(0, imageSize.x, 0, imageSize.y));
}

// Save the image.
if (!_cmdLine.outputRaw)
Expand Down Expand Up @@ -299,21 +327,21 @@ namespace toucan
stdout);
}

void App::_writeY4mHeader()
void App::_writeY4mHeader(const IMATH_NAMESPACE::V2i& imageSize)
{
std::string s = "YUV4MPEG2 ";
fwrite(s.c_str(), s.size(), 1, stdout);

{
std::stringstream ss;
ss << "W" << _graph->getImageSize().x;
ss << "W" << imageSize.x;
s = ss.str();
}
fwrite(s.c_str(), s.size(), 1, stdout);

{
std::stringstream ss;
ss << " H" << _graph->getImageSize().y;
ss << " H" << imageSize.y;
s = ss.str();
}
fwrite(s.c_str(), s.size(), 1, stdout);
Expand Down
5 changes: 3 additions & 2 deletions bin/toucan-render/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ namespace toucan

private:
void _writeRawFrame(const OIIO::ImageBuf&);
void _writeY4mHeader();
void _writeY4mHeader(const IMATH_NAMESPACE::V2i&);
void _writeY4mFrame(const OIIO::ImageBuf&);

struct CmdLine
{
std::shared_ptr<ftk::CmdLineValueArg<std::string> > input;
std::shared_ptr<ftk::CmdLineValueArg<std::string> > output;
bool outputRaw = false;

std::shared_ptr<ftk::CmdLineValueOption<std::string> > videoCodec;
std::shared_ptr<ftk::CmdLineValueOption<float> > scale;
std::shared_ptr<ftk::CmdLineFlagOption> printStart;
std::shared_ptr<ftk::CmdLineFlagOption> printDuration;
std::shared_ptr<ftk::CmdLineFlagOption> printRate;
Expand Down
2 changes: 1 addition & 1 deletion cmake/SuperBuild/Buildyaml-cpp.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include(ExternalProject)

set(yaml-cpp_GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp.git")
set(yaml-cpp_GIT_TAG "yaml-cpp-0.7.0")
set(yaml-cpp_GIT_TAG "yaml-cpp-0.9.0")

set(yaml-cpp_ARGS
${toucan_EXTERNAL_PROJECT_ARGS}
Expand Down
6 changes: 5 additions & 1 deletion lib/toucanRender/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ else()
PluginUnix.cpp)
endif()

find_package(PkgConfig REQUIRED)
pkg_check_modules(FFmpeg REQUIRED IMPORTED_TARGET libavcodec libavformat libavutil libswscale)

add_library(toucanRender ${HEADERS} ${HEADERS_PRIVATE} ${SOURCE})
set(LIBS_PUBLIC
toucanResource
Expand All @@ -51,7 +54,8 @@ set(LIBS_PUBLIC
OTIO::opentime
lunasvg::lunasvg
OpenImageIO::OpenImageIO
MINIZIP::minizip)
MINIZIP::minizip
PkgConfig::FFmpeg)
if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
list(APPEND LIBS_PUBLIC stdc++fs)
endif()
Expand Down