Skip to content

Commit e8bcc13

Browse files
committed
added support for fetching the default video/audio codec of an output format
1 parent cfb0fb3 commit e8bcc13

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

source/ffmpeg-cpp/ffmpeg-cpp/Muxing/Muxer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Muxer.h"
22
#include "FFmpegException.h"
33
#include "OutputStream.h"
4+
#include "CodecDeducer.h"
45

56
#include <string>
67

@@ -70,6 +71,16 @@ namespace ffmpegcpp
7071
packetQueue.clear();
7172
}
7273

74+
AVCodec* Muxer::GetDefaultVideoFormat()
75+
{
76+
return CodecDeducer::DeduceEncoder(containerFormat->video_codec);
77+
}
78+
79+
AVCodec* Muxer::GetDefaultAudioFormat()
80+
{
81+
return CodecDeducer::DeduceEncoder(containerFormat->audio_codec);
82+
}
83+
7384
void Muxer::AddOutputStream(OutputStream* outputStream)
7485
{
7586
if (opened) throw FFmpegException("You cannot open a new stream after something was written to the muxer");

source/ffmpeg-cpp/ffmpeg-cpp/Muxing/Muxer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ namespace ffmpegcpp {
2323

2424
bool IsPrimed();
2525

26+
AVCodec* GetDefaultVideoFormat();
27+
AVCodec* GetDefaultAudioFormat();
28+
2629

2730
private:
2831

source/ffmpeg-cpp/ffmpeg-cpp/Sources/Demuxer.cpp

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -82,47 +82,6 @@ namespace ffmpegcpp
8282
}
8383
}
8484

85-
/*vector<StreamInfo> Demuxer::GetAudioStreamInfo()
86-
{
87-
return GetStreamInfo(AVMEDIA_TYPE_AUDIO);
88-
}
89-
90-
vector<StreamInfo> Demuxer::GetVideoStreamInfo()
91-
{
92-
return GetStreamInfo(AVMEDIA_TYPE_VIDEO);
93-
}
94-
95-
vector<StreamInfo> Demuxer::GetStreamInfo(AVMediaType mediaType)
96-
{
97-
vector<StreamInfo> streamInfo;
98-
for (int i = 0; i < containerContext->nb_streams; ++i)
99-
{
100-
AVStream* stream = containerContext->streams[i];
101-
102-
// find decoder for the stream
103-
AVCodec* codec = CodecDeducer::DeduceDecoder(stream->codecpar->codec_id);
104-
if (!codec)
105-
{
106-
throw FFmpegException(string("Failed to deduce codec for stream ") + std::to_string(i) + " in container");
107-
}
108-
109-
if (codec->type == mediaType)
110-
{
111-
streamInfo.push_back(CreateInfo(i, stream, codec));
112-
}
113-
}
114-
return streamInfo;
115-
}
116-
117-
StreamInfo Demuxer::CreateInfo(int streamIndex, AVStream* stream, AVCodec* codec)
118-
{
119-
StreamInfo info;
120-
info.streamId = streamIndex;
121-
info.stream = stream;
122-
info.codec = codec;
123-
return info;
124-
}*/
125-
12685
void Demuxer::DecodeBestAudioStream(FrameSink* frameSink)
12786
{
12887
int ret = av_find_best_stream(containerContext, AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0);
@@ -338,4 +297,9 @@ namespace ffmpegcpp
338297
// Return the right stream's frame count.
339298
return GetInputStreamById(streamId)->GetFramesProcessed();
340299
}
300+
301+
const char* Demuxer::GetFileName()
302+
{
303+
return fileName;
304+
}
341305
}

source/ffmpeg-cpp/ffmpeg-cpp/Sources/Demuxer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace ffmpegcpp
3232
ContainerInfo GetInfo();
3333
int GetFrameCount(int streamId);
3434

35+
const char* GetFileName();
36+
3537
private:
3638

3739
bool done = false;

0 commit comments

Comments
 (0)