[FFmpeg-devel] [PATCH] cmdutils: sort codec lists
Michael Niedermayer
michaelni at gmx.at
Sat Sep 22 20:39:07 CEST 2012
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
cmdutils.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/cmdutils.c b/cmdutils.c
index bd4ba4a..488cf0d 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -902,6 +902,10 @@ static void print_codecs_for_id(enum AVCodecID id, int encoder)
printf(")");
}
+static av_always_inline int cmp_codec_desc(const AVCodecDescriptor *a, const AVCodecDescriptor *b) {
+ return 256*(a->type - b->type) + strcmp(a->name, b->name);
+}
+
int show_codecs(void *optctx, const char *opt, const char *arg)
{
const AVCodecDescriptor *desc = NULL;
@@ -916,8 +920,16 @@ int show_codecs(void *optctx, const char *opt, const char *arg)
" ....L. = Lossy compression\n"
" .....S = Lossless compression\n"
" -------\n");
- while ((desc = avcodec_descriptor_next(desc))) {
+ for(;;) {
const AVCodec *codec = NULL;
+ const AVCodecDescriptor *last = desc, *tmp = NULL;
+
+ while(tmp = avcodec_descriptor_next(tmp))
+ if(!last || cmp_codec_desc(tmp, last) > 0)
+ if(desc==last || cmp_codec_desc(tmp, desc) < 0)
+ desc = tmp;
+ if(desc == last)
+ return 0;
printf(" ");
printf(avcodec_find_decoder(desc->id) ? "D" : ".");
@@ -948,7 +960,6 @@ int show_codecs(void *optctx, const char *opt, const char *arg)
printf("\n");
}
- return 0;
}
static void print_codecs(int encoder)
@@ -966,8 +977,16 @@ static void print_codecs(int encoder)
" .....D = Supports direct rendering method 1\n"
" ------\n",
encoder ? "Encoders" : "Decoders");
- while ((desc = avcodec_descriptor_next(desc))) {
+ for(;;) {
const AVCodec *codec = NULL;
+ const AVCodecDescriptor *last = desc, *tmp = NULL;
+
+ while(tmp = avcodec_descriptor_next(tmp))
+ if(!last || cmp_codec_desc(tmp, last) > 0)
+ if(desc==last || cmp_codec_desc(tmp, desc) < 0)
+ desc = tmp;
+ if(desc == last)
+ return;
while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
printf(" %c", get_media_type_char(desc->type));
--
1.7.9.5
More information about the ffmpeg-devel
mailing list