Skip to content
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

Bugfix #3

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5b94e48
moved library files to the common directory structure
wvaarle Dec 14, 2018
3c94fde
moved example files to the common directory structure
wvaarle Dec 14, 2018
465a076
removed all visual studio project files
wvaarle Dec 14, 2018
de143d4
update gitignore file
wvaarle Dec 14, 2018
d76cc3e
Fixed include paths
wvaarle Dec 14, 2018
add307f
added cmake files
wvaarle Dec 17, 2018
0534884
use nullptr instead of NULL or 0 (clang-tidy: modernize-use-nullptr)
wvaarle Dec 17, 2018
498ad8f
use the override keyword on overridden functions (clang-tidy: moderni…
wvaarle Dec 17, 2018
25fc7da
replaced std::endl with '\n'
wvaarle Dec 17, 2018
145c709
examples: use smart pointers instead of raw pointers
wvaarle Dec 17, 2018
5d5b477
examples: removed using namespace std
wvaarle Dec 17, 2018
785c64d
examples: removed using namespace ffmpegcpp
wvaarle Dec 17, 2018
dace788
smart pointerify all uses of AVCodecContext*
wvaarle Dec 18, 2018
01872f6
smart pointerify all uses of AVPacket*
wvaarle Dec 18, 2018
165c80e
smart pointerify all uses of AVFrame*
wvaarle Dec 18, 2018
0edf8db
smart pointerify all uses of AVFilterGraph*
wvaarle Dec 18, 2018
09288a8
smart pointerify all uses of AVAudioFifo*
wvaarle Dec 18, 2018
203808a
smart pointerify all uses of SwsContext*
wvaarle Dec 18, 2018
edc7549
smart pointerify all uses of SwrContext*
wvaarle Dec 18, 2018
1117ca4
smart pointerify all uses of AVCodecParserContext*
wvaarle Dec 18, 2018
09172b8
smart pointerify all uses of AVFormatContext*
wvaarle Dec 18, 2018
efed9f8
removed more cleanup() functions by managing member variables with sm…
wvaarle Dec 18, 2018
cee50cc
use smart pointer for OpenCodec
wvaarle Dec 19, 2018
d5b3e56
forward declare as much as possible
wvaarle Dec 19, 2018
5b5bd80
replaced InputStream** with vector<unique_ptr>
wvaarle Dec 19, 2018
0659b07
replaced for loops with algorithms where possible
wvaarle Dec 19, 2018
9520784
added const specifier to const member functions
wvaarle Dec 19, 2018
c070af8
removed std.h
wvaarle Dec 20, 2018
d49c1c7
removed some compile warnings
wvaarle Dec 20, 2018
9b0be3c
replaced char * with std::strings
wvaarle Dec 20, 2018
814276e
code cleanup
wvaarle Dec 21, 2018
87b1be7
fixed compile time issues
wvaarle Dec 21, 2018
974b36c
fixed crashes
wvaarle Dec 21, 2018
bce29c8
don't free resources when not owner
wvaarle Dec 21, 2018
a2cc28f
fixed memory issue
wvaarle Dec 23, 2018
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
23 changes: 3 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/source/ffmpeg-cpp/.vs/ffmpeg-cpp/v15
/source/ffmpeg-cpp/ffmpeg-cpp/obj
/source/ffmpeg-cpp/demo/obj
/source/ffmpeg-cpp/x64/Debug
/source/ffmpeg-cpp/obj/Debug
/source/ffmpeg-cpp/demo/samples/out.mp4
/ffmpeg/include
/ffmpeg/include
/ffmpeg/lib
/ffmpeg/bin
/bin
/lib

/source/ffmpeg-cpp/decode_audio/obj
/source/ffmpeg-cpp/encode_audio/obj
/source/ffmpeg-cpp/encode_video/obj
/source/ffmpeg-cpp/decode_video/obj
/source/ffmpeg-cpp/filtering_video/obj
/include

/source/ffmpeg-cpp/remuxing/obj
/.vs
/.vscode
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.5)

project(ffmpegcpp VERSION 1.0.0)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

file(GLOB_RECURSE ffmpegcpp_files "include/ffmpegcpp/*.h" "src/*.cpp")
file(GLOB_RECURSE header_files "include/ffmpegcpp/*.h")

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${ffmpegcpp_files})

add_library(ffmpegcpp STATIC ${ffmpegcpp_files})

set_target_properties(ffmpegcpp PROPERTIES
VERSION ${PROJECT_VERSION}
PUBLIC_HEADER ${header_files}
CXX_STANDARD 17
)

set_target_properties(ffmpegcpp PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)

target_include_directories(ffmpegcpp PRIVATE
include/ffmpegcpp
ffmpeg/include
)

target_link_libraries(ffmpegcpp
${PROJECT_SOURCE_DIR}/ffmpeg/lib/avcodec.lib
${PROJECT_SOURCE_DIR}/ffmpeg/lib/avdevice.lib
${PROJECT_SOURCE_DIR}/ffmpeg/lib/avfilter.lib
${PROJECT_SOURCE_DIR}/ffmpeg/lib/avformat.lib
${PROJECT_SOURCE_DIR}/ffmpeg/lib/avutil.lib
${PROJECT_SOURCE_DIR}/ffmpeg/lib/postproc.lib
${PROJECT_SOURCE_DIR}/ffmpeg/lib/swresample.lib
${PROJECT_SOURCE_DIR}/ffmpeg/lib/swscale.lib
)

install(TARGETS ffmpegcpp
ARCHIVE DESTINATION ${CMAKE_BINARY_DIR}/lib
LIBRARY DESTINATION ${CMAKE_BINARY_DIR}/lib
PUBLIC_HEADER DESTINATION ${CMAKE_BINARY_DIR}/lib/include
)

install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/ffmpeg/bin/ DESTINATION ${CMAKE_BINARY_DIR}/bin/Release FILES_MATCHING PATTERN "*.dll")
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/samples/ DESTINATION ${CMAKE_BINARY_DIR}/bin/Release/samples)

add_subdirectory(examples)
7 changes: 7 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_subdirectory(decode_audio)
add_subdirectory(decode_video)
add_subdirectory(demo)
add_subdirectory(encode_audio)
add_subdirectory(encode_video)
add_subdirectory(filtering_video)
add_subdirectory(remuxing)
17 changes: 17 additions & 0 deletions examples/decode_audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

add_executable(decode_audio
decode_audio.cpp
)

set_target_properties(decode_audio PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

target_include_directories(decode_audio PUBLIC
${PROJECT_SOURCE_DIR}/include/ffmpegcpp
${PROJECT_SOURCE_DIR}/ffmpeg/include
)

target_link_libraries(decode_audio ffmpegcpp)

set_target_properties(decode_audio PROPERTIES FOLDER examples)
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@

#include <iostream>
#include <memory>

#include "ffmpegcpp.h"

using namespace std;
using namespace ffmpegcpp;

class RawAudioFileSink : public AudioFrameSink
class RawAudioFileSink : public ffmpegcpp::AudioFrameSink
{
public:

RawAudioFileSink(const char* fileName)
RawAudioFileSink(const std::string & fileName)
{
file = fopen(fileName, "wb");
file = fopen(fileName.c_str(), "wb");
}

virtual void WriteFrame(AVFrame* frame, AVRational* timeBase)
void WriteFrame(AVFrame* frame, AVRational* timeBase) override
{
// Just write out the samples channel by channel to a file.
int data_size = av_get_bytes_per_sample((AVSampleFormat)frame->format);
Expand All @@ -28,12 +26,12 @@ class RawAudioFileSink : public AudioFrameSink
}
}

virtual void Close()
void Close() override
{
fclose(file);
}

virtual bool IsPrimed()
bool IsPrimed() const override
{
// Return whether we have all information we need to start writing out data.
// Since we don't really need any data in this use case, we are always ready.
Expand All @@ -52,36 +50,33 @@ int main()
try
{
// Load this container file so we can extract audio from it.
Demuxer* demuxer = new Demuxer("samples/big_buck_bunny.mp4");
ffmpegcpp::Demuxer demuxer("samples/big_buck_bunny.mp4");

// Create a file sink that will just output the raw audio data.
RawAudioFileSink* fileSink = new RawAudioFileSink("rawaudio");
auto fileSink = std::make_unique<RawAudioFileSink>("rawaudio");

// tie the file sink to the best audio stream in the input container.
demuxer->DecodeBestAudioStream(fileSink);
demuxer.DecodeBestAudioStream(fileSink.get());

// Prepare the output pipeline. This will push a small amount of frames to the file sink until it IsPrimed returns true.
demuxer->PreparePipeline();
demuxer.PreparePipeline();

// Push all the remaining frames through.
while (!demuxer->IsDone())
while (!demuxer.IsDone())
{
demuxer->Step();
demuxer.Step();
}

// done
delete demuxer;
delete fileSink;
}
catch (FFmpegException e)
catch (ffmpegcpp::FFmpegException e)
{
cerr << "Exception caught!" << endl;
cerr << e.what() << endl;
std::cerr << "Exception caught!" << '\n';
std::cerr << e.what() << '\n';
throw e;
}

cout << "Decoding complete!" << endl;
cout << "Press any key to continue..." << endl;
std::cout << "Decoding complete!" << '\n';
std::cout << "Press any key to continue..." << '\n';

getchar();
}
17 changes: 17 additions & 0 deletions examples/decode_video/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

add_executable(decode_video
decode_video.cpp
)

set_target_properties(decode_video PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

target_include_directories(decode_video PUBLIC
${PROJECT_SOURCE_DIR}/include/ffmpegcpp
${PROJECT_SOURCE_DIR}/ffmpeg/include
)

target_link_libraries(decode_video ffmpegcpp)

set_target_properties(decode_video PROPERTIES FOLDER examples)
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@

#include <iostream>
#include <memory>

#include "ffmpegcpp.h"

using namespace std;
using namespace ffmpegcpp;

class PGMFileSink : public VideoFrameSink
class PGMFileSink : public ffmpegcpp::VideoFrameSink
{
public:

PGMFileSink()
{
}

virtual void WriteFrame(AVFrame* frame, AVRational* timeBase)
void WriteFrame(AVFrame* frame, AVRational* timeBase) override
{
++frameNumber;
printf("saving frame %3d\n", frameNumber);
Expand All @@ -41,12 +39,12 @@ class PGMFileSink : public VideoFrameSink
fclose(f);
}

virtual void Close()
void Close() override
{
// nothing to do here.
}

virtual bool IsPrimed()
bool IsPrimed() const override
{
// Return whether we have all information we need to start writing out data.
// Since we don't really need any data in this use case, we are always ready.
Expand All @@ -67,36 +65,32 @@ int main()
try
{
// Load this container file so we can extract video from it.
Demuxer* demuxer = new Demuxer("samples/big_buck_bunny.mp4");
ffmpegcpp::Demuxer demuxer("samples/big_buck_bunny.mp4");

// Create a file sink that will just output the raw frame data in one PGM file per frame.
PGMFileSink* fileSink = new PGMFileSink();
auto fileSink = std::make_unique<PGMFileSink>();

// tie the file sink to the best video stream in the input container.
demuxer->DecodeBestVideoStream(fileSink);
demuxer.DecodeBestVideoStream(fileSink.get());

// Prepare the output pipeline. This will push a small amount of frames to the file sink until it IsPrimed returns true.
demuxer->PreparePipeline();
demuxer.PreparePipeline();

// Push all the remaining frames through.
while (!demuxer->IsDone())
while (!demuxer.IsDone())
{
demuxer->Step();
demuxer.Step();
}

// done
delete demuxer;
delete fileSink;
}
catch (FFmpegException e)
catch (ffmpegcpp::FFmpegException e)
{
cerr << "Exception caught!" << endl;
cerr << e.what() << endl;
std::cerr << "Exception caught!" << '\n';
std::cerr << e.what() << '\n';
throw e;
}

cout << "Decoding complete!" << endl;
cout << "Press any key to continue..." << endl;
std::cout << "Decoding complete!" << '\n';
std::cout << "Press any key to continue..." << '\n';

getchar();
}
19 changes: 19 additions & 0 deletions examples/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

add_executable(demo
demo.cpp
GeneratedAudioSource.cpp
GeneratedVideoSource.cpp
)

set_target_properties(demo PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)

target_include_directories(demo PUBLIC
${PROJECT_SOURCE_DIR}/include/ffmpegcpp
${PROJECT_SOURCE_DIR}/ffmpeg/include
)

target_link_libraries(demo ffmpegcpp)

set_target_properties(demo PROPERTIES FOLDER examples)
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#include "GeneratedAudioSource.h"

GeneratedAudioSource::GeneratedAudioSource(AudioFrameSink* frameSink)
GeneratedAudioSource::GeneratedAudioSource(ffmpegcpp::AudioFrameSink* frameSink)
{
this->sampleRate = 44100;
this->channels = 2;
this->format = AV_SAMPLE_FMT_S16;

// generate a raw video source that will convert the raw format to any other format and pass it on to the encoder
// or any other sink (might be a filter as well).
output = new RawAudioDataSource(format, this->sampleRate, this->channels, frameSink);
output = std::make_unique<ffmpegcpp::RawAudioDataSource>(format, this->sampleRate, this->channels, frameSink);

samples = new uint16_t[channels * 2 * sampleCount];

}

GeneratedAudioSource::~GeneratedAudioSource()
{
delete output;
delete samples;
}

Expand All @@ -28,7 +27,7 @@ void GeneratedAudioSource::PreparePipeline()
}
}

bool GeneratedAudioSource::IsDone()
bool GeneratedAudioSource::IsDone() const
{
return frameNumber >= 120;
}
Expand All @@ -37,7 +36,7 @@ void GeneratedAudioSource::Step()
{
/* encode a single tone sound */
float t = 0.0f;
float tincr = 2 * M_PI * 440.0 / sampleRate;
float tincr = (float)(2.0 * M_PI * 440.0) / (float)sampleRate;
for (int i = 0; i < 120; i++)
{
/* make sure the frame is writable -- makes a copy if the encoder
Expand Down
32 changes: 32 additions & 0 deletions examples/demo/GeneratedAudioSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <memory>

#include "ffmpegcpp.h"

class GeneratedAudioSource : public ffmpegcpp::InputSource
{
public:

GeneratedAudioSource(ffmpegcpp::AudioFrameSink* frameSink);
~GeneratedAudioSource();

void PreparePipeline() override;
bool IsDone() const override;
void Step() override;

private:

int sampleRate;
int channels;
AVSampleFormat format;

std::unique_ptr<ffmpegcpp::RawAudioDataSource> output;

int sampleCount = 735;

uint16_t* samples;

int frameNumber = 0;
};

Loading