Skip to content

Commit d82a388

Browse files
clean Metadata API
1 parent f73db27 commit d82a388

13 files changed

+291
-195
lines changed

app/avMeta/avMeta.cpp

Lines changed: 75 additions & 63 deletions
Large diffs are not rendered by default.

app/avTranscoder/avTranscoder.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <iostream>
22
#include <iomanip>
33

4-
#include <AvTranscoder/Media.hpp>
54
#include <AvTranscoder/InputStream.hpp>
65
#include <AvTranscoder/InputStreamAudio.hpp>
76
#include <AvTranscoder/InputStreamVideo.hpp>
@@ -20,8 +19,8 @@ void transcodeVideo( const char* inputfilename, const char* outputFilename )
2019
{
2120
using namespace avtranscoder;
2221

23-
Media input( inputfilename );
24-
input.analyse();
22+
InputFile input;
23+
input.setup( inputfilename ).analyse();
2524

2625
// init video decoders
2726
InputStreamVideo inputStreamVideo; // take the first video stream per default

src/AvTranscoder/InputFile.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#include "InputFile.hpp"
2+
#include "Metadatas/VideoStreamProperties.hpp"
3+
#include "Metadatas/AudioStreamProperties.hpp"
4+
#include "Metadatas/DataStreamProperties.hpp"
5+
#include "Metadatas/SubtitleStreamProperties.hpp"
6+
#include "Metadatas/AttachementStreamProperties.hpp"
7+
#include "Metadatas/UnknownStreamProperties.hpp"
8+
29

310
extern "C" {
411
#ifndef __STDC_CONSTANT_MACROS
@@ -54,6 +61,69 @@ InputFile& InputFile::setup( const std::string& filename )
5461
return *this;
5562
}
5663

64+
InputFile& InputFile::analyse()
65+
{
66+
properties.filename = m_formatContext->filename;
67+
properties.formatName = m_formatContext->iformat->name;
68+
properties.formatLongName = m_formatContext->iformat->long_name;
69+
properties.streamsCount = m_formatContext->nb_streams;
70+
properties.programsCount = m_formatContext->nb_programs;
71+
properties.startTime = 1.0 * (uint)m_formatContext->start_time / AV_TIME_BASE;
72+
properties.duration = 1.0 * m_formatContext->duration / AV_TIME_BASE;
73+
properties.bitRate = m_formatContext->bit_rate;
74+
properties.packetSize = m_formatContext->packet_size;
75+
76+
AVDictionaryEntry *tag = NULL;
77+
while( ( tag = av_dict_get( m_formatContext->metadata, "", tag, AV_DICT_IGNORE_SUFFIX ) ) )
78+
{
79+
properties.metadatas.push_back( std::pair<std::string, std::string>( tag->key, tag->value ) );
80+
}
81+
82+
for( size_t streamId = 0; streamId < m_formatContext->nb_streams; streamId++ )
83+
{
84+
switch( m_formatContext->streams[streamId]->codec->codec_type )
85+
{
86+
case AVMEDIA_TYPE_VIDEO:
87+
{
88+
properties.videoStreams.push_back( videoStreamInfo( m_formatContext, streamId ) );
89+
break;
90+
}
91+
case AVMEDIA_TYPE_AUDIO:
92+
{
93+
properties.audioStreams.push_back( audioStreamInfo( m_formatContext, streamId ) );
94+
break;
95+
}
96+
case AVMEDIA_TYPE_DATA:
97+
{
98+
properties.dataStreams.push_back( dataStreamInfo( m_formatContext, streamId ) );
99+
break;
100+
}
101+
case AVMEDIA_TYPE_SUBTITLE:
102+
{
103+
properties.subtitleStreams.push_back( subtitleStreamInfo( m_formatContext, streamId ) );
104+
break;
105+
}
106+
case AVMEDIA_TYPE_ATTACHMENT:
107+
{
108+
properties.attachementStreams.push_back( attachementStreamInfo( m_formatContext, streamId ) );
109+
break;
110+
}
111+
case AVMEDIA_TYPE_UNKNOWN:
112+
{
113+
properties.unknownStreams.push_back( unknownStreamInfo( m_formatContext, streamId ) );
114+
break;
115+
}
116+
case AVMEDIA_TYPE_NB:
117+
{
118+
// std::cout << "NB" << std::endl;
119+
break;
120+
}
121+
}
122+
}
123+
124+
return *this;
125+
}
126+
57127
VideoDesc InputFile::getVideoDesc( size_t videoStreamId )
58128
{
59129
int selectedStream = -1;

src/AvTranscoder/InputFile.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "DatasStructures/DataStreamDesc.hpp"
55
#include "DatasStructures/VideoDesc.hpp"
6+
#include "Metadatas/MediaMetadatasStructures.hpp"
67

78
#include <string>
89
#include <vector>
@@ -24,6 +25,13 @@ class InputFile
2425

2526
InputFile& setup( const std::string& file );
2627

28+
// *** Metadatas section ***
29+
// run the analyse on the file after a setup.
30+
InputFile& analyse();
31+
// get properties on the file
32+
const Properties& getProperties() const { return properties; }
33+
34+
2735
VideoDesc getVideoDesc( size_t videoStreamId );
2836
bool getAudioStream( );
2937

@@ -35,11 +43,11 @@ class InputFile
3543

3644
protected:
3745
AVFormatContext* m_formatContext;
38-
3946
AVStream* m_stream;
4047

41-
std::string m_filename;
48+
Properties properties;
4249

50+
std::string m_filename;
4351
size_t m_packetCount;
4452
};
4553

src/AvTranscoder/Media.cpp

Lines changed: 0 additions & 103 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef _AV_TRANSCODER_ATTACHEMENT_STREAM_PROPERTIES_HPP_
2+
#define _AV_TRANSCODER_ATTACHEMENT_STREAM_PROPERTIES_HPP_
3+
4+
extern "C" {
5+
#ifndef __STDC_CONSTANT_MACROS
6+
#define __STDC_CONSTANT_MACROS
7+
#endif
8+
#include <libavcodec/avcodec.h>
9+
#include <libavformat/avformat.h>
10+
#include <libavutil/avutil.h>
11+
#include <libavutil/pixdesc.h>
12+
}
13+
14+
namespace avtranscoder
15+
{
16+
17+
AttachementProperties attachementStreamInfo( const AVFormatContext* formatContext, const size_t index )
18+
{
19+
AttachementProperties ap;
20+
ap.streamId = index;
21+
return ap;
22+
}
23+
24+
}
25+
26+
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef _AV_TRANSCODER_DATA_STREAM_PROPERTIES_HPP_
2+
#define _AV_TRANSCODER_DATA_STREAM_PROPERTIES_HPP_
3+
4+
extern "C" {
5+
#ifndef __STDC_CONSTANT_MACROS
6+
#define __STDC_CONSTANT_MACROS
7+
#endif
8+
#include <libavcodec/avcodec.h>
9+
#include <libavformat/avformat.h>
10+
#include <libavutil/avutil.h>
11+
#include <libavutil/pixdesc.h>
12+
}
13+
14+
namespace avtranscoder
15+
{
16+
17+
DataProperties dataStreamInfo( const AVFormatContext* formatContext, const size_t index )
18+
{
19+
DataProperties dp;
20+
dp.streamId = index;
21+
return dp;
22+
}
23+
24+
}
25+
26+
#endif

src/AvTranscoder/Media.hpp renamed to src/AvTranscoder/Metadatas/MediaMetadatasStructures.hpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _AV_TRANSCODER_MEDIA_HPP_
22
#define _AV_TRANSCODER_MEDIA_HPP_
33

4-
#include "common.hpp"
4+
#include <AvTranscoder/common.hpp>
55

66
#include <string>
77
#include <vector>
@@ -79,6 +79,22 @@ struct AudioProperties {
7979
size_t bit_rate;
8080
};
8181

82+
struct DataProperties {
83+
size_t streamId;
84+
};
85+
86+
struct SubtitleProperties {
87+
size_t streamId;
88+
};
89+
90+
struct AttachementProperties {
91+
size_t streamId;
92+
};
93+
94+
struct UnknownProperties {
95+
size_t streamId;
96+
};
97+
8298
struct Properties {
8399
std::string filename;
84100
std::string formatName;
@@ -89,25 +105,15 @@ struct Properties {
89105
double duration;
90106
size_t bitRate;
91107
size_t packetSize;
92-
std::vector< VideoProperties > videoStreams;
93-
std::vector< AudioProperties > audioStreams;
94-
std::vector< std::pair< std::string, std::string > > metadatas; // ( key, value )
95-
};
96-
97-
class Media
98-
{
99-
public:
100-
Media( const std::string& inputFile = "" );
101-
102-
// return true if analyse was done with success
103-
bool analyse();
104-
105-
const Properties& getProperties() const { return properties; }
108+
109+
std::vector< VideoProperties > videoStreams;
110+
std::vector< AudioProperties > audioStreams;
111+
std::vector< DataProperties > dataStreams;
112+
std::vector< SubtitleProperties > subtitleStreams;
113+
std::vector< AttachementProperties > attachementStreams;
114+
std::vector< UnknownProperties > unknownStreams;
106115

107-
private:
108-
std::string filename;
109-
AVFormatContext* formatContext;
110-
Properties properties;
116+
std::vector< std::pair< std::string, std::string > > metadatas; // ( key, value )
111117
};
112118

113119
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef _AV_TRANSCODER_SUBTITLE_STREAM_PROPERTIES_HPP_
2+
#define _AV_TRANSCODER_SUBTITLE_STREAM_PROPERTIES_HPP_
3+
4+
extern "C" {
5+
#ifndef __STDC_CONSTANT_MACROS
6+
#define __STDC_CONSTANT_MACROS
7+
#endif
8+
#include <libavcodec/avcodec.h>
9+
#include <libavformat/avformat.h>
10+
#include <libavutil/avutil.h>
11+
#include <libavutil/pixdesc.h>
12+
}
13+
14+
namespace avtranscoder
15+
{
16+
17+
SubtitleProperties subtitleStreamInfo( const AVFormatContext* formatContext, const size_t index )
18+
{
19+
SubtitleProperties sp;
20+
sp.streamId = index;
21+
22+
return sp;
23+
}
24+
25+
}
26+
27+
#endif

0 commit comments

Comments
 (0)