[FFmpeg-devel] [PATCH] avformat: implement query_codec for the image2 muxer.
tab
tab at 0x09.net
Sun Sep 6 17:07:20 CEST 2015
Allows avformat_query_codec to be used to check for valid image2 encoders.
Reuses the existing ff_guess_image2_codec ID table.
---
libavformat/img2.c | 10 +++-------
libavformat/img2.h | 7 +++++++
libavformat/img2enc.c | 12 ++++++++++++
3 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 184600f..50352b5 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -22,13 +22,9 @@
#include "libavutil/avstring.h"
#include "internal.h"
+#include "img2.h"
-typedef struct IdStrMap {
- enum AVCodecID id;
- const char *str;
-} IdStrMap;
-
-static const IdStrMap img_tags[] = {
+const IdStrMap ff_img_tags[] = {
{ AV_CODEC_ID_MJPEG, "jpeg" },
{ AV_CODEC_ID_MJPEG, "jpg" },
{ AV_CODEC_ID_MJPEG, "jps" },
@@ -103,5 +99,5 @@ static enum AVCodecID av_str2id(const IdStrMap *tags, const char *str)
enum AVCodecID ff_guess_image2_codec(const char *filename)
{
- return av_str2id(img_tags, filename);
+ return av_str2id(ff_img_tags, filename);
}
diff --git a/libavformat/img2.h b/libavformat/img2.h
index f6b9dd9..deebcc3 100644
--- a/libavformat/img2.h
+++ b/libavformat/img2.h
@@ -62,6 +62,13 @@ typedef struct VideoDemuxData {
int ts_from_file;
} VideoDemuxData;
+typedef struct IdStrMap {
+ enum AVCodecID id;
+ const char *str;
+} IdStrMap;
+
+extern const IdStrMap ff_img_tags[];
+
extern const AVOption ff_img_options[];
int ff_img_read_header(AVFormatContext *s1);
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index f56c39e..11768b2 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -30,6 +30,7 @@
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
+#include "img2.h"
typedef struct VideoMuxData {
const AVClass *class; /**< Class for private options. */
@@ -172,6 +173,15 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
return 0;
}
+static int query_codec(enum AVCodecID id, int std_compliance)
+{
+ int i;
+ for (i = 0; ff_img_tags[i].id != AV_CODEC_ID_NONE; i++)
+ if (ff_img_tags[i].id == id)
+ return 1;
+ return 0;
+}
+
#define OFFSET(x) offsetof(VideoMuxData, x)
#define ENC AV_OPT_FLAG_ENCODING_PARAM
static const AVOption muxoptions[] = {
@@ -200,6 +210,7 @@ AVOutputFormat ff_image2_muxer = {
.video_codec = AV_CODEC_ID_MJPEG,
.write_header = write_header,
.write_packet = write_packet,
+ .query_codec = query_codec,
.flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE,
.priv_class = &img2mux_class,
};
@@ -212,6 +223,7 @@ AVOutputFormat ff_image2pipe_muxer = {
.video_codec = AV_CODEC_ID_MJPEG,
.write_header = write_header,
.write_packet = write_packet,
+ .query_codec = query_codec,
.flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS
};
#endif
--
2.5.1
More information about the ffmpeg-devel
mailing list