遍历支持的解码器.txt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 下面简单介绍一下遍历ffmpeg中的解码器信息的方法(这些解码器以一个链表的形式存储):
  2. 1.注册所有编解码器:av_register_all();
  3. 2.声明一个AVCodec类型的指针,比如说AVCodec* p;
  4. 3.调用av_codec_next()函数,即可获得指向链表下一个解码器的指针,循环往复可以获得所有解码器的信息。注意,如果想要获得指向第一个解码器的指针,则需要将该函数的参数设置为NULL。
  5. /**
  6. * If c is NULL, returns the first registered codec,
  7. * if c is non-NULL, returns the next registered codec after c,
  8. * or NULL if c is the last one.
  9. */
  10. int getSupportCodecs(void)
  11. {
  12. char *info = (char *)malloc(40000);
  13. memset(info, 0, 40000);
  14. av_register_all();
  15. AVCodec *c_temp = av_codec_next(NULL);
  16. while (c_temp != NULL)
  17. {
  18. if (c_temp->decode != NULL)
  19. {
  20. strcat(info, "[Decode]");
  21. }
  22. else
  23. {
  24. strcat(info, "[Encode]");
  25. }
  26. switch (c_temp->type)
  27. {
  28. case AVMEDIA_TYPE_VIDEO:
  29. strcat(info, "[Video]");
  30. break;
  31. case AVMEDIA_TYPE_AUDIO:
  32. strcat(info, "[Audeo]");
  33. break;
  34. default:
  35. strcat(info, "[Other]");
  36. break;
  37. }
  38. sprintf(info, "%s %10s\n", info, c_temp->name);
  39. c_temp = c_temp->next;
  40. }
  41. fprintf(stderr, "%s %s\n", __FUNCTION__, info);
  42. free(info);
  43. return 0;
  44. }