diff --git a/conf/lms.conf b/conf/lms.conf index 7c310b0a..2c186cb3 100644 --- a/conf/lms.conf +++ b/conf/lms.conf @@ -4,6 +4,9 @@ # Must have write privileges in order to create and modify this directory working-dir = "/var/lms/"; +# ffmpeg location +ffmpeg-file = "/usr/bin/ffmpeg"; + # Log files, empty means stdout log-file = ""; access-log-file = ""; diff --git a/src/av/AvTranscoder.cpp b/src/av/AvTranscoder.cpp index 5ddc943e..d151e61a 100644 --- a/src/av/AvTranscoder.cpp +++ b/src/av/AvTranscoder.cpp @@ -22,7 +22,9 @@ #include #include +#include "main/Service.hpp" #include "AvInfo.hpp" +#include "utils/Config.hpp" #include "utils/Path.hpp" #include "utils/Logger.hpp" @@ -30,33 +32,15 @@ namespace Av { #define LMS_LOG_TRANSCODE(sev) LMS_LOG(TRANSCODE, sev) << "[" << _id << "] - " -// TODO, parametrize? -static const std::vector execNames = -{ - "avconv", - "ffmpeg", -}; - -static std::filesystem::path avConvPath = std::filesystem::path(); -static std::atomic globalId = {0}; +static std::atomic globalId {}; +static std::filesystem::path ffmpegPath; void Transcoder::init() { - for (const std::string& execName : execNames) - { - const std::filesystem::path p {searchExecPath(execName)}; - if (!p.empty()) - { - avConvPath = p; - break; - } - } - - if (!avConvPath.empty()) - LMS_LOG(TRANSCODE, INFO) << "Using transcoder " << avConvPath.string(); - else - throw AvException("Cannot find any transcoder binary!"); + ffmpegPath = getService()->getPath("ffmpeg-file", "/usr/bin/ffmpeg"); + if (!std::filesystem::exists(ffmpegPath)) + throw LmsException {"File '" + ffmpegPath.string() + "' does not exist!"}; } Transcoder::Transcoder(const std::filesystem::path& filePath, const TranscodeParameters& parameters) @@ -79,7 +63,7 @@ Transcoder::start() std::vector args; - args.emplace_back(avConvPath.string()); + args.emplace_back(ffmpegPath.string()); // Make sure we do not produce anything in the stderr output // in order not to block the whole forked process @@ -190,7 +174,7 @@ Transcoder::start() _child = std::make_shared(); // Caution: stdin must have been closed before - _child->open(avConvPath.string(), args); + _child->open(ffmpegPath.string(), args); if (!_child->is_open()) { LMS_LOG_TRANSCODE(DEBUG) << "Exec failed!"; diff --git a/src/utils/Path.cpp b/src/utils/Path.cpp index e8bc9c49..f256fd6b 100644 --- a/src/utils/Path.cpp +++ b/src/utils/Path.cpp @@ -28,31 +28,6 @@ #include "utils/Exception.hpp" #include "utils/Logger.hpp" -std::filesystem::path searchExecPath(std::string filename) -{ - std::string path; - - path = ::getenv("PATH"); - if (path.empty()) - throw LmsException("Environment variable PATH not found"); - - std::string result; - using tokenizer = boost::tokenizer>; - boost::char_separator sep(":"); - tokenizer tok(path, sep); - for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it) - { - std::filesystem::path p = *it; - p /= filename; - if (!::access(p.c_str(), X_OK)) - { - result = p.string(); - break; - } - } - return result; -} - void computeCrc(const std::filesystem::path& p, std::vector& crc) { using crc_type = boost::crc_32_type; diff --git a/src/utils/Path.hpp b/src/utils/Path.hpp index cd6f37ad..56e40587 100644 --- a/src/utils/Path.hpp +++ b/src/utils/Path.hpp @@ -23,8 +23,6 @@ #include #include -std::filesystem::path searchExecPath(std::string filename); - void computeCrc(const std::filesystem::path& p, std::vector& checksum); // Make sure the given path is a directory