From a861023c28159c363d49dce4f79a92debdc4241e Mon Sep 17 00:00:00 2001 From: "Simon A. Eugster" Date: Sat, 11 Feb 2012 16:08:38 +0100 Subject: [PATCH] Audio alignment: Attempts to get familiar with mlt --- CMakeLists.txt | 1 + testingArea/CMakeLists.txt | 15 ++++++ testingArea/audioOffset.cpp | 100 ++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 testingArea/CMakeLists.txt create mode 100644 testingArea/audioOffset.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 45aeff18..d2a161b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ add_subdirectory(renderer) add_subdirectory(src) add_subdirectory(thumbnailer) add_subdirectory(titles) +add_subdirectory(testingArea) macro_display_feature_log() diff --git a/testingArea/CMakeLists.txt b/testingArea/CMakeLists.txt new file mode 100644 index 00000000..1b863b16 --- /dev/null +++ b/testingArea/CMakeLists.txt @@ -0,0 +1,15 @@ + +message(STATUS "Building experimental executables") + +include_directories( + ${LIBMLT_INCLUDE_DIR} + ${LIBMLTPLUS_INCLUDE_DIR} +) +include(${QT_USE_FILE}) + +add_executable(audioOffset audioOffset.cpp) +target_link_libraries(audioOffset + ${QT_LIBRARIES} + ${LIBMLT_LIBRARY} + ${LIBMLTPLUS_LIBRARY} +) diff --git a/testingArea/audioOffset.cpp b/testingArea/audioOffset.cpp new file mode 100644 index 00000000..6e9a0b55 --- /dev/null +++ b/testingArea/audioOffset.cpp @@ -0,0 +1,100 @@ + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + char *fileMain; + char *fileSub; + if (argc > 2) { + fileMain = argv[1]; + fileSub = argv[2]; + } else { + std::cout << "Usage: " << argv[0] << "
" << std::endl; + return 0; + } + std::cout << "Trying to align (1)\n\t" << fileSub << "\nto fit on (2)\n\t" << fileMain + << "\n, result will indicate by how much (1) has to be moved." << std::endl; + + + // Initialize MLT + Mlt::Factory::init(NULL); + + // Load an arbitrary profile + Mlt::Profile prof("hdv_1080_25p"); + + + std::cout << "MLT initialized, profile loaded. Loading clips ..." << std::endl; + + + Mlt::Producer producer(prof, fileMain); + if (!producer.is_valid()) { + std::cout << fileMain << " is invalid." << std::endl; + return 2; + } + std::cout << "Successfully loaded producer " << fileMain << std::endl; + std::cout << "Some data: " << std::endl + << "Length: " << producer.get_length() << std::endl + << "fps: " << producer.get_fps() << std::endl; + + int nSamples = 50; + Mlt::Frame *frame = producer.get_frame(); + float *data = frame->get_audio(mlt_audio_float, 24000, 1, nSamples); + + for (int i = 0; i < nSamples; i++) { + std::cout << " " << data[i]; + } + std::cout << std::endl; + +/* + producer.set("video_index", "-1"); + + if (KdenliveSettings::normaliseaudiothumbs()) { + Mlt::Filter m_convert(prof, "volume"); + m_convert.set("gain", "normalise"); + producer.attach(m_convert); + } + + int last_val = 0; + int val = 0; + double framesPerSecond = mlt_producer_get_fps(producer.get_producer()); + Mlt::Frame *mlt_frame; + + for (int z = (int) frame; z < (int)(frame + lengthInFrames) && producer.is_valid() && !m_abortAudioThumb; z++) { + val = (int)((z - frame) / (frame + lengthInFrames) * 100.0); + if (last_val != val && val > 1) { + setThumbsProgress(i18n("Creating audio thumbnail for %1", url.fileName()), val); + last_val = val; + } + producer.seek(z); + mlt_frame = producer.get_frame(); + if (mlt_frame && mlt_frame->is_valid()) { + int samples = mlt_sample_calculator(framesPerSecond, frequency, mlt_frame_get_position(mlt_frame->get_frame())); + qint16* pcm = static_cast(mlt_frame->get_audio(audioFormat, frequency, channels, samples)); + for (int c = 0; c < channels; c++) { + QByteArray audioArray; + audioArray.resize(arrayWidth); + for (int i = 0; i < audioArray.size(); i++) { + audioArray[i] = ((*(pcm + c + i * samples / audioArray.size())) >> 9) + 127 / 2 ; + } + f.write(audioArray); + storeIn[z][c] = audioArray; + } + } else { + f.write(QByteArray(arrayWidth, '\x00')); + } + delete mlt_frame; + } + f.close(); + setThumbsProgress(i18n("Creating audio thumbnail for %1", url.fileName()), -1); + if (m_abortAudioThumb) { + f.remove(); + } else { + clip->updateAudioThumbnail(storeIn); + }*/ + + return 0; + +} -- 2.39.2