Skip to content

Commit 99f660f

Browse files
author
Clement Champetier
committed
Common: add getFormat
Get the format name from the given filename.
1 parent e891d86 commit 99f660f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/AvTranscoder/common.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern "C" {
55
#define __STDC_CONSTANT_MACROS
66
#endif
77
#include <libavcodec/avcodec.h>
8+
#include <libavformat/avformat.h>
89
#include <libavutil/opt.h>
910
#include <libavutil/error.h>
1011
}
@@ -156,4 +157,19 @@ int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
156157
return 0;
157158
}
158159

160+
std::string getFormat( const std::string& filename )
161+
{
162+
std::string format( "" );
163+
164+
av_register_all();
165+
AVOutputFormat* avOutputFormat = av_guess_format( NULL, filename.c_str(), NULL);
166+
if( avOutputFormat )
167+
{
168+
if( avOutputFormat->name )
169+
format = std::string( avOutputFormat->name );
170+
}
171+
172+
return format;
173+
}
174+
159175
}

src/AvTranscoder/common.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ void split( std::vector< std::string >& splitedString, const std::string& inputS
8686

8787
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );
8888

89+
90+
std::string getFormat( const std::string& filename );
91+
8992
}
9093

9194
#endif

0 commit comments

Comments
 (0)