Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
replaced char * with std::strings
  • Loading branch information
wvaarle committed Dec 20, 2018
commit 9b0be3c96b645a9c0ce21bdf4b4a9e9b68f9d443
4 changes: 2 additions & 2 deletions examples/decode_audio/decode_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ 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");
}

void WriteFrame(AVFrame* frame, AVRational* timeBase) override
Expand Down
47 changes: 25 additions & 22 deletions examples/demo/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ void PlayDemo(int argc, char** argv)
{

// These are example video and audio sources used below.
const char* rawVideoFile = "samples/carphone_qcif.y4m";
int rawVideoWidth = 176; int rawVideoHeight = 162;
const char* rawAudioFile = "samples/Vivaldi_s16le_2_channels_samplerate_11025.dat";
const char* rawAudioFormat = "s16le"; int rawAudioSampleRate = 11025; int rawAudioChannels = 2;
std::string rawVideoFile = "samples/carphone_qcif.y4m";
int rawVideoWidth = 176;
int rawVideoHeight = 162;
std::string rawAudioFile = "samples/Vivaldi_s16le_2_channels_samplerate_11025.dat";
std::string rawAudioFormat = "s16le";
int rawAudioSampleRate = 11025;
int rawAudioChannels = 2;

const char* encodedVideoFile = "samples/carphone.h264";
const char* encodedAudioFile = "samples/Vivaldi_Sonata_eminor_.mp3";
std::string encodedVideoFile = "samples/carphone.h264";
std::string encodedAudioFile = "samples/Vivaldi_Sonata_eminor_.mp3";

const char* containerWithVideoAndAudioFile = "samples/big_buck_bunny.mp4";
const char* containerWithAudioFile = "samples/DesiJourney.wav";
std::string containerWithVideoAndAudioFile = "samples/big_buck_bunny.mp4";
std::string containerWithAudioFile = "samples/DesiJourney.wav";

// hard-code the settings here, but let them be overridden by the arguments
std::string inputAudioSource = "CONTAINER"; // options are RAW, ENCODED, CONTAINER, GENERATED
Expand Down Expand Up @@ -71,13 +74,13 @@ void PlayDemo(int argc, char** argv)
std::unique_ptr<ffmpegcpp::AudioCodec> audioCodec;
if (outputAudioCodec == "MP2")
{
printf("Encoding audio as MP2...\n");
std::cout << "Encoding audio as MP2...\n";
audioCodec = std::make_unique<ffmpegcpp::AudioCodec>(AV_CODEC_ID_MP2);

}
else if (outputAudioCodec == "AAC")
{
printf("Encoding audio as AAC...\n");
std::cout << "Encoding audio as AAC...\n";
audioCodec = std::make_unique<ffmpegcpp::AudioCodec>(AV_CODEC_ID_AAC);

}
Expand All @@ -102,21 +105,21 @@ void PlayDemo(int argc, char** argv)
std::unique_ptr<ffmpegcpp::VideoCodec> videoCodec;
if (outputVideoCodec == "H264")
{
printf("Encoding video as H264 on Nvidia GPU...\n");
std::cout << "Encoding video as H264 on Nvidia GPU...\n";
auto h264Codec = std::make_unique<ffmpegcpp::H264NVEncCodec>();
h264Codec->SetPreset("hq");
videoCodec = std::move(h264Codec);
}
else if (outputVideoCodec == "H265")
{
printf("Encoding video as H265 on Nvidia GPU...\n");
std::cout << "Encoding video as H265 on Nvidia GPU...\n";
auto h265Codec = std::make_unique<ffmpegcpp::H265NVEncCodec>();
h265Codec->SetPreset("hq");
videoCodec = std::move(h265Codec);
}
else if (outputVideoCodec == "VP9")
{
printf("Encoding video as VP9...\n");
std::cout << "Encoding video as VP9...\n";
auto vp9Codec = std::make_unique<ffmpegcpp::VP9Codec>();
vp9Codec->SetLossless(true);
videoCodec = std::move(vp9Codec);
Expand Down Expand Up @@ -144,25 +147,25 @@ void PlayDemo(int argc, char** argv)
{
if (inputAudioSource == "RAW")
{
printf("Pulling audio from %s...\n", rawAudioFile);
std::cout << "Pulling audio from " << rawAudioFile << "...\n";
audioInputSource = std::make_unique<ffmpegcpp::RawAudioFileSource>(rawAudioFile, rawAudioFormat, rawAudioSampleRate, rawAudioChannels, audioEncoder.get());
}
else if (inputAudioSource == "ENCODED")
{
printf("Pulling audio from %s...\n", encodedAudioFile);
std::cout << "Pulling audio from " << encodedAudioFile << "...\n";
audioInputSource = std::make_unique<ffmpegcpp::EncodedFileSource>(encodedAudioFile, AV_CODEC_ID_MP3, audioEncoder.get());
}
else if (inputAudioSource == "CONTAINER")
{
// if the input comes from a container, we use the demuxer class - it is just an input source like any other
printf("Pulling audio from %s...\n", containerWithAudioFile);
std::cout << "Pulling audio from " << containerWithAudioFile << "...\n";
auto demuxer = std::make_unique<ffmpegcpp::Demuxer>(containerWithAudioFile);
demuxer->DecodeBestAudioStream(audioEncoder.get());
audioInputSource = std::move(demuxer);
}
else if (inputAudioSource == "GENERATED")
{
printf("Generating 440Hz audio tone...\n");
std::cout << "Generating 440Hz audio tone...\n";
audioInputSource = std::make_unique<GeneratedAudioSource>(audioEncoder.get());
}
}
Expand All @@ -177,7 +180,7 @@ void PlayDemo(int argc, char** argv)
std::unique_ptr<ffmpegcpp::VideoFilter> videoFilter;
if (videoFilterConfig != nullptr && videoEncoder != nullptr)
{
printf("Applying filter %s to video...\n", videoFilterConfig);
std::cout << "Applying filter " << videoFilterConfig << " to video...\n";
videoFilter = std::make_unique<ffmpegcpp::VideoFilter>(videoFilterConfig, videoEncoder.get());
}

Expand All @@ -191,24 +194,24 @@ void PlayDemo(int argc, char** argv)
{
if (inputVideoSource == "RAW")
{
printf("Pulling video from %s...\n", rawVideoFile);
std::cout << "Pulling video from " << rawVideoFile << "...\n";
videoInputSource = std::make_unique<ffmpegcpp::RawVideoFileSource>(rawVideoFile, videoFilter.get());
}
else if (inputVideoSource == "ENCODED")
{
printf("Pulling video from %s...\n", encodedVideoFile);
std::cout << "Pulling video from " << encodedVideoFile << "...\n";
videoInputSource = std::make_unique<ffmpegcpp::RawVideoFileSource>(encodedVideoFile, videoFilter.get());
}
else if (inputVideoSource == "CONTAINER")
{
printf("Pulling video from %s...\n", containerWithVideoAndAudioFile);
std::cout << "Pulling video from " << containerWithVideoAndAudioFile << "...\n";
auto demuxer = std::make_unique<ffmpegcpp::Demuxer>(containerWithVideoAndAudioFile);
demuxer->DecodeBestVideoStream(videoFilter.get());
videoInputSource = std::move(demuxer);
}
else if (inputVideoSource == "GENERATED")
{
printf("Generating checkerboard video pattern...\n");
std::cout << "Generating checkerboard video pattern...\n";
videoInputSource = std::make_unique<GeneratedVideoSource>(640, 480, videoFilter.get());
}
}
Expand Down
7 changes: 5 additions & 2 deletions examples/encode_audio/encode_audio.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include <iostream>
#include <memory>
#include <string>

#include "ffmpegcpp.h"

Expand All @@ -22,8 +23,10 @@ int main()
// Load the raw audio file so we can process it.
// We need to provide some info because we can't derive it from the raw format.
// Hand it the encoder so it will pass on its raw data to the encoder, which will in turn pass it on to the muxer.
const char* rawAudioFile = "samples/Vivaldi_s16le_2_channels_samplerate_11025.dat";
const char* rawAudioFormat = "s16le"; int rawAudioSampleRate = 11025; int rawAudioChannels = 2;
std::string rawAudioFile = "samples/Vivaldi_s16le_2_channels_samplerate_11025.dat";
std::string rawAudioFormat = "s16le";
int rawAudioSampleRate = 11025;
int rawAudioChannels = 2;
auto audioFile = std::make_unique<ffmpegcpp::RawAudioFileSource>(rawAudioFile, rawAudioFormat, rawAudioSampleRate, rawAudioChannels, encoder.get());

// Prepare the output pipeline. This will push a small amount of frames to the file sink until it IsPrimed returns true.
Expand Down
8 changes: 5 additions & 3 deletions include/ffmpegcpp/CodecDeducer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <string>

enum AVCodecID;
struct AVCodec;

Expand All @@ -9,13 +11,13 @@ namespace ffmpegcpp
{
public:

static AVCodec* DeduceEncoderFromFilename(const char* fileName);
static AVCodec* DeduceEncoderFromFilename(const std::string & fileName);

static AVCodec* DeduceEncoder(AVCodecID codecId);
static AVCodec* DeduceEncoder(const char* codecName);
static AVCodec* DeduceEncoder(const std::string & codecName);

static AVCodec* DeduceDecoder(AVCodecID codecId);
static AVCodec* DeduceDecoder(const char* codecName);
static AVCodec* DeduceDecoder(const std::string & codecName);
};

}
4 changes: 3 additions & 1 deletion include/ffmpegcpp/Codecs/AudioCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Codecs/Codec.h"

#include <string>

enum AVCodecID;
enum AVSampleFormat;

Expand All @@ -13,7 +15,7 @@ namespace ffmpegcpp
{
public:

AudioCodec(const char* codecName);
AudioCodec(const std::string & codecName);
AudioCodec(AVCodecID codecId);

std::unique_ptr<OpenCodec> Open(int bitRate, AVSampleFormat format, int sampleRate);
Expand Down
9 changes: 5 additions & 4 deletions include/ffmpegcpp/Codecs/Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "FFmpegResource.h"

#include <memory>
#include <string>

enum AVCodecID;
struct AVCodecContext;
Expand All @@ -15,12 +16,12 @@ namespace ffmpegcpp
{
public:

Codec(const char* codecName);
Codec(const std::string & codecName);
Codec(AVCodecID codecId);

void SetOption(const char* name, const char* value);
void SetOption(const char* name, int value);
void SetOption(const char* name, double value);
void SetOption(const std::string & name, const std::string & value);
void SetOption(const std::string & name, int value);
void SetOption(const std::string & name, double value);

void SetGlobalContainerHeader(); // used by the Muxer for configuration purposes

Expand Down
4 changes: 3 additions & 1 deletion include/ffmpegcpp/Codecs/H264NVEncCodec.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "VideoCodec.h"

#include <string>

namespace ffmpegcpp
{

Expand All @@ -11,7 +13,7 @@ namespace ffmpegcpp

H264NVEncCodec();

void SetPreset(const char* preset);
void SetPreset(const std::string & preset);
};


Expand Down
4 changes: 3 additions & 1 deletion include/ffmpegcpp/Codecs/H265NVEncCodec.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "VideoCodec.h"

#include <string>

namespace ffmpegcpp
{

Expand All @@ -11,7 +13,7 @@ namespace ffmpegcpp

H265NVEncCodec();

void SetPreset(const char* preset);
void SetPreset(const std::string & preset);
};


Expand Down
5 changes: 3 additions & 2 deletions include/ffmpegcpp/Codecs/VP9Codec.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include "VideoCodec.h"

#include <string>

namespace ffmpegcpp
{

Expand All @@ -11,12 +13,11 @@ namespace ffmpegcpp

VP9Codec();

void SetDeadline(const char* deadline);
void SetDeadline(const std::string & deadline);
void SetCpuUsed(int cpuUsed);

void SetLossless(bool lossless);
void SetCrf(int crf);
};


}
4 changes: 3 additions & 1 deletion include/ffmpegcpp/Codecs/VideoCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Codec.h"

#include <string>

enum AVCodecID;
enum AVSampleFormat;
struct AVRational;
Expand All @@ -14,7 +16,7 @@ namespace ffmpegcpp
{
public:

VideoCodec(const char* codecName);
VideoCodec(const std::string & codecName);
VideoCodec(AVCodecID codecId);
virtual ~VideoCodec();

Expand Down
4 changes: 2 additions & 2 deletions include/ffmpegcpp/FFmpegException.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ 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);

char const* what() const override
{
Expand Down
6 changes: 4 additions & 2 deletions include/ffmpegcpp/FrameSinks/VideoFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "FrameSinks/VideoFrameSink.h"
#include "FFmpegResource.h"

#include <string>

struct AVFilterContext;
struct AVFilterGraph;
struct AVFrame;
Expand All @@ -16,7 +18,7 @@ namespace ffmpegcpp

public:

VideoFilter(const char* filterString, VideoFrameSink* target);
VideoFilter(const std::string & filterString, VideoFrameSink* target);

void WriteFrame(AVFrame* frame, AVRational* timeBase) override;
void Close() override;
Expand All @@ -30,7 +32,7 @@ namespace ffmpegcpp

VideoFrameSink* target;

const char* filterString;
std::string filterString;
AVPixelFormat outputFormat;

FFmpegResource<AVFilterGraph> filter_graph;
Expand Down
2 changes: 1 addition & 1 deletion include/ffmpegcpp/Muxing/Muxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ffmpegcpp {
{
public:

Muxer(const char* fileName);
Muxer(const std::string & fileName);
~Muxer();

void AddOutputStream(OutputStream* stream);
Expand Down
6 changes: 3 additions & 3 deletions include/ffmpegcpp/Sources/Demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace ffmpegcpp
{
public:

Demuxer(const char* fileName);
Demuxer(const char* fileName, AVInputFormat* inputFormat, AVDictionary *inputFormatOptions);
Demuxer(const std::string & fileName);
Demuxer(const std::string & fileName, AVInputFormat* inputFormat, AVDictionary *inputFormatOptions);

void DecodeBestAudioStream(AudioFrameSink* frameSink);
void DecodeBestVideoStream(VideoFrameSink* frameSink);
Expand All @@ -51,7 +51,7 @@ namespace ffmpegcpp

bool done = false;

const char* fileName;
std::string fileName;

std::vector<StreamInfo> GetStreamInfo(AVMediaType mediaType) const;
StreamInfo CreateInfo(int streamIndex, AVStream* stream, AVCodec* codec) const;
Expand Down
Loading