0012-ffmpeg-add-omx_pix_fmt.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From c4fe39d5b2e35b7195ae3041adcb6ef786322dbb Mon Sep 17 00:00:00 2001
  2. From: "arvin.zhu" <arvin.zhu@starfivetech.com>
  3. Date: Fri, 23 Sep 2022 10:04:25 +0800
  4. Subject: [PATCH] ffmpeg: add omx_pix_fmt
  5. add omx_pix_fmt for mjpeg_omx decoder
  6. Signed-off-by: arvin.zhu <arvin.zhu@starfivetech.com>
  7. ---
  8. libavcodec/omxdec.c | 58 +++++++++++++++++++++++++++++++++++++++++----
  9. 1 file changed, 54 insertions(+), 4 deletions(-)
  10. diff --git a/libavcodec/omxdec.c b/libavcodec/omxdec.c
  11. index 03a2bca..b489c09 100755
  12. --- a/libavcodec/omxdec.c
  13. +++ b/libavcodec/omxdec.c
  14. @@ -105,8 +105,13 @@ static const struct {
  15. { OMX_COLOR_FormatYUV420Planar, AV_PIX_FMT_YUV420P },
  16. { OMX_COLOR_FormatYUV420SemiPlanar, AV_PIX_FMT_NV12 },
  17. - { OMX_COLOR_FormatYUV420PackedSemiPlanar, AV_PIX_FMT_NV21 },
  18. - { OMX_COLOR_FormatYUV444Interleaved, AV_PIX_FMT_YUV444P },
  19. + { OMX_COLOR_FormatYVU420SemiPlanar, AV_PIX_FMT_NV21 },
  20. + { OMX_COLOR_FormatYUV422SemiPlanar, AV_PIX_FMT_NV16 },
  21. + { OMX_COLOR_FormatYUV422Planar, AV_PIX_FMT_YUV422P },
  22. + { OMX_COLOR_FormatYCbYCr, AV_PIX_FMT_YUYV422 },
  23. + { OMX_COLOR_FormatYCrYCb, AV_PIX_FMT_YVYU422 },
  24. + { OMX_COLOR_FormatCbYCrY, AV_PIX_FMT_UYVY422 },
  25. + { OMX_COLOR_FormatYUV444Planar, AV_PIX_FMT_YUV444P },
  26. { 0 }
  27. };
  28. @@ -271,6 +276,7 @@ typedef struct OMXCodecContext {
  29. int input_zerocopy;
  30. int profile;
  31. + char *pixel_format; /**< Set by a private option. */
  32. } OMXCodecContext;
  33. static void append_buffer(pthread_mutex_t *mutex, pthread_cond_t *cond,
  34. @@ -571,9 +577,43 @@ static av_cold int omx_component_init(AVCodecContext *avctx, const char *role)
  35. out_port_params.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
  36. else if (avctx->codec->id == AV_CODEC_ID_HEVC)
  37. out_port_params.format.video.eCompressionFormat = OMX_VIDEO_CodingHEVC;
  38. - else if (avctx->codec->id == AV_CODEC_ID_MJPEG)
  39. + else if (avctx->codec->id == AV_CODEC_ID_MJPEG){
  40. out_port_params.format.video.eCompressionFormat = OMX_VIDEO_CodingMJPEG;
  41. + av_log(avctx, AV_LOG_VERBOSE, "OMX_pixel_format:%s\n", s->pixel_format);
  42. + switch (av_get_pix_fmt(s->pixel_format)) {
  43. + case AV_PIX_FMT_NV12:
  44. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
  45. + break;
  46. + case AV_PIX_FMT_NV21:
  47. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYVU420SemiPlanar;
  48. + break;
  49. + case AV_PIX_FMT_YUV420P:
  50. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
  51. + break;
  52. + case AV_PIX_FMT_NV16:
  53. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYUV422SemiPlanar;
  54. + break;
  55. + case AV_PIX_FMT_YUV422P:
  56. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYUV422Planar;
  57. + break;
  58. + case AV_PIX_FMT_YUYV422:
  59. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYCbYCr;
  60. + break;
  61. + case AV_PIX_FMT_YVYU422:
  62. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYCrYCb;
  63. + break;
  64. + case AV_PIX_FMT_UYVY422:
  65. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatCbYCrY;
  66. + break;
  67. + case AV_PIX_FMT_YUV444P:
  68. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYUV444Planar;
  69. + break;
  70. + default:
  71. + out_port_params.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
  72. + }
  73. + }
  74. +
  75. err = OMX_SetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
  76. CHECK(err);
  77. err = OMX_GetParameter(s->handle, OMX_IndexParamPortDefinition, &out_port_params);
  78. @@ -961,6 +1001,15 @@ static const AVOption options_hevc[] = {
  79. { NULL },
  80. };
  81. +static const AVOption options_mjpeg[] = {
  82. + { "omx_libname", "OpenMAX library name", OFFSET(libname), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
  83. + { "omx_libprefix", "OpenMAX library prefix", OFFSET(libprefix), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VDE },
  84. + { "zerocopy", "Try to avoid copying input frames if possible", OFFSET(input_zerocopy), AV_OPT_TYPE_INT, { .i64 = CONFIG_OMX_RPI }, 0, 1, VD },
  85. + { "omx_pix_fmt", "Set the decoding pixel format for mjpeg_omx decoder. The following formats are supported: yuv420p, nv12, nv21, nv16, yuv422p, yuyv422, yvyu422, uyvy422, yuv444p.", OFFSET(pixel_format), AV_OPT_TYPE_STRING, { .str = "yuv420p" }, 0, 0, VD },
  86. +
  87. + { NULL },
  88. +};
  89. +
  90. static const AVClass omx_mpeg4dec_class = {
  91. .class_name = "mpeg4_omx",
  92. .item_name = av_default_item_name,
  93. @@ -1027,6 +1076,7 @@ AVCodec ff_hevc_omx_decoder = {
  94. static const AVClass omx_mjpegdec_class = {
  95. .class_name = "mjpeg_omx",
  96. .item_name = av_default_item_name,
  97. + .option = options_mjpeg,
  98. .version = LIBAVUTIL_VERSION_INT,
  99. };
  100. AVCodec ff_mjpeg_omx_decoder = {
  101. @@ -1040,6 +1090,6 @@ AVCodec ff_mjpeg_omx_decoder = {
  102. .close = omx_decode_end,
  103. .capabilities = AV_CODEC_CAP_DR1,
  104. .max_lowres = 3,
  105. - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
  106. + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
  107. .priv_class = &omx_mjpegdec_class,
  108. };
  109. --
  110. 2.17.1