diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 73f0dca2..00000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# .github/workflows/codety.yaml -name: Codety -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "**" ] -jobs: - Codety_Static_Code_Analysis: - runs-on: ubuntu-latest - permissions: - pull-requests: write - contents: read - container: - image: codetyio/codety - steps: - - uses: actions/checkout@main - - run: codety - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..33e13e23 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,147 @@ +name: Release + +on: + release: + types: + - created + push: + tags: + - "v*.*.*" + # push: + # branches: + # - 'main' + # pull_request: + # branches: + # - '**' + +jobs: + build: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Checkout BMF repository (specific branch) + run: | + sudo apt update + sudo apt install -y make git pkg-config libssl-dev cmake binutils-dev libgoogle-glog-dev gcc g++ golang wget libgl1 + sudo apt install -y python3.9 python3-dev python3-pip libsndfile1 libsndfile1-dev + # sudo python3 -m pip install timeout_decorator numpy onnxruntime pytest opencv-python librosa + + git clone https://github.com/JackLau1222/bmf.git + + # - name: Cache FFmpeg build + # uses: actions/cache@v3 + # with: + # path: | + # /usr/local/bin/ffmpeg + # /usr/local/lib/ + # /usr/local/include/ + # key: ${{ runner.os }}-ffmpeg-${{ hashFiles('bmf/scripts/build_ffmpeg.sh') }} + # restore-keys: | + # ${{ runner.os }}-ffmpeg- + + # - name: Cache BMF build + # uses: actions/cache@v3 + # with: + # path: bmf/output/ + # key: ${{ runner.os }}-bmf-${{ hashFiles('bmf/build.sh') }} + # restore-keys: | + # ${{ runner.os }}-bmf- + + - name: Compile FFmpeg and BMF if not cached + run: | + if [ ! -f "/usr/local/bin/ffmpeg" ]; then + echo "FFmpeg not found, starting build..." + (cd bmf && git checkout fork_by_oc && sudo scripts/build_ffmpeg.sh nasm yasm x264 x265 opus && ./build.sh ) + else + echo "FFmpeg is already installed, skipping build." + fi + + - name: Set up BMF + run: | + cd bmf + echo "C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include" >> $GITHUB_ENV + echo "CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include" >> $GITHUB_ENV + echo "LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib" >> $GITHUB_ENV + + + - name: Set up Qt + run: | + sudo apt-get install -y qt5-qmake qtbase5-dev qtchooser qtbase5-dev-tools cmake build-essential + + - name: Build with CMake + run: | + (cd src && cmake -B build && cd build && make -j$(nproc)) + + # - name: Start tmate session for debugging + # uses: mxschmitt/action-tmate@v3 + # with: + # sudo: true + # duration: 7200 + + - name: Copy libs + run: | + # linuxdeployqt + sudo apt-get -y install git g++ libgl1-mesa-dev + git clone https://github.com/probonopd/linuxdeployqt.git + # Then build in Qt Creator, or use + export PATH=$(readlink -f /tmp/.mount_QtCreator-*-x86_64/*/gcc_64/bin/):$PATH + (cd linuxdeployqt && qmake && make && sudo make install) + # patchelf + wget https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.bz2 + tar xf patchelf-0.9.tar.bz2 + ( cd patchelf-0.9/ && ./configure && make && sudo make install ) + # appimage + sudo wget -c "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" -O /usr/local/bin/appimagetool + sudo chmod a+x /usr/local/bin/appimagetool + (linuxdeployqt/bin/linuxdeployqt ./src/build/OpenConverter -appimage) + continue-on-error: true + + + - name: Copy runtime + run: | + # mkdir /src/build/lib + cp /usr/local/lib/libswscale.so.6 src/build/lib + cp /usr/local/lib/libavfilter.so.8 src/build/lib + cp /usr/local/lib/libpostproc.so.56 src/build/lib + cp bmf/output/bmf/lib/libbuiltin_modules.so src/build/lib + cp bmf/output/bmf/BUILTIN_CONFIG.json src/build + touch src/build/activate_env.sh + echo export LD_LIBRARY_PATH="./lib" >> src/build/activate_env.sh + + # Step to package the build directory + - name: Create tar.gz package + run: | + # VERSION="1.3" + BUILD_DIR="src/build" + PACKAGE_NAME="OpenConverter_Linux_x86.tar.gz" + OUTPUT_DIR="OpenConverter_Linux_x86" + mkdir -p $OUTPUT_DIR + cp -r $BUILD_DIR/* $OUTPUT_DIR/ + tar -czvf $PACKAGE_NAME -C $OUTPUT_DIR . + rm -rf $OUTPUT_DIR + + # Step to upload the tar.gz package as an artifact + - name: Upload build artifact + uses: actions/upload-artifact@v3 + with: + name: OpenConverter_Linux_x86 + path: OpenConverter_Linux_x86.tar.gz + + + - name: Get GitHub Release information + id: release_info + run: echo "::set-output name=release_tag::$(echo ${GITHUB_REF#refs/tags/})" + + + - name: Upload Release Asset + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: ./build/OpenConverter_Linux_x86.tar.gz + + - name: Finish + run: echo "Release upload complete" \ No newline at end of file diff --git a/.github/workflows/review.yaml b/.github/workflows/review.yaml new file mode 100644 index 00000000..5f655d65 --- /dev/null +++ b/.github/workflows/review.yaml @@ -0,0 +1,123 @@ +name: Review + +on: + pull_request: + branches: + - '**' + +jobs: + build: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Checkout BMF repository (specific branch) + run: | + sudo apt update + sudo apt install -y make git pkg-config libssl-dev cmake binutils-dev libgoogle-glog-dev gcc g++ golang wget libgl1 + sudo apt install -y python3.9 python3-dev python3-pip libsndfile1 libsndfile1-dev + # sudo python3 -m pip install timeout_decorator numpy onnxruntime pytest opencv-python librosa + + git clone https://github.com/JackLau1222/bmf.git + + # - name: Cache FFmpeg build + # uses: actions/cache@v3 + # with: + # path: | + # /usr/local/bin/ffmpeg + # /usr/local/lib/libav* + # /usr/local/lib/libsw* + # /usr/local/lib/libpostproc* + # /usr/local/include/libav* + # /usr/local/include/libsw* + # /usr/local/include/libpostproc* + # key: ${{ runner.os }}-ffmpeg-${{ hashFiles('bmf/scripts/build_ffmpeg.sh') }} + # restore-keys: | + # ${{ runner.os }}-ffmpeg- + + # - name: Cache BMF build + # uses: actions/cache@v3 + # with: + # path: bmf/output/ + # key: ${{ runner.os }}-bmf-${{ hashFiles('bmf/build.sh') }} + # restore-keys: | + # ${{ runner.os }}-bmf- + + - name: Compile FFmpeg and BMF if not cached + run: | + if [ ! -f "/usr/local/bin/ffmpeg" ]; then + echo "FFmpeg not found, starting build..." + (cd bmf && git checkout fork_by_oc && sudo scripts/build_ffmpeg.sh nasm yasm x264 x265 opus && ./build.sh ) + else + echo "FFmpeg is already installed, skipping build." + fi + + - name: Set up BMF + run: | + cd bmf + echo "C_INCLUDE_PATH=${C_INCLUDE_PATH}:$(pwd)/output/bmf/include" >> $GITHUB_ENV + echo "CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:$(pwd)/output/bmf/include" >> $GITHUB_ENV + echo "LIBRARY_PATH=${LIBRARY_PATH}:$(pwd)/output/bmf/lib" >> $GITHUB_ENV + echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/output/bmf/lib" >> $GITHUB_ENV + + + - name: Set up Qt + run: | + sudo apt-get install -y qt5-qmake qtbase5-dev qtchooser qtbase5-dev-tools cmake build-essential + + - name: Build with CMake + run: | + (cd src && cmake -B build && cd build && make -j$(nproc)) + + - name: Copy libs + run: | + # linuxdeployqt + sudo apt-get -y install git g++ libgl1-mesa-dev + git clone https://github.com/probonopd/linuxdeployqt.git + # Then build in Qt Creator, or use + export PATH=$(readlink -f /tmp/.mount_QtCreator-*-x86_64/*/gcc_64/bin/):$PATH + (cd linuxdeployqt && qmake && make && sudo make install) + # patchelf + wget https://nixos.org/releases/patchelf/patchelf-0.9/patchelf-0.9.tar.bz2 + tar xf patchelf-0.9.tar.bz2 + ( cd patchelf-0.9/ && ./configure && make && sudo make install ) + # appimage + sudo wget -c "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" -O /usr/local/bin/appimagetool + sudo chmod a+x /usr/local/bin/appimagetool + (linuxdeployqt/bin/linuxdeployqt ./src/build/OpenConverter -appimage) + continue-on-error: true + + + - name: Copy runtime + run: | + # mkdir /src/build/lib + cp /usr/local/lib/libswscale.so.6 src/build/lib + cp /usr/local/lib/libavfilter.so.8 src/build/lib + cp /usr/local/lib/libpostproc.so.56 src/build/lib + cp bmf/output/bmf/lib/libbuiltin_modules.so src/build/lib + cp bmf/output/bmf/BUILTIN_CONFIG.json src/build + touch src/build/activate_env.sh + echo export LD_LIBRARY_PATH="./lib" >> src/build/activate_env.sh + + # Step to package the build directory + - name: Create tar.gz package + run: | + BUILD_DIR="src/build" + PACKAGE_NAME="OpenConverter_Linux_x86.tar.gz" + OUTPUT_DIR="OpenConverter_Linux_x86" + mkdir -p $OUTPUT_DIR + cp -r $BUILD_DIR/* $OUTPUT_DIR/ + tar -czvf $PACKAGE_NAME -C $OUTPUT_DIR . + rm -rf $OUTPUT_DIR + + # Step to upload the tar.gz package as an artifact + - name: Upload build artifact + uses: actions/upload-artifact@v3 + with: + name: OpenConverter_Linux_x86 + path: OpenConverter_Linux_x86.tar.gz + + - name: Finish + run: echo "Release upload complete" \ No newline at end of file diff --git a/.gitignore b/.gitignore index d63eeb1c..7f02bb22 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ open_converter.pro.user -build* +build-* .vscode .DS_Store -./src/.DS_Store \ No newline at end of file +./src/.DS_Store +src/CMakeLists.txt.user +src/build* \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..a5961127 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,178 @@ +cmake_minimum_required(VERSION 3.5) + +project(OpenConverter VERSION 1.2 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +option(USE_BMF_TRANSCODER "Use BMF Transcoder" ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +if(WIN32) + message(STATUS "This is a Windows platform.") + if (DEFINED ENV{FFMPEG_ROOT_PATH}) + set(FFMPEG_ROOT_PATH $ENV{FFMPEG_ROOT_PATH}) + else() + message(STATUS "FFMPEG_ROOT_PATH environment variable is not set, using default path.") + set(FFMPEG_ROOT_PATH "D:/ffmpeg/ffmpeg-n5.1.6-16-g6e63e49496-win64-gpl-shared-5.1/ffmpeg-n5.1.6-16-g6e63e49496-win64-gpl-shared-5.1") + endif() + set(FFMPEG_INCLUDE_DIRS ${FFMPEG_ROOT_PATH}/include) + set(FFMPEG_LIBRARY_DIRS ${FFMPEG_ROOT_PATH}/lib) +else() + # Ensure pkg-config is found + find_package(PkgConfig REQUIRED) + + # Find the FFmpeg libraries (avcodec, avformat, avutil) + pkg_check_modules(FFMPEG REQUIRED libavcodec libavformat libavfilter libavutil libswresample libswscale) +endif() + +## Use pkg-config to find x264 +#pkg_check_modules(X264 REQUIRED x264) + +## Use pkg-config to find x265 (if necessary) +#pkg_check_modules(X265 REQUIRED x265) + +# Add source files conditionally based on whether to use BMF or FFmpeg transcoder +if (USE_BMF_TRANSCODER) + # Check if the BMF_ROOT_PATH environment variable is set + if (DEFINED ENV{BMF_ROOT_PATH}) + set(BMF_ROOT_PATH $ENV{BMF_ROOT_PATH}) + else() + message(STATUS "BMF_ROOT_PATH environment variable is not set, using default path.") + # You can set a default path here if you want + set(BMF_ROOT_PATH "/Users/jacklau/Documents/Programs/Git/Github/bmf/output/bmf") + endif() + # Add BMF include and library directories + include_directories(${BMF_ROOT_PATH}/include) + link_directories(${BMF_ROOT_PATH}/lib) + + add_definitions(-DUSE_BMF) # Define a macro for BMF transcoder + list(APPEND SOURCES + ${CMAKE_SOURCE_DIR}/transcoder/src/transcoder_bmf.cpp + ) +else() + add_definitions(-DUSE_FFMPEG) # Define a macro for FFmpeg transcoder + list(APPEND SOURCES + ${CMAKE_SOURCE_DIR}/transcoder/src/transcoder_ffmpeg.cpp + ) +endif() + +# Add include directories for FFmpeg +include_directories( + ${FFMPEG_INCLUDE_DIRS} +) + +link_directories( + ${FFMPEG_LIBRARY_DIRS} +) + +# Add common source files +list(APPEND SOURCES + ${CMAKE_SOURCE_DIR}/main.cpp + ${CMAKE_SOURCE_DIR}/builder/src/encode_setting.cpp + ${CMAKE_SOURCE_DIR}/builder/src/open_converter.cpp + ${CMAKE_SOURCE_DIR}/common/src/encode_parameter.cpp + ${CMAKE_SOURCE_DIR}/common/src/info.cpp + ${CMAKE_SOURCE_DIR}/common/src/process_parameter.cpp + ${CMAKE_SOURCE_DIR}/common/src/stream_context.cpp + ${CMAKE_SOURCE_DIR}/engine/src/converter.cpp +) + +# Add header files +set(HEADERS + ${CMAKE_SOURCE_DIR}/builder/include/encode_setting.h + ${CMAKE_SOURCE_DIR}/builder/include/open_converter.h + ${CMAKE_SOURCE_DIR}/common/include/encode_parameter.h + ${CMAKE_SOURCE_DIR}/common/include/info.h + ${CMAKE_SOURCE_DIR}/common/include/process_parameter.h + ${CMAKE_SOURCE_DIR}/common/include/stream_context.h + ${CMAKE_SOURCE_DIR}/engine/include/converter.h + ${CMAKE_SOURCE_DIR}/transcoder/include/transcoder.h + ${CMAKE_SOURCE_DIR}/transcoder/include/transcoder_bmf.h + ${CMAKE_SOURCE_DIR}/transcoder/include/transcoder_ffmpeg.h +) + +# Add UI files +set(UI_FILES + ${CMAKE_SOURCE_DIR}/builder/src/encode_setting.ui + ${CMAKE_SOURCE_DIR}/builder/src/open_converter.ui +) + +# Add resource files +set(RESOURCE_FILES + ${CMAKE_SOURCE_DIR}/resources/lang.qrc +) + +# Handle MOC, UIC, and RCC (Qt build steps) +# Automatically handle UI files using UIC +#qt_wrap_ui(UI_HEADERS ${UI_FILES}) +# qt_add_resources(RESOURCE_OBJECTS ${RESOURCE_FILES}) +# qt_wrap_cpp(MOC_HEADERS ${HEADERS}) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(OpenConverter + MANUAL_FINALIZATION + ${SOURCES} ${UI_FILES} ${RESOURCE_FILES} ${HEADERS} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET OpenConverter APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(OpenConverter SHARED + ${SOURCES} ${UI_FILES} ${RESOURCE_FILES} ${HEADERS} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(OpenConverter + ${SOURCES} ${UI_FILES} ${RESOURCE_FILES} ${HEADERS} + ) + endif() +endif() + +target_link_libraries(OpenConverter + PRIVATE Qt${QT_VERSION_MAJOR}::Widgets + avformat + avcodec + avutil + pthread + swresample +) + +if(USE_BMF_TRANSCODER) + target_link_libraries(OpenConverter PRIVATE + engine + bmf_module_sdk + hmp + builtin_modules + ) +endif() + +# Set translation files +set(TRANSLATIONS ${CMAKE_SOURCE_DIR}/resources/lang_chinese.ts) + +set_target_properties(OpenConverter PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +install(TARGETS OpenConverter + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(OpenConverter) +endif() diff --git a/src/encode_setting.h b/src/builder/include/encode_setting.h similarity index 96% rename from src/encode_setting.h rename to src/builder/include/encode_setting.h index 6b0123ae..61577b9f 100644 --- a/src/encode_setting.h +++ b/src/builder/include/encode_setting.h @@ -19,7 +19,7 @@ #define ENCODE_SETTING_H #include -#include "encode_parameter.h" +#include "../../common/include/encode_parameter.h" namespace Ui { class EncodeSetting; diff --git a/src/open_converter.h b/src/builder/include/open_converter.h similarity index 96% rename from src/open_converter.h rename to src/builder/include/open_converter.h index 4595ce7f..0c0a8d5b 100644 --- a/src/open_converter.h +++ b/src/builder/include/open_converter.h @@ -19,8 +19,8 @@ #define OPEN_CONVERTER_H #include -#include "info.h" -#include "converter.h" +#include "../../common/include/info.h" +#include "../../engine/include/converter.h" #include "encode_setting.h" #include #include diff --git a/src/encode_setting.cpp b/src/builder/src/encode_setting.cpp similarity index 97% rename from src/encode_setting.cpp rename to src/builder/src/encode_setting.cpp index ec866052..cb62744f 100644 --- a/src/encode_setting.cpp +++ b/src/builder/src/encode_setting.cpp @@ -1,4 +1,4 @@ -#include "encode_setting.h" +#include "../include/encode_setting.h" #include "ui_encode_setting.h" /* Receive pointers from widget */ diff --git a/src/encode_setting.ui b/src/builder/src/encode_setting.ui similarity index 100% rename from src/encode_setting.ui rename to src/builder/src/encode_setting.ui diff --git a/src/open_converter.cpp b/src/builder/src/open_converter.cpp similarity index 99% rename from src/open_converter.cpp rename to src/builder/src/open_converter.cpp index 0b6b338e..cf2c6539 100644 --- a/src/open_converter.cpp +++ b/src/builder/src/open_converter.cpp @@ -1,4 +1,4 @@ -#include "open_converter.h" +#include "../include/open_converter.h" #include "ui_open_converter.h" OpenConverter::OpenConverter(QWidget *parent) diff --git a/src/open_converter.ui b/src/builder/src/open_converter.ui similarity index 100% rename from src/open_converter.ui rename to src/builder/src/open_converter.ui diff --git a/src/LICENSE b/src/common/LICENSE similarity index 100% rename from src/LICENSE rename to src/common/LICENSE diff --git a/src/encode_parameter.h b/src/common/include/encode_parameter.h similarity index 98% rename from src/encode_parameter.h rename to src/common/include/encode_parameter.h index 3ac01000..3763f468 100644 --- a/src/encode_parameter.h +++ b/src/common/include/encode_parameter.h @@ -19,6 +19,7 @@ #define ENCODEPARAMETER_H #include +#include class EncodeParameter { private: diff --git a/src/info.h b/src/common/include/info.h similarity index 100% rename from src/info.h rename to src/common/include/info.h diff --git a/src/process_parameter.h b/src/common/include/process_parameter.h similarity index 98% rename from src/process_parameter.h rename to src/common/include/process_parameter.h index ff015919..1a6569ac 100644 --- a/src/process_parameter.h +++ b/src/common/include/process_parameter.h @@ -47,7 +47,7 @@ class ProcessParameter : public QObject { void update_Time_Required(double result); private: - double processNumber; + int64_t processNumber; double timeRequired; }; diff --git a/src/stream_context.h b/src/common/include/stream_context.h similarity index 97% rename from src/stream_context.h rename to src/common/include/stream_context.h index b7c504f0..1e26abf2 100644 --- a/src/stream_context.h +++ b/src/common/include/stream_context.h @@ -29,7 +29,7 @@ class StreamContext { ~StreamContext(); AVFormatContext *fmtCtx = NULL; - char *filename = NULL; + const char *filename = NULL; int videoIdx; AVStream *videoStream = NULL; diff --git a/src/encode_parameter.cpp b/src/common/src/encode_parameter.cpp similarity index 96% rename from src/encode_parameter.cpp rename to src/common/src/encode_parameter.cpp index 1420d806..34b75728 100644 --- a/src/encode_parameter.cpp +++ b/src/common/src/encode_parameter.cpp @@ -1,4 +1,4 @@ -#include "encode_parameter.h" +#include "../include/encode_parameter.h" EncodeParameter::EncodeParameter() { videoCodec = ""; diff --git a/src/info.cpp b/src/common/src/info.cpp similarity index 99% rename from src/info.cpp rename to src/common/src/info.cpp index 562ae37e..f0ecfc08 100644 --- a/src/info.cpp +++ b/src/common/src/info.cpp @@ -1,4 +1,4 @@ -#include "info.h" +#include "../include/info.h" Info::Info() { quickInfo = new QuickInfo(); diff --git a/src/process_parameter.cpp b/src/common/src/process_parameter.cpp similarity index 80% rename from src/process_parameter.cpp rename to src/common/src/process_parameter.cpp index 6b1e09f8..65061ab6 100644 --- a/src/process_parameter.cpp +++ b/src/common/src/process_parameter.cpp @@ -1,5 +1,4 @@ -#include "process_parameter.h" -// #include "moc_process_parameter.h" +#include "../include/process_parameter.h" ProcessParameter::ProcessParameter(QObject *parent) : QObject(parent) { processNumber = 0; @@ -9,7 +8,7 @@ ProcessParameter::ProcessParameter(QObject *parent) : QObject(parent) { void ProcessParameter::set_Process_Number(int64_t frameNumber, int64_t frameTotalNumnber) { - double result = (double)frameNumber / (double)frameTotalNumnber; + int64_t result = (double)frameNumber / (double)frameTotalNumnber * 100 ; if (processNumber != result) { processNumber = result; emit update_Process_Number(result); @@ -18,6 +17,7 @@ void ProcessParameter::set_Process_Number(int64_t frameNumber, void ProcessParameter::set_Process_Number(int64_t processNumber) { if (processNumber > 0) + this->processNumber = processNumber; emit update_Process_Number(processNumber); } @@ -32,8 +32,8 @@ void ProcessParameter::set_Time_Required(double timeRequired) { double ProcessParameter::get_Time_Required() { return timeRequired; } -ProcessParameter get_Process_Parmeter() { - // TODO -} +//ProcessParameter get_Process_Parmeter() { +// // TODO +//} ProcessParameter::~ProcessParameter() {} diff --git a/src/stream_context.cpp b/src/common/src/stream_context.cpp similarity index 89% rename from src/stream_context.cpp rename to src/common/src/stream_context.cpp index d0f72f23..562678b5 100644 --- a/src/stream_context.cpp +++ b/src/common/src/stream_context.cpp @@ -1,4 +1,4 @@ -#include "stream_context.h" +#include "../include/stream_context.h" StreamContext::StreamContext() { fmtCtx = NULL; diff --git a/src/converter.cpp b/src/converter.cpp deleted file mode 100644 index d75c8b89..00000000 --- a/src/converter.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "converter.h" - -Converter::Converter() {} -/* Receive pointers from widget */ -Converter::Converter(ProcessParameter *processParamter, - EncodeParameter *encodeParamter) - : processParameter(processParamter), encodeParameter(encodeParamter) { - transcoder = new Transcoder(this->processParameter, this->encodeParameter); - transcoder_bmf = new TranscoderBMF(this->processParameter, this->encodeParameter); - this->encodeParameter = encodeParamter; -} - -void Converter::convert_Format(QString src, QString dst) { - if (encodeParameter->get_Video_Codec_Name() == "") { - copyVideo = true; - } else { - copyVideo = false; - } - - if (encodeParameter->get_Audio_Codec_Name() == "") { - copyAudio = true; - } else { - copyAudio = false; - } - QByteArray ba = src.toLocal8Bit(); - char *sourceFileName = ba.data(); - - QByteArray bb = dst.toLocal8Bit(); - char *destinationFileName = bb.data(); - //emit return_Value_Converter(transcode(sourceFileName, destinationFileName)); - emit return_Value_Converter(transcoder_bmf->transcode(src.toStdString(), dst.toStdString())); -} - -bool Converter::transcode(char *src, char *dst) { - bool flag = true; - int ret = -1; - // deal with arguments - - StreamContext *decoder = new StreamContext; - StreamContext *encoder = new StreamContext; - - av_log_set_level(AV_LOG_DEBUG); - - decoder->filename = src; - encoder->filename = dst; - - transcoder->open_Media(decoder, encoder); - - if (!transcoder->prepare_Decoder(decoder)) { - flag = false; - goto end; - } - - if (!copyVideo) { - if (!transcoder->prepare_Encoder_Video(decoder, encoder)) { - flag = false; - goto end; - } - } else { - transcoder->prepare_Copy(encoder->fmtCtx, &encoder->videoStream, - decoder->videoStream->codecpar); - } - - if (!copyAudio) { - if (!transcoder->prepare_Encoder_Audio(decoder, encoder)) { - flag = false; - goto end; - } - } else { - transcoder->prepare_Copy(encoder->fmtCtx, &encoder->audioStream, - decoder->audioStream->codecpar); - } - - // binding - ret = avio_open2(&encoder->fmtCtx->pb, encoder->filename, AVIO_FLAG_WRITE, - NULL, NULL); - if (ret < 0) { - // av_log(encoder->fmtCtx, AV_LOG_ERROR, "%s", av_err2str(ret)); - flag = false; - goto end; - } - /* Write the stream header, if any. */ - ret = avformat_write_header(encoder->fmtCtx, NULL); - if (ret < 0) { - fprintf(stderr, "Error occurred when opening output file: %s\n", - av_err2str(ret)); - flag = false; - goto end; - } - - // read video data from multimedia files to write into destination file - while (av_read_frame(decoder->fmtCtx, decoder->pkt) >= 0) { - if (decoder->pkt->stream_index == decoder->videoIdx) { - if (!copyVideo) { - transcoder->transcode_Video(decoder, encoder); - } else { - transcoder->remux(decoder->pkt, encoder->fmtCtx, - decoder->videoStream, encoder->videoStream); - } - - // encode(oFmtCtx, outCodecCtx, outFrame, outPkt, inStream, - // outStream); - } else if (decoder->pkt->stream_index == decoder->audioIdx) { - if (!copyAudio) { - - } else { - transcoder->remux(decoder->pkt, encoder->fmtCtx, - decoder->audioStream, encoder->audioStream); - } - } - } - if (!copyVideo) { - encoder->frame = NULL; - // write the buffered frame - transcoder->encode_Video(decoder->videoStream, encoder); - } - - processParameter->set_Process_Number(1, 1); - - av_write_trailer(encoder->fmtCtx); - -// free memory -end: - if (decoder->fmtCtx) { - avformat_close_input(&decoder->fmtCtx); - decoder->fmtCtx = NULL; - } - if (decoder->videoCodecCtx) { - avcodec_free_context(&decoder->videoCodecCtx); - decoder->videoCodecCtx = NULL; - } - if (decoder->frame) { - av_frame_free(&decoder->frame); - decoder->frame = NULL; - } - if (decoder->pkt) { - av_packet_free(&decoder->pkt); - decoder->pkt = NULL; - } - - if (encoder->fmtCtx && !(encoder->fmtCtx->oformat->flags & AVFMT_NOFILE)) { - avio_closep(&encoder->fmtCtx->pb); - } - if (encoder->fmtCtx) { - avformat_free_context(encoder->fmtCtx); - encoder->fmtCtx = NULL; - } - if (encoder->videoCodecCtx) { - avcodec_free_context(&encoder->videoCodecCtx); - encoder->videoCodecCtx = NULL; - } - if (encoder->frame) { - av_frame_free(&encoder->frame); - encoder->frame = NULL; - } - if (encoder->pkt) { - av_packet_free(&encoder->pkt); - encoder->pkt = NULL; - } - return flag; -} - -Converter::~Converter() {} diff --git a/src/converter.h b/src/engine/include/converter.h similarity index 90% rename from src/converter.h rename to src/engine/include/converter.h index 051b5064..3d1c9f94 100644 --- a/src/converter.h +++ b/src/engine/include/converter.h @@ -18,11 +18,9 @@ #ifndef CONVERTER_H #define CONVERTER_H -#endif // CONVERTER_H +#include "../../transcoder/include/transcoder.h" // Include the base class header -#include "transcoder.h" -#include "transcoder_bmf.h" -#include "encode_parameter.h" +#include "../../common/include/encode_parameter.h" #include #include @@ -38,8 +36,6 @@ class Converter : public QObject { private: Transcoder *transcoder = NULL; - TranscoderBMF *transcoder_bmf = NULL; - // encoder's parameters bool copyVideo; bool copyAudio; @@ -57,3 +53,5 @@ class Converter : public QObject { bool transcode(char *src, char *dst); }; + +#endif // CONVERTER_H diff --git a/src/engine/src/converter.cpp b/src/engine/src/converter.cpp new file mode 100644 index 00000000..61b37d36 --- /dev/null +++ b/src/engine/src/converter.cpp @@ -0,0 +1,176 @@ +#include "../include/converter.h" + +#if defined(USE_BMF) + #include "../../transcoder/include/transcoder_bmf.h" +#elif defined(USE_FFMPEG) + #include "../../transcoder/include/transcoder_ffmpeg.h" +#else + #error "No transcoder selected. Please define USE_BMF or USE_FFMPEG." +#endif + +Converter::Converter() {} +/* Receive pointers from widget */ +Converter::Converter(ProcessParameter *processParamter, + EncodeParameter *encodeParamter) + : processParameter(processParamter), encodeParameter(encodeParamter) { + #if defined(USE_BMF) + transcoder = new TranscoderBMF(this->processParameter, this->encodeParameter); + #elif defined(USE_FFMPEG) + transcoder = new TranscoderFFmpeg(this->processParameter, this->encodeParameter); + #endif + + + this->encodeParameter = encodeParamter; +} + +void Converter::convert_Format(QString src, QString dst) { + if (encodeParameter->get_Video_Codec_Name() == "") { + copyVideo = true; + } else { + copyVideo = false; + } + + if (encodeParameter->get_Audio_Codec_Name() == "") { + copyAudio = true; + } else { + copyAudio = false; + } + QByteArray ba = src.toLocal8Bit(); + char *sourceFileName = ba.data(); + + QByteArray bb = dst.toLocal8Bit(); + char *destinationFileName = bb.data(); + //emit return_Value_Converter(transcode(sourceFileName, destinationFileName)); + emit return_Value_Converter(transcoder->transcode(src.toStdString(), dst.toStdString())); +} + +// bool Converter::transcode(char *src, char *dst) { +// bool flag = true; +// int ret = -1; +// // deal with arguments + +// StreamContext *decoder = new StreamContext; +// StreamContext *encoder = new StreamContext; + +// av_log_set_level(AV_LOG_DEBUG); + +// decoder->filename = src; +// encoder->filename = dst; + +// transcoder->open_Media(decoder, encoder); + +// if (!transcoder->prepare_Decoder(decoder)) { +// flag = false; +// goto end; +// } + +// if (!copyVideo) { +// if (!transcoder->prepare_Encoder_Video(decoder, encoder)) { +// flag = false; +// goto end; +// } +// } else { +// transcoder->prepare_Copy(encoder->fmtCtx, &encoder->videoStream, +// decoder->videoStream->codecpar); +// } + +// if (!copyAudio) { +// if (!transcoder->prepare_Encoder_Audio(decoder, encoder)) { +// flag = false; +// goto end; +// } +// } else { +// transcoder->prepare_Copy(encoder->fmtCtx, &encoder->audioStream, +// decoder->audioStream->codecpar); +// } + +// // binding +// ret = avio_open2(&encoder->fmtCtx->pb, encoder->filename, AVIO_FLAG_WRITE, +// NULL, NULL); +// if (ret < 0) { +// // av_log(encoder->fmtCtx, AV_LOG_ERROR, "%s", av_err2str(ret)); +// flag = false; +// goto end; +// } +// /* Write the stream header, if any. */ +// ret = avformat_write_header(encoder->fmtCtx, NULL); +// if (ret < 0) { +// // fprintf(stderr, "Error occurred when opening output file: %s\n", +// // av_err2str(ret)); +// flag = false; +// goto end; +// } + +// // read video data from multimedia files to write into destination file +// while (av_read_frame(decoder->fmtCtx, decoder->pkt) >= 0) { +// if (decoder->pkt->stream_index == decoder->videoIdx) { +// if (!copyVideo) { +// transcoder->transcode_Video(decoder, encoder); +// } else { +// transcoder->remux(decoder->pkt, encoder->fmtCtx, +// decoder->videoStream, encoder->videoStream); +// } + +// // encode(oFmtCtx, outCodecCtx, outFrame, outPkt, inStream, +// // outStream); +// } else if (decoder->pkt->stream_index == decoder->audioIdx) { +// if (!copyAudio) { + +// } else { +// transcoder->remux(decoder->pkt, encoder->fmtCtx, +// decoder->audioStream, encoder->audioStream); +// } +// } +// } +// if (!copyVideo) { +// encoder->frame = NULL; +// // write the buffered frame +// transcoder->encode_Video(decoder->videoStream, encoder); +// } + +// processParameter->set_Process_Number(1, 1); + +// av_write_trailer(encoder->fmtCtx); + +// // free memory +// end: +// if (decoder->fmtCtx) { +// avformat_close_input(&decoder->fmtCtx); +// decoder->fmtCtx = NULL; +// } +// if (decoder->videoCodecCtx) { +// avcodec_free_context(&decoder->videoCodecCtx); +// decoder->videoCodecCtx = NULL; +// } +// if (decoder->frame) { +// av_frame_free(&decoder->frame); +// decoder->frame = NULL; +// } +// if (decoder->pkt) { +// av_packet_free(&decoder->pkt); +// decoder->pkt = NULL; +// } + +// if (encoder->fmtCtx && !(encoder->fmtCtx->oformat->flags & AVFMT_NOFILE)) { +// avio_closep(&encoder->fmtCtx->pb); +// } +// if (encoder->fmtCtx) { +// avformat_free_context(encoder->fmtCtx); +// encoder->fmtCtx = NULL; +// } +// if (encoder->videoCodecCtx) { +// avcodec_free_context(&encoder->videoCodecCtx); +// encoder->videoCodecCtx = NULL; +// } +// if (encoder->frame) { +// av_frame_free(&encoder->frame); +// encoder->frame = NULL; +// } +// if (encoder->pkt) { +// av_packet_free(&encoder->pkt); +// encoder->pkt = NULL; +// } +// return flag; +// } + +Converter::~Converter() {} diff --git a/src/main.cpp b/src/main.cpp index 087887eb..74421c7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "open_converter.h" +#include "builder/include/open_converter.h" #include @@ -9,4 +9,4 @@ int main(int argc, char *argv[]) { w.setWindowTitle("Open Converter"); w.show(); return a.exec(); -} \ No newline at end of file +} diff --git a/src/open_converter.pro b/src/open_converter.pro deleted file mode 100644 index 676f3ff8..00000000 --- a/src/open_converter.pro +++ /dev/null @@ -1,63 +0,0 @@ -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++17 - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -SOURCES += \ - converter.cpp \ - encode_parameter.cpp \ - encode_setting.cpp \ - info.cpp \ - main.cpp \ - open_converter.cpp \ - process_parameter.cpp \ - stream_context.cpp \ - transcoder.cpp \ - transcoder_bmf.cpp - -HEADERS += \ - converter.h \ - encode_parameter.h \ - encode_setting.h \ - info.h \ - open_converter.h \ - process_parameter.h \ - stream_context.h \ - transcoder.h \ - transcoder_bmf.h - -FORMS += \ - encode_setting.ui \ - open_converter.ui - - -BMF_ROOT_PATH=/Users/jacklau/Documents/Programs/Git/Github/bmf - -LIBS += -L/usr/local/lib -L/opt/homebrew/Cellar/x264/r3108/lib -L/opt/homebrew/Cellar/x265/4.0_1/lib -L/usr/local/lib -L/opt/homebrew/Cellar/libx11/1.8.9/lib -lavformat -lavcodec -lavutil -lm -lbz2 -lz -Wl,-framework,CoreFoundation -Wl,-framework,Security -lavcodec -liconv -lm -framework AudioToolbox -lx264 -lx265 -pthread -lz -framework VideoToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices -lswresample -lm -lavutil -pthread -lm -framework VideoToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices - -LIBS += -L/Users/jacklau/Documents/Programs/Git/Github/bmf/output/bmf/lib -lengine -lbmf_module_sdk -lhmp -lbuiltin_modules - -INCLUDEPATH += /usr/local/include - -INCLUDEPATH += /opt/homebrew/Cellar/x264/r3108/include - -INCLUDEPATH += /opt/homebrew/Cellar/x265/4.0_1/include - -INCLUDEPATH += /Users/jacklau/Documents/Programs/Git/Github/bmf/output/bmf/include - -TRANSLATIONS += lang_chinese.ts - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - -DISTFILES += - -RESOURCES += \ - lang.qrc diff --git a/src/lang.qrc b/src/resources/lang.qrc similarity index 100% rename from src/lang.qrc rename to src/resources/lang.qrc diff --git a/src/lang_chinese.qm b/src/resources/lang_chinese.qm similarity index 100% rename from src/lang_chinese.qm rename to src/resources/lang_chinese.qm diff --git a/src/lang_chinese.ts b/src/resources/lang_chinese.ts similarity index 100% rename from src/lang_chinese.ts rename to src/resources/lang_chinese.ts diff --git a/src/transcoder/LICENSE b/src/transcoder/LICENSE new file mode 100644 index 00000000..f166cc57 --- /dev/null +++ b/src/transcoder/LICENSE @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! \ No newline at end of file diff --git a/src/transcoder/include/transcoder.h b/src/transcoder/include/transcoder.h new file mode 100644 index 00000000..18574aff --- /dev/null +++ b/src/transcoder/include/transcoder.h @@ -0,0 +1,37 @@ +/* + * Copyright 2024 Jack Lau + * Email: jacklau1222gm@gmail.com + * + * This file is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + */ + +#ifndef TRANSCODER_H +#define TRANSCODER_H + +#include "../../common/include/process_parameter.h" +#include "../../common/include/encode_parameter.h" +#include "../../common/include/stream_context.h" + +class Transcoder { +public: + Transcoder(ProcessParameter *processParameter, EncodeParameter *encodeParameter) + : processParameter(processParameter), encodeParameter(encodeParameter) {} + + virtual ~Transcoder() = default; + + virtual bool transcode(std::string input_path, std::string output_path) = 0; + + ProcessParameter *processParameter = NULL; + + EncodeParameter *encodeParameter = NULL; +}; + +#endif \ No newline at end of file diff --git a/src/transcoder_bmf.h b/src/transcoder/include/transcoder_bmf.h similarity index 90% rename from src/transcoder_bmf.h rename to src/transcoder/include/transcoder_bmf.h index 3db1e2c5..34e62b4d 100644 --- a/src/transcoder_bmf.h +++ b/src/transcoder/include/transcoder_bmf.h @@ -16,16 +16,14 @@ #ifndef TRANSCODER_BMF_H #define TRANSCODER_BMF_H -#include "process_parameter.h" -#include "encode_parameter.h" -#include "stream_context.h" +#include "transcoder.h" #include "builder.hpp" #include "nlohmann/json.hpp" #include -class TranscoderBMF { +class TranscoderBMF : public Transcoder { public: TranscoderBMF(ProcessParameter *processParameter, EncodeParameter *encodeParamter); @@ -41,9 +39,6 @@ class TranscoderBMF { bmf_sdk::CBytes encoder_callback(bmf_sdk::CBytes input); private: - ProcessParameter *processParameter = NULL; - - EncodeParameter *encodeParameter = NULL; static int frameNumber; diff --git a/src/transcoder.h b/src/transcoder/include/transcoder_ffmpeg.h similarity index 78% rename from src/transcoder.h rename to src/transcoder/include/transcoder_ffmpeg.h index a39b4d03..ebf11350 100644 --- a/src/transcoder.h +++ b/src/transcoder/include/transcoder_ffmpeg.h @@ -13,8 +13,10 @@ * Lesser General Public License for more details. */ -#ifndef TRANSCODER_H -#define TRANSCODER_H +#ifndef TRANSCODERFFMPEG_H +#define TRANSCODERFFMPEG_H + +#include "transcoder.h" extern "C" { #include @@ -22,18 +24,16 @@ extern "C" { #include }; -#include "process_parameter.h" -#include "encode_parameter.h" -#include "stream_context.h" #define ENCODE_BIT_RATE 5000000 -class Transcoder { +class TranscoderFFmpeg : public Transcoder { public: - Transcoder(); - Transcoder(ProcessParameter *processParameter, - EncodeParameter *encodeParamter); - ~Transcoder(); + TranscoderFFmpeg(ProcessParameter *processParameter, + EncodeParameter *encodeParameter); + ~TranscoderFFmpeg(); + + bool transcode(std::string input_path, std::string output_path); bool open_Media(StreamContext *decoder, StreamContext *encoder); @@ -56,13 +56,13 @@ class Transcoder { AVStream *outStream); private: - ProcessParameter *processParameter = NULL; - - EncodeParameter *encodeParamter = NULL; + // encoder's parameters + bool copyVideo; + bool copyAudio; static int frameNumber; int64_t frameTotalNumber; }; -#endif // TRANSCODER_H +#endif // TRANSCODERFFMPEG_H diff --git a/src/transcoder_bmf.cpp b/src/transcoder/src/transcoder_bmf.cpp similarity index 98% rename from src/transcoder_bmf.cpp rename to src/transcoder/src/transcoder_bmf.cpp index 74c31a73..27b658eb 100644 --- a/src/transcoder_bmf.cpp +++ b/src/transcoder/src/transcoder_bmf.cpp @@ -1,9 +1,9 @@ -#include "transcoder_bmf.h" +#include "../include/transcoder_bmf.h" /* Receive pointers from converter */ TranscoderBMF::TranscoderBMF(ProcessParameter *processParameter, EncodeParameter *encodeParameter) - : processParameter(processParameter), encodeParameter(encodeParameter) { + : Transcoder(processParameter, encodeParameter) { frameTotalNumber = 0; } @@ -152,7 +152,7 @@ bool TranscoderBMF::prepare_info(std::string input_path, std::string output_path } } }; - + return true; } bool TranscoderBMF::transcode(std::string input_path, std::string output_path) { diff --git a/src/transcoder.cpp b/src/transcoder/src/transcoder_ffmpeg.cpp similarity index 69% rename from src/transcoder.cpp rename to src/transcoder/src/transcoder_ffmpeg.cpp index 32257c81..89b42252 100644 --- a/src/transcoder.cpp +++ b/src/transcoder/src/transcoder_ffmpeg.cpp @@ -1,17 +1,144 @@ -#include "transcoder.h" +#include "../include/transcoder_ffmpeg.h" -Transcoder::Transcoder() {} - -int Transcoder::frameNumber = 0; +int TranscoderFFmpeg::frameNumber = 0; /* Receive pointers from converter */ -Transcoder::Transcoder(ProcessParameter *processParameter, - EncodeParameter *encodeParamter) - : processParameter(processParameter), encodeParamter(encodeParamter) { +TranscoderFFmpeg::TranscoderFFmpeg(ProcessParameter *processParameter, + EncodeParameter *encodeParameter) + : Transcoder(processParameter, encodeParameter) { frameTotalNumber = 0; } -bool Transcoder::open_Media(StreamContext *decoder, StreamContext *encoder) { +bool TranscoderFFmpeg::transcode(std::string input_path, std::string output_path) { + bool flag = true; + int ret = -1; + // deal with arguments + + StreamContext *decoder = new StreamContext; + StreamContext *encoder = new StreamContext; + + av_log_set_level(AV_LOG_DEBUG); + + decoder->filename = input_path.c_str(); + encoder->filename = output_path.c_str(); + + open_Media(decoder, encoder); + + if (!prepare_Decoder(decoder)) { + flag = false; + goto end; + } + + if (!copyVideo) { + if (!prepare_Encoder_Video(decoder, encoder)) { + flag = false; + goto end; + } + } else { + prepare_Copy(encoder->fmtCtx, &encoder->videoStream, + decoder->videoStream->codecpar); + } + + if (!copyAudio) { + if (!prepare_Encoder_Audio(decoder, encoder)) { + flag = false; + goto end; + } + } else { + prepare_Copy(encoder->fmtCtx, &encoder->audioStream, + decoder->audioStream->codecpar); + } + + // binding + ret = avio_open2(&encoder->fmtCtx->pb, encoder->filename, AVIO_FLAG_WRITE, + NULL, NULL); + if (ret < 0) { + // av_log(encoder->fmtCtx, AV_LOG_ERROR, "%s", av_err2str(ret)); + flag = false; + goto end; + } + /* Write the stream header, if any. */ + ret = avformat_write_header(encoder->fmtCtx, NULL); + if (ret < 0) { +// fprintf(stderr, "Error occurred when opening output file: %s\n", +// av_err2str(ret)); + flag = false; + goto end; + } + + // read video data from multimedia files to write into destination file + while (av_read_frame(decoder->fmtCtx, decoder->pkt) >= 0) { + if (decoder->pkt->stream_index == decoder->videoIdx) { + if (!copyVideo) { + transcode_Video(decoder, encoder); + } else { + remux(decoder->pkt, encoder->fmtCtx, + decoder->videoStream, encoder->videoStream); + } + + // encode(oFmtCtx, outCodecCtx, outFrame, outPkt, inStream, + // outStream); + } else if (decoder->pkt->stream_index == decoder->audioIdx) { + if (!copyAudio) { + + } else { + remux(decoder->pkt, encoder->fmtCtx, + decoder->audioStream, encoder->audioStream); + } + } + } + if (!copyVideo) { + encoder->frame = NULL; + // write the buffered frame + encode_Video(decoder->videoStream, encoder); + } + + processParameter->set_Process_Number(1, 1); + + av_write_trailer(encoder->fmtCtx); + +// free memory +end: + if (decoder->fmtCtx) { + avformat_close_input(&decoder->fmtCtx); + decoder->fmtCtx = NULL; + } + if (decoder->videoCodecCtx) { + avcodec_free_context(&decoder->videoCodecCtx); + decoder->videoCodecCtx = NULL; + } + if (decoder->frame) { + av_frame_free(&decoder->frame); + decoder->frame = NULL; + } + if (decoder->pkt) { + av_packet_free(&decoder->pkt); + decoder->pkt = NULL; + } + + if (encoder->fmtCtx && !(encoder->fmtCtx->oformat->flags & AVFMT_NOFILE)) { + avio_closep(&encoder->fmtCtx->pb); + } + if (encoder->fmtCtx) { + avformat_free_context(encoder->fmtCtx); + encoder->fmtCtx = NULL; + } + if (encoder->videoCodecCtx) { + avcodec_free_context(&encoder->videoCodecCtx); + encoder->videoCodecCtx = NULL; + } + if (encoder->frame) { + av_frame_free(&encoder->frame); + encoder->frame = NULL; + } + if (encoder->pkt) { + av_packet_free(&encoder->pkt); + encoder->pkt = NULL; + } + return flag; +} + +bool TranscoderFFmpeg::open_Media(StreamContext *decoder, StreamContext *encoder) { int ret = -1; /* set the frameNumber to zero to avoid some bugs */ frameNumber = 0; @@ -32,7 +159,7 @@ bool Transcoder::open_Media(StreamContext *decoder, StreamContext *encoder) { return true; } -bool Transcoder::copyFrame(AVFrame *oldFrame, AVFrame *newFrame) { +bool TranscoderFFmpeg::copyFrame(AVFrame *oldFrame, AVFrame *newFrame) { int response; newFrame->pts = oldFrame->pts; newFrame->format = oldFrame->format; @@ -57,7 +184,7 @@ bool Transcoder::copyFrame(AVFrame *oldFrame, AVFrame *newFrame) { return true; } -bool Transcoder::encode_Video(AVStream *inStream, StreamContext *encoder) { +bool TranscoderFFmpeg::encode_Video(AVStream *inStream, StreamContext *encoder) { int ret = -1; // send frame to encoder @@ -107,7 +234,7 @@ bool Transcoder::encode_Video(AVStream *inStream, StreamContext *encoder) { return true; } -bool Transcoder::transcode_Video(StreamContext *decoder, +bool TranscoderFFmpeg::transcode_Video(StreamContext *decoder, StreamContext *encoder) { int ret = -1; @@ -142,7 +269,7 @@ bool Transcoder::transcode_Video(StreamContext *decoder, return 0; } -bool Transcoder::prepare_Decoder(StreamContext *decoder) { +bool TranscoderFFmpeg::prepare_Decoder(StreamContext *decoder) { int ret = -1; for (int i = 0; i < decoder->fmtCtx->nb_streams; i++) { @@ -221,7 +348,7 @@ bool Transcoder::prepare_Decoder(StreamContext *decoder) { return true; } -bool Transcoder::prepare_Encoder_Video(StreamContext *decoder, +bool TranscoderFFmpeg::prepare_Encoder_Video(StreamContext *decoder, StreamContext *encoder) { int ret = -1; @@ -232,8 +359,8 @@ bool Transcoder::prepare_Encoder_Video(StreamContext *decoder, */ // find the encodec by Name // QByteArray ba = encodeParamter->get_Video_Codec_Name().toLocal8Bit(); - const char *codec = encodeParamter->get_Video_Codec_Name().c_str(); - encoder->videoCodec = avcodec_find_encoder_by_name(codec); + std::string codec = encodeParameter->get_Video_Codec_Name(); + encoder->videoCodec = avcodec_find_encoder_by_name(codec.c_str()); // find the encodec by ID // encoder->videoCodec = @@ -328,20 +455,20 @@ bool Transcoder::prepare_Encoder_Video(StreamContext *decoder, return true; } -bool Transcoder::prepare_Encoder_Audio(StreamContext *decoder, +bool TranscoderFFmpeg::prepare_Encoder_Audio(StreamContext *decoder, StreamContext *encoder) { // TODO return true; } -bool Transcoder::prepare_Copy(AVFormatContext *avCtx, AVStream **stream, +bool TranscoderFFmpeg::prepare_Copy(AVFormatContext *avCtx, AVStream **stream, AVCodecParameters *codecParam) { *stream = avformat_new_stream(avCtx, NULL); avcodec_parameters_copy((*stream)->codecpar, codecParam); return true; } -bool Transcoder::remux(AVPacket *pkt, AVFormatContext *avCtx, +bool TranscoderFFmpeg::remux(AVPacket *pkt, AVFormatContext *avCtx, AVStream *inStream, AVStream *outStream) { av_packet_rescale_ts(pkt, inStream->time_base, outStream->time_base); if (av_interleaved_write_frame(avCtx, pkt) < 0) { @@ -351,4 +478,4 @@ bool Transcoder::remux(AVPacket *pkt, AVFormatContext *avCtx, return true; } -Transcoder::~Transcoder() {} +TranscoderFFmpeg::~TranscoderFFmpeg() {} diff --git a/src/version.log b/src/version.log index 809ec54a..a1225029 100644 --- a/src/version.log +++ b/src/version.log @@ -1,7 +1,8 @@ -OpenConverter Version 1.2 +OpenConverter Version 1.3 key changes: -* fix bug +* implement audio transcode +* implement time required auto-update +* optimize the project file structure * optimize code -* add multi-language support -* add LGPL LICENSE \ No newline at end of file +* move LGPL LICENSE to proper place \ No newline at end of file