- Notifications
You must be signed in to change notification settings - Fork50
Support external encoder#313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
10 commits Select commitHold shift + click to select a range
7fcc1b6
changes to support FFmpeg 4.1
MarcAntoine-Arnaudc2106bd
Travis: update FFmpeg version to 4.*
valnoel1c95f19
Travis: use Python3 for unit tests
valnoel37af8e4
Appveyor: update FFmpeg version to 4.* and use Python3 for unit tests
valnoelb49c7c0
Update unit tests
valnoel8eee769
add API to use an external encoder
MarcAntoine-Arnaudaa434a8
pass copy to private
MarcAntoine-Arnaud5e16a85
remove copy of contructors
MarcAntoine-Arnaudd4241d0
StreamTranscoder: fix output AudioFrameDesc when an encoder is specified
valnoel6671f36
Add OutputFile unit test
valnoelFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
38 changes: 23 additions & 15 deletions.travis.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionsCMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsapp/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletionsapp/customEncoder/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
### cpp/customEncoder | ||
# Load custom cmake utilities | ||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) | ||
include(AvTranscoderMacros) | ||
# Build app | ||
add_executable(custom-encoder customEncoder.cpp) | ||
set_target_properties(custom-encoder PROPERTIES VERSION ${AVTRANSCODER_VERSION}) | ||
target_link_libraries(custom-encoder avtranscoder-shared) | ||
# Install app | ||
if(WIN32) | ||
set(BINARY_FILES "${CMAKE_CURRENT_BINARY_DIR}/custom-encoder.exe") | ||
else() | ||
set(BINARY_FILES "${CMAKE_CURRENT_BINARY_DIR}/custom-encoder" "${CMAKE_CURRENT_BINARY_DIR}/custom-encoder-${AVTRANSCODER_VERSION}") | ||
endif() | ||
install( | ||
FILES ${BINARY_FILES} | ||
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE | ||
DESTINATION "bin/" | ||
OPTIONAL | ||
) |
208 changes: 208 additions & 0 deletionsapp/customEncoder/customEncoder.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
#include <AvTranscoder/transcoder/Transcoder.hpp> | ||
#include <AvTranscoder/file/OutputFile.hpp> | ||
#include <AvTranscoder/progress/ConsoleProgress.hpp> | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <vector> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <cstdlib> | ||
void parseConfigFile(const std::string& configFilename, avtranscoder::Transcoder& transcoder) | ||
{ | ||
std::ifstream configFile(configFilename.c_str(), std::ifstream::in); | ||
std::string line; | ||
while(std::getline(configFile, line)) | ||
{ | ||
std::istringstream is_line(line); | ||
std::string filename; | ||
if(std::getline(is_line, filename, '=')) | ||
{ | ||
std::string streamId; | ||
if(std::getline(is_line, streamId, ':')) | ||
{ | ||
std::string transcodeProfile; | ||
std::getline(is_line, transcodeProfile); | ||
std::stringstream ss(streamId); | ||
size_t streamIndex = 0; | ||
char separator = 'x'; | ||
std::vector<size_t> channelIndexArray; | ||
ss >> streamIndex; | ||
ss >> separator; | ||
if(separator == '.') | ||
{ | ||
int subStreamIndex = -1; | ||
ss >> subStreamIndex; | ||
channelIndexArray.push_back(subStreamIndex); | ||
} | ||
// generated stream | ||
if(!filename.length()) | ||
transcoder.addGenerateStream(transcodeProfile); | ||
else | ||
{ | ||
avtranscoder::InputStreamDesc inputDesc(filename, streamIndex, channelIndexArray); | ||
transcoder.addStream(inputDesc, transcodeProfile); | ||
} | ||
} | ||
} | ||
} | ||
configFile.close(); | ||
} | ||
class AvExport CustomCodec | ||
: public avtranscoder::ICodec | ||
{ | ||
public: | ||
CustomCodec() | ||
: avtranscoder::ICodec(avtranscoder::eCodecTypeEncoder, AV_CODEC_ID_PCM_S24LE) | ||
{ | ||
} | ||
void openCodec(){} | ||
void closeCodec(){} | ||
std::string getCodecName() const { return "Custom Encoder"; }; | ||
AVCodecID getCodecId() const { return AV_CODEC_ID_PCM_S24LE; } | ||
avtranscoder::ECodecType getCodecType() const { return avtranscoder::eCodecTypeEncoder; } | ||
int getLatency() const { return 0; } | ||
avtranscoder::OptionArray getOptions() { | ||
std::vector<avtranscoder::Option> options; | ||
return options; | ||
} | ||
}; | ||
class AvExport CustomEncoder | ||
: public avtranscoder::IEncoder | ||
{ | ||
public: | ||
CustomEncoder() | ||
: _codec() | ||
{} | ||
/** | ||
* @brief Setup the encoder | ||
* @param profile: set encoder parameters from the given profile | ||
* @note Open the encoder. | ||
*/ | ||
void setupEncoder(const avtranscoder::ProfileLoader::Profile& profile = avtranscoder::ProfileLoader::Profile()) { | ||
return; | ||
}; | ||
/** | ||
* @brief Encode a new frame, and get coded frame | ||
* @param sourceFrame: frame that needs to be encoded | ||
* @param codedFrame: output encoded coded data (first frames can be delayed) | ||
* @return status of encoding | ||
* @throw runtime_error if the encoded process failed. | ||
*/ | ||
bool encodeFrame(const avtranscoder::IFrame& sourceFrame, avtranscoder::CodedData& codedFrame) { | ||
codedFrame.assign(5760, 0); | ||
return true; | ||
}; | ||
/** | ||
* @brief Get the frames remaining into the encoder | ||
* @param codedFrame: output encoded data | ||
* @return status of encoding | ||
* @throw runtime_error if the encoded process failed. | ||
*/ | ||
bool encodeFrame(avtranscoder::CodedData& codedFrame) { | ||
return false; | ||
}; | ||
/** | ||
* @brief Get codec used for encoding. | ||
* @return a reference to the codec | ||
*/ | ||
avtranscoder::ICodec& getCodec() { | ||
return _codec; | ||
}; | ||
private: | ||
CustomCodec _codec; | ||
}; | ||
int main(int argc, char** argv) | ||
{ | ||
std::string help; | ||
help += "Usage\n"; | ||
help += "\tavprocessor INPUT_FILE_NAME OUTPUT_FILE_NAME [--verbose] [--logFile] [--help]\n"; | ||
help += "Command line options\n"; | ||
help += "\t--verbose: set log level to AV_LOG_DEBUG\n"; | ||
help += "\t--logFile: put log in 'avtranscoder.log' file\n"; | ||
help += "\t--help: display this help\n"; | ||
// Preload FFmpeg context | ||
avtranscoder::preloadCodecsAndFormats(); | ||
avtranscoder::Logger::setLogLevel(AV_LOG_QUIET); | ||
// List command line arguments | ||
std::vector<std::string> arguments; | ||
for(int argument = 1; argument < argc; ++argument) | ||
{ | ||
arguments.push_back(argv[argument]); | ||
} | ||
for(size_t argument = 0; argument < arguments.size(); ++argument) | ||
{ | ||
if(arguments.at(argument) == "--help") | ||
{ | ||
std::cout << help << std::endl; | ||
return 0; | ||
} | ||
else if(arguments.at(argument) == "--verbose") | ||
{ | ||
avtranscoder::Logger::setLogLevel(AV_LOG_DEBUG); | ||
} | ||
else if(arguments.at(argument) == "--logFile") | ||
{ | ||
avtranscoder::Logger::logInFile(); | ||
} | ||
} | ||
// Check required arguments | ||
if(argc < 3) | ||
{ | ||
std::cout << "avprocessor can rewrap or transcode inputs to create an output media file." << std::endl; | ||
std::cout << "Use option --help to display help" << std::endl; | ||
return (-1); | ||
} | ||
try | ||
{ | ||
std::string output_format = "s24le"; | ||
avtranscoder::OutputFile outputFile(argv[2], output_format); | ||
avtranscoder::Transcoder transcoder(outputFile); | ||
transcoder.setProcessMethod(avtranscoder::eProcessMethodBasedOnStream); | ||
CustomEncoder* customEncoder = new CustomEncoder; | ||
avtranscoder::InputStreamDesc inputDescLeft(argv[1], 1, 0); | ||
avtranscoder::InputStreamDesc inputDescRight(argv[1], 2, 0); | ||
std::vector<avtranscoder::InputStreamDesc> inputDescriptors; | ||
inputDescriptors.push_back(avtranscoder::InputStreamDesc(argv[1], 1, 0)); | ||
inputDescriptors.push_back(avtranscoder::InputStreamDesc(argv[1], 2, 0)); | ||
transcoder.addStream(inputDescriptors, customEncoder); | ||
avtranscoder::ConsoleProgress progress; | ||
transcoder.process(progress); | ||
} | ||
catch(std::exception& e) | ||
{ | ||
std::cerr << "ERROR: during process, an error occured: " << e.what() << std::endl; | ||
} | ||
catch(...) | ||
{ | ||
std::cerr << "ERROR: during process, an unknown error occured" << std::endl; | ||
} | ||
} |
8 changes: 4 additions & 4 deletionsappveyor.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletionssrc/AvTranscoder/encoder/VideoEncoder.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletionssrc/AvTranscoder/file/IOutputFile.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.