Skip to content

linux version #26

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,14 @@ This will build a .lib file that you can use in your own C++ projects. It will a

## Linux

Currently, only a Windows environment with Visual Studio is supported. This is simply because I do not have experience with cmake and Linux-projects, since the project itself is fully platform-independent. If anyone is willing to help me out with configuring cmake, please get in touch!
install ffmpeg lib either from your distro or from ffmpeg.org (adapt CMakeList.txt if needed)
ffmpeg-cpp/source/ffmpeg-cpp
cmake -DCMAKE_BUILD_TYPE=Release .
make

to have an eclispe project
cmake -G "Eclipse CDT4 - Unix Makefiles" .
eclipse File/import/existing code from makefile project

# Usage

301 changes: 301 additions & 0 deletions source/ffmpeg-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
cmake_minimum_required(VERSION 3.1)
#
#build using cmake -DCMAKE_BUILD_TYPE=Release .
#
project(ffmpeg-cpp- CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-D__STDC_CONSTANT_MACROS")
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so;.a")

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(ZLIB REQUIRED)

#if you use ffmepg built from source (configure/make), put here the ffmpeg path
set (FFMPEG_PATH "../../ffmpeg")

# if you have the package installed on a debian based distro
# should be something like /usr/include/x86_64-linux-gnu/libavcodec/avcodec.h
#
# therefore you should have
#
# find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h /usr/include/x86_64-linux-gnu )
# find_library(AVCODEC_LIBRARY avcodec /usr/lib/x86_64-linux-gnu )

find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h $FFMPEG_PATH )
find_library(AVCODEC_LIBRARY avcodec $FFMPEG_PATH/libavcodec )

message("AVCODEC_INCLUDE_DIR: ${AVCODEC_INCLUDE_DIR}")
message("AVCODEC_LIBRARY: ${AVCODEC_LIBRARY}")

find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h $FFMPEG_PATH )
find_library(AVFORMAT_LIBRARY avformat $FFMPEG_PATH/libavformat )

find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h $FFMPEG_PATH )
find_library(AVUTIL_LIBRARY avutil $FFMPEG_PATH/libavutil )

find_path(AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h $FFMPEG_PATH )
find_library(AVDEVICE_LIBRARY avdevice $FFMPEG_PATH/libavdevice )

find_path(SWSCALE_INCLUDE_DIR libswscale/swscale.h $FFMPEG_PATH )
find_library(SWSCALE_LIBRARY swscale $FFMPEG_PATH/libswscale )

find_path(RESAMPLE_INCLUDE_DIR libavresample/avresample.h $FFMPEG_PATH )
find_library(RESAMPLE_LIBRARY swresample $FFMPEG_PATH/libswresample )

find_path(AVFILTER_INCLUDE_DIR libavfilter/avfilter.h $FFMPEG_PATH )
find_library(AVFILTER_LIBRARY avfilter $FFMPEG_PATH/libavfilter )
message("AVFILTER_INCLUDE_DIR: ${AVFILTER_INCLUDE_DIR}")
message("AVFILTER_LIBRARY: ${AVFILTER_LIBRARY}")

add_subdirectory(ffmpeg-cpp)

add_executable(${PROJECT_NAME}decode_audio)
target_include_directories(${PROJECT_NAME}decode_audio
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}decode_audio
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}decode_audio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/decode_audio/decode_audio.cpp
)

######################################################################################"
add_executable(${PROJECT_NAME}decode_video)
target_include_directories(${PROJECT_NAME}decode_video
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}decode_video
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}decode_video
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/decode_video/decode_video.cpp
)

######################################################################################"
add_executable(${PROJECT_NAME}demo)
target_include_directories(${PROJECT_NAME}demo
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}demo
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
${AVFILTER_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}demo
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/demo/demo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/demo/GeneratedAudioSource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/demo/GeneratedAudioSource.h
${CMAKE_CURRENT_SOURCE_DIR}/demo/GeneratedVideoSource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/demo/GeneratedVideoSource.h
)

######################################################################################"
add_executable(${PROJECT_NAME}difference)
target_include_directories(${PROJECT_NAME}difference
PRIVATE
${AVCODEC_INCLUDE_DIR}
)
target_link_libraries(${PROJECT_NAME}difference
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
${AVFILTER_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}difference
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/difference/difference.cpp
)

######################################################################################"
add_executable(${PROJECT_NAME}encode_audio)

target_include_directories(${PROJECT_NAME}encode_audio
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}encode_audio
PRIVATE
ffmpegCppLib
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}encode_audio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/encode_audio/encode_audio.cpp
)

######################################################################################"
add_executable(${PROJECT_NAME}encode_video)
target_include_directories(${PROJECT_NAME}encode_video
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}encode_video
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}encode_video
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/encode_video/encode_video.cpp
)

######################################################################################"
add_executable(${PROJECT_NAME}filtering_audio)
target_include_directories(${PROJECT_NAME}filtering_audio
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}filtering_audio
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
${AVFILTER_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}filtering_audio
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/filtering_audio/filtering_audio.cpp
)

######################################################################################"
add_executable(${PROJECT_NAME}filtering_video)
target_include_directories(${PROJECT_NAME}filtering_video
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}filtering_video
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
${AVFILTER_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}filtering_video
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/filtering_video/filtering_video.cpp
)

###########################################################################################
add_executable(${PROJECT_NAME}print_info)
target_include_directories(${PROJECT_NAME}print_info
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}print_info
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}print_info
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/print_info/print_info.cpp
)

######################################################################################"
add_executable(${PROJECT_NAME}remuxing)
target_include_directories(${PROJECT_NAME}remuxing
PRIVATE
${AVCODEC_INCLUDE_DIR}
)

target_link_libraries(${PROJECT_NAME}remuxing
PRIVATE
# warning the order of libs matters !
Threads::Threads
ffmpegCppLib
${AVFORMAT_LIBRARY}
${AVCODEC_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
ZLIB::ZLIB
)

target_sources(${PROJECT_NAME}remuxing
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/remuxing/remuxing.cpp
)

116 changes: 116 additions & 0 deletions source/ffmpeg-cpp/ffmpeg-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
cmake_minimum_required(VERSION 3.1)

project(ffmpegCppLib)

add_library(${PROJECT_NAME})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

target_sources(${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/AudioFormatConverter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/FFmpegException.cpp
${CMAKE_CURRENT_SOURCE_DIR}/OpenCodec.h
${CMAKE_CURRENT_SOURCE_DIR}/AudioFormatConverter.h
${CMAKE_CURRENT_SOURCE_DIR}/FFmpegException.h
${CMAKE_CURRENT_SOURCE_DIR}/std.h
${CMAKE_CURRENT_SOURCE_DIR}/CodecDeducer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ffmpeg.h
${CMAKE_CURRENT_SOURCE_DIR}/VideoFormatConverter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/CodecDeducer.h
${CMAKE_CURRENT_SOURCE_DIR}/FrameContainer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/VideoFormatConverter.h
${CMAKE_CURRENT_SOURCE_DIR}/ConvertedAudioProcessor.h
${CMAKE_CURRENT_SOURCE_DIR}/FrameContainer.h
${CMAKE_CURRENT_SOURCE_DIR}/ffmpegcpp.h
${CMAKE_CURRENT_SOURCE_DIR}/OpenCodec.cpp

${CMAKE_CURRENT_SOURCE_DIR}/Codecs/AudioCodec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/Codec.h
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/PNGCodec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/VideoCodec.h
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/AudioCodec.h
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/JPGCodec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/PNGCodec.h
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/VP9Codec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/Codec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/JPGCodec.h
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/VideoCodec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Codecs/VP9Codec.h

${CMAKE_CURRENT_SOURCE_DIR}/codecs/H264NVEncCodec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/codecs/H264NVEncCodec.h
${CMAKE_CURRENT_SOURCE_DIR}/codecs/H265NVEncCodec.cpp
${CMAKE_CURRENT_SOURCE_DIR}/codecs/H265NVEncCodec.h

${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/AudioInputStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/InputStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/StreamData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/VideoInputStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/AudioInputStream.h
${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/InputStream.h
${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/StreamData.h
${CMAKE_CURRENT_SOURCE_DIR}/Demuxing/VideoInputStream.h

${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/AudioEncoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/Filter.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/OneInputFrameSink.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/AudioEncoder.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/FrameSink.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/VideoEncoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/AudioFilter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/FrameSinkStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/VideoEncoder.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/AudioFilter.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/FrameSinkStream.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/VideoFilterInput.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/AudioFrameSink.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/FrameWriter.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/VideoFilterInput.h
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/Filter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/OneInputFrameSink.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Frame\ Sinks/VideoFrameSink.h

${CMAKE_CURRENT_SOURCE_DIR}/Info/AudioStreamInfo.h
${CMAKE_CURRENT_SOURCE_DIR}/Info/ContainerInfo.h
${CMAKE_CURRENT_SOURCE_DIR}/Info/VideoStreamInfo.h

${CMAKE_CURRENT_SOURCE_DIR}/Muxing/AudioOutputStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Muxing/Muxer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Muxing/OutputStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Muxing/VideoOutputStream.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Muxing/AudioOutputStream.h
${CMAKE_CURRENT_SOURCE_DIR}/Muxing/Muxer.h
${CMAKE_CURRENT_SOURCE_DIR}/Muxing/OutputStream.h
${CMAKE_CURRENT_SOURCE_DIR}/Muxing/VideoOutputStream.h

${CMAKE_CURRENT_SOURCE_DIR}/Sources/Demuxer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawAudioDataSource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawVideoDataSource.h
${CMAKE_CURRENT_SOURCE_DIR}/Sources/Demuxer.h
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawAudioDataSource.h
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawVideoFileSource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Sources/EncodedFileSource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawAudioFileSource.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawVideoFileSource.h
${CMAKE_CURRENT_SOURCE_DIR}/Sources/EncodedFileSource.h
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawAudioFileSource.h
${CMAKE_CURRENT_SOURCE_DIR}/Sources/InputSource.h
${CMAKE_CURRENT_SOURCE_DIR}/Sources/RawVideoDataSource.cpp

)

target_include_directories(${PROJECT_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/Codecs
)

target_link_libraries(${PROJECT_NAME}
PRIVATE
${AVCODEC_LIBRARY}
${AVFORMAT_LIBRARY}
${AVUTIL_LIBRARY}
${AVDEVICE_LIBRARY}
${RESAMPLE_LIBRARY}
${SWSCALE_LIBRARY}
)
12 changes: 6 additions & 6 deletions source/ffmpeg-cpp/ffmpeg-cpp/FFmpegException.cpp
Original file line number Diff line number Diff line change
@@ -4,14 +4,14 @@ using namespace std;

namespace ffmpegcpp
{
FFmpegException::FFmpegException(string error) : exception(error.c_str())
FFmpegException::FFmpegException(const string &error) : exception(),errorMsg(error)
{
}

FFmpegException::FFmpegException(string error, int returnValue)
: exception(
(error + ": " + av_make_error_string(this->error, AV_ERROR_MAX_STRING_SIZE, returnValue)).c_str()
)
FFmpegException::FFmpegException(const string &errorStr, int returnValue)
:exception()
{
char error[AV_ERROR_MAX_STRING_SIZE];
errorMsg=errorStr + ": " + av_make_error_string(error, AV_ERROR_MAX_STRING_SIZE, returnValue);
}
}
}
12 changes: 6 additions & 6 deletions source/ffmpeg-cpp/ffmpeg-cpp/FFmpegException.h
Original file line number Diff line number Diff line change
@@ -11,18 +11,18 @@ namespace ffmpegcpp

public:

FFmpegException(std::string error);
FFmpegException(const std::string &error);

FFmpegException(std::string error, int returnValue);
FFmpegException(const std::string &error, int returnValue);

virtual char const* what() const
char const* what() const noexcept override
{
return std::exception::what();
return errorMsg.c_str();
}


private:

char error[AV_ERROR_MAX_STRING_SIZE];
std::string errorMsg;
};
}
}
2 changes: 0 additions & 2 deletions source/ffmpeg-cpp/ffmpeg-cpp/OpenCodec.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

#include "OpenCodec.h"
#include "FFmpegException.h"

8 changes: 6 additions & 2 deletions source/ffmpeg-cpp/ffmpeg-cpp/ffmpeg.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,11 @@

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#ifdef _MSC_VER
#include <crtdbg.h>
//MS specific
#endif

extern "C" {
#include <libavcodec/avcodec.h>
@@ -16,4 +20,4 @@ extern "C" {
#include <libavfilter/buffersrc.h>
#include <libswresample/swresample.h>
#include <libavutil/audio_fifo.h>
}
}
4 changes: 2 additions & 2 deletions source/ffmpeg-cpp/ffmpeg-cpp/ffmpegcpp.h
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@

#include "Codecs/AudioCodec.h"

#include "Codecs/H265NVEncCodec.h"
#include "Codecs/H264NVEncCodec.h"
#include "codecs/H265NVEncCodec.h"
#include "codecs/H264NVEncCodec.h"
#include "Codecs/VP9Codec.h"
#include "Codecs/PNGCodec.h"
#include "Codecs/JPGCodec.h"