Added a configuration option to specify ffmpeg binary location #5
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
# Must have write privileges in order to create and modify this directory
|
# Must have write privileges in order to create and modify this directory
|
||||||
working-dir = "/var/lms/";
|
working-dir = "/var/lms/";
|
||||||
|
|
||||||
|
# ffmpeg location
|
||||||
|
ffmpeg-file = "/usr/bin/ffmpeg";
|
||||||
|
|
||||||
# Log files, empty means stdout
|
# Log files, empty means stdout
|
||||||
log-file = "";
|
log-file = "";
|
||||||
access-log-file = "";
|
access-log-file = "";
|
||||||
|
|||||||
+9
-25
@@ -22,7 +22,9 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "main/Service.hpp"
|
||||||
#include "AvInfo.hpp"
|
#include "AvInfo.hpp"
|
||||||
|
#include "utils/Config.hpp"
|
||||||
#include "utils/Path.hpp"
|
#include "utils/Path.hpp"
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
@@ -30,33 +32,15 @@ namespace Av {
|
|||||||
|
|
||||||
#define LMS_LOG_TRANSCODE(sev) LMS_LOG(TRANSCODE, sev) << "[" << _id << "] - "
|
#define LMS_LOG_TRANSCODE(sev) LMS_LOG(TRANSCODE, sev) << "[" << _id << "] - "
|
||||||
|
|
||||||
// TODO, parametrize?
|
static std::atomic<size_t> globalId {};
|
||||||
static const std::vector<std::string> execNames =
|
static std::filesystem::path ffmpegPath;
|
||||||
{
|
|
||||||
"avconv",
|
|
||||||
"ffmpeg",
|
|
||||||
};
|
|
||||||
|
|
||||||
static std::filesystem::path avConvPath = std::filesystem::path();
|
|
||||||
static std::atomic<size_t> globalId = {0};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Transcoder::init()
|
Transcoder::init()
|
||||||
{
|
{
|
||||||
for (const std::string& execName : execNames)
|
ffmpegPath = getService<Config>()->getPath("ffmpeg-file", "/usr/bin/ffmpeg");
|
||||||
{
|
if (!std::filesystem::exists(ffmpegPath))
|
||||||
const std::filesystem::path p {searchExecPath(execName)};
|
throw LmsException {"File '" + ffmpegPath.string() + "' does not exist!"};
|
||||||
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!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transcoder::Transcoder(const std::filesystem::path& filePath, const TranscodeParameters& parameters)
|
Transcoder::Transcoder(const std::filesystem::path& filePath, const TranscodeParameters& parameters)
|
||||||
@@ -79,7 +63,7 @@ Transcoder::start()
|
|||||||
|
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
|
|
||||||
args.emplace_back(avConvPath.string());
|
args.emplace_back(ffmpegPath.string());
|
||||||
|
|
||||||
// Make sure we do not produce anything in the stderr output
|
// Make sure we do not produce anything in the stderr output
|
||||||
// in order not to block the whole forked process
|
// in order not to block the whole forked process
|
||||||
@@ -190,7 +174,7 @@ Transcoder::start()
|
|||||||
_child = std::make_shared<redi::ipstream>();
|
_child = std::make_shared<redi::ipstream>();
|
||||||
|
|
||||||
// Caution: stdin must have been closed before
|
// Caution: stdin must have been closed before
|
||||||
_child->open(avConvPath.string(), args);
|
_child->open(ffmpegPath.string(), args);
|
||||||
if (!_child->is_open())
|
if (!_child->is_open())
|
||||||
{
|
{
|
||||||
LMS_LOG_TRANSCODE(DEBUG) << "Exec failed!";
|
LMS_LOG_TRANSCODE(DEBUG) << "Exec failed!";
|
||||||
|
|||||||
@@ -28,31 +28,6 @@
|
|||||||
#include "utils/Exception.hpp"
|
#include "utils/Exception.hpp"
|
||||||
#include "utils/Logger.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<char>>;
|
|
||||||
boost::char_separator<char> 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<unsigned char>& crc)
|
void computeCrc(const std::filesystem::path& p, std::vector<unsigned char>& crc)
|
||||||
{
|
{
|
||||||
using crc_type = boost::crc_32_type;
|
using crc_type = boost::crc_32_type;
|
||||||
|
|||||||
@@ -23,8 +23,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::filesystem::path searchExecPath(std::string filename);
|
|
||||||
|
|
||||||
void computeCrc(const std::filesystem::path& p, std::vector<unsigned char>& checksum);
|
void computeCrc(const std::filesystem::path& p, std::vector<unsigned char>& checksum);
|
||||||
|
|
||||||
// Make sure the given path is a directory
|
// Make sure the given path is a directory
|
||||||
|
|||||||
Reference in New Issue
Block a user