Made the player work, first WIP version
This commit is contained in:
+3
-3
@@ -201,7 +201,7 @@ MediaFile::getStreams(Stream::Type type) const
|
||||
return res;
|
||||
}
|
||||
|
||||
int
|
||||
boost::optional<std::size_t>
|
||||
MediaFile::getBestStreamId(Stream::Type type) const
|
||||
{
|
||||
if (_context == nullptr)
|
||||
@@ -215,7 +215,7 @@ MediaFile::getBestStreamId(Stream::Type type) const
|
||||
case Stream::Type::Video: avMediaType = AVMEDIA_TYPE_VIDEO; break;
|
||||
case Stream::Type::Subtitle: avMediaType = AVMEDIA_TYPE_SUBTITLE; break;
|
||||
default:
|
||||
return -1;
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
int res = av_find_best_stream(_context,
|
||||
@@ -227,7 +227,7 @@ MediaFile::getBestStreamId(Stream::Type type) const
|
||||
if (res < 0)
|
||||
{
|
||||
LMS_LOG(AV, ERROR) << "Cannot find best stream for type " << streamType_to_string(type);
|
||||
return -1;
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
+2
-1
@@ -35,6 +35,7 @@ extern "C"
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp> //no i/o just types
|
||||
|
||||
@@ -84,7 +85,7 @@ class MediaFile
|
||||
std::map<std::string, std::string> getMetaData(void);
|
||||
|
||||
std::vector<Stream> getStreams(Stream::Type type) const;
|
||||
int getBestStreamId(Stream::Type type) const; // -1 if failure/unknown
|
||||
boost::optional<std::size_t> getBestStreamId(Stream::Type type) const; // none if failure/unknown
|
||||
bool hasAttachedPictures(void) const;
|
||||
std::vector<Picture> getAttachedPictures(std::size_t nbMaxPictures) const;
|
||||
|
||||
|
||||
+14
-57
@@ -39,11 +39,8 @@ static std::vector<EncodingInfo> encodingInfos =
|
||||
{
|
||||
{Encoding::MP3, "audio/mp3", 0},
|
||||
{Encoding::OGA, "audio/ogg", 1},
|
||||
{Encoding::OGV, "video/ogg", 2},
|
||||
{Encoding::WEBMA, "audio/webm", 3},
|
||||
{Encoding::WEBMV, "video/webm", 4},
|
||||
{Encoding::M4A, "audio/mp4", 5},
|
||||
{Encoding::M4V, "video/mp4", 6},
|
||||
};
|
||||
|
||||
std::string encoding_to_mimetype(Encoding encoding)
|
||||
@@ -139,10 +136,10 @@ Transcoder::start()
|
||||
args.push_back("-nostdin");
|
||||
|
||||
// input Offset
|
||||
if (_parameters.getOffset().total_seconds() > 0)
|
||||
if (_parameters.offset.total_seconds() > 0)
|
||||
{
|
||||
args.push_back("-ss");
|
||||
args.push_back(std::to_string(_parameters.getOffset().total_seconds()));
|
||||
args.push_back(std::to_string(_parameters.offset.total_seconds()));
|
||||
}
|
||||
|
||||
// Input file
|
||||
@@ -151,20 +148,24 @@ Transcoder::start()
|
||||
|
||||
// Output bitrates
|
||||
args.push_back("-b:a");
|
||||
args.push_back(std::to_string(_parameters.getBitrate(Stream::Type::Audio)));
|
||||
// if (_parameters.getOutputFormat().getType() == Format::Video)
|
||||
// oss << " -b:v " << _parameters.getOutputBitrate(Stream::Video);
|
||||
args.push_back(std::to_string(_parameters.bitrate));
|
||||
|
||||
// Stream mapping
|
||||
for (int streamId : _parameters.getSelectedStreamIds())
|
||||
// Stream mapping, if set
|
||||
if (_parameters.stream)
|
||||
{
|
||||
// 0 means the first input file
|
||||
args.push_back("-map");
|
||||
args.push_back("0:" + std::to_string(streamId));
|
||||
args.push_back("0:" + std::to_string(*_parameters.stream));
|
||||
}
|
||||
|
||||
// Strip metadata
|
||||
args.push_back("-map_metadata");
|
||||
args.push_back("-1");
|
||||
|
||||
// Skip video flows (including covers)
|
||||
args.push_back("-vn");
|
||||
|
||||
// Codecs and formats
|
||||
switch( _parameters.getEncoding())
|
||||
switch( _parameters.encoding)
|
||||
{
|
||||
case Encoding::MP3:
|
||||
args.push_back("-f");
|
||||
@@ -178,20 +179,6 @@ Transcoder::start()
|
||||
args.push_back("ogg");
|
||||
break;
|
||||
|
||||
case Encoding::OGV:
|
||||
args.push_back("-acodec");
|
||||
args.push_back("libvorbis");
|
||||
args.push_back("-ac");
|
||||
args.push_back("2");
|
||||
args.push_back("-ar");
|
||||
args.push_back("44100");
|
||||
args.push_back("-vcodec");
|
||||
args.push_back("libtheora");
|
||||
args.push_back("-threads");
|
||||
args.push_back("4");
|
||||
args.push_back("-f");
|
||||
args.push_back("ogg");
|
||||
break;
|
||||
case Encoding::WEBMA:
|
||||
args.push_back("-codec:a");
|
||||
args.push_back("libvorbis");
|
||||
@@ -199,21 +186,6 @@ Transcoder::start()
|
||||
args.push_back("webm");
|
||||
break;
|
||||
|
||||
case Encoding::WEBMV:
|
||||
args.push_back("-acodec");
|
||||
args.push_back("libvorbis");
|
||||
args.push_back("-ac");
|
||||
args.push_back("2");
|
||||
args.push_back("-ar");
|
||||
args.push_back("44100");
|
||||
args.push_back("-vcodec");
|
||||
args.push_back("libvpx");
|
||||
args.push_back("-threads");
|
||||
args.push_back("4");
|
||||
args.push_back("-f");
|
||||
args.push_back("webm");
|
||||
break;
|
||||
|
||||
case Encoding::M4A:
|
||||
args.push_back("-acodec");
|
||||
args.push_back("aac");
|
||||
@@ -223,21 +195,6 @@ Transcoder::start()
|
||||
args.push_back("experimental");
|
||||
break;
|
||||
|
||||
case Encoding::M4V:
|
||||
args.push_back("-acodec");
|
||||
args.push_back("aac");
|
||||
args.push_back("-strict");
|
||||
args.push_back("experimental");
|
||||
args.push_back("-ac");
|
||||
args.push_back("2");
|
||||
args.push_back("-ar");
|
||||
args.push_back("-44100");
|
||||
args.push_back("-vcodec");
|
||||
args.push_back("libx264");
|
||||
args.push_back("-f");
|
||||
args.push_back("m4v");
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
+8
-27
@@ -25,8 +25,8 @@
|
||||
#include <pstreams/pstream.h>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp> //no i/o just types
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "AvInfo.hpp"
|
||||
|
||||
@@ -39,42 +39,23 @@ enum class Encoding
|
||||
OGV,
|
||||
MP3,
|
||||
WEBMA,
|
||||
WEBMV,
|
||||
M4A,
|
||||
M4V,
|
||||
};
|
||||
|
||||
std::string encoding_to_mimetype(Encoding encoding);
|
||||
int encoding_to_int(Encoding encoding);
|
||||
Encoding encoding_from_int(int encoding);
|
||||
|
||||
class TranscodeParameters
|
||||
struct TranscodeParameters
|
||||
{
|
||||
public:
|
||||
Encoding encoding = Encoding::MP3;
|
||||
boost::optional<std::size_t> stream = boost::none; // Id of the stream to be transcoded (auto detect by default)
|
||||
std::size_t bitrate = 128000;
|
||||
boost::posix_time::time_duration offset = boost::posix_time::seconds(0);
|
||||
|
||||
// Setters
|
||||
void setEncoding(Encoding encoding) { _encoding = encoding; }
|
||||
void setOffset(boost::posix_time::time_duration offset) {_offset = offset; }
|
||||
void setBitrate(Stream::Type type, std::size_t bitrate) { _outputBitrate[type] = bitrate; }
|
||||
|
||||
// Manually add the streams to be transcoded
|
||||
// If no stream is added, input streams are selected automatically
|
||||
void addStream(int inputStreamId) { _selectedStreams.insert(inputStreamId); }
|
||||
|
||||
// Getters
|
||||
Encoding getEncoding(void) const { return _encoding; }
|
||||
boost::posix_time::time_duration getOffset(void) const { return _offset; }
|
||||
std::set<int> getSelectedStreamIds(void) const { return _selectedStreams; }
|
||||
std::size_t getBitrate(Stream::Type type) { return _outputBitrate[type]; }
|
||||
|
||||
private:
|
||||
Encoding _encoding = Encoding::MP3;
|
||||
boost::posix_time::time_duration _offset = boost::posix_time::seconds(0);
|
||||
std::set<int> _selectedStreams;
|
||||
std::map<Stream::Type, std::size_t> _outputBitrate = { {Stream::Type::Audio, 0}, { Stream::Type::Video, 0}, { Stream::Type::Subtitle, 0} };
|
||||
TranscodeParameters() {}
|
||||
};
|
||||
|
||||
|
||||
class Transcoder
|
||||
{
|
||||
public:
|
||||
@@ -89,7 +70,7 @@ class Transcoder
|
||||
|
||||
bool start();
|
||||
void process(std::vector<unsigned char>& output, std::size_t maxSize);
|
||||
bool isComplete(void) { return _isComplete; }
|
||||
bool isComplete(void) const { return _isComplete; }
|
||||
|
||||
const TranscodeParameters& getParameters() const { return _parameters; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user