[FFmpeg-devel] [PATCH] Fixes avcodec_find_best_pix_fmt() with more than 64 pix fmts defined

Michael Niedermayer michaelni at gmx.at
Sat Aug 27 01:00:53 CEST 2011


On Fri, Aug 26, 2011 at 01:08:48PM -0400, Matthew Einhorn wrote:
> On Fri, Aug 26, 2011 at 12:32 PM, Matthew Einhorn <moiein2000 at gmail.com> wrote:
> > On Fri, Aug 26, 2011 at 12:10 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> >> On Sun, Aug 21, 2011 at 04:19:14PM -0400, Matthew Einhorn wrote:
> >>> On Sun, Aug 21, 2011 at 2:56 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> >> [...]
> >>> ---
> >>>  libavcodec/avcodec.h    |   34 ++++++++++++++++++++++++++++++++
> >>>  libavcodec/imgconvert.c |   49 ++++++++++++++++++++++++++++++++++------------
> >>>  2 files changed, 70 insertions(+), 13 deletions(-)
> >>>
> >>> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> >>> index 4f0ed2d..6578d5d 100644
> >>> --- a/libavcodec/avcodec.h
> >>> +++ b/libavcodec/avcodec.h
> >>> @@ -3511,6 +3511,40 @@ int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_
> >>>  enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt,
> >>>                                int has_alpha, int *loss_ptr);
> >>>
> >>> +/**
> >>> + * Find the best pixel format to convert to given a certain source pixel
> >>> + * format and a selection of two destination pixel formats. When converting from
> >>> + * one pixel format to another, information loss may occur.  For example, when converting
> >>> + * from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when
> >>> + * converting from some formats to other formats. avcodec_find_best_pix_fmt2() selects which of
> >>> + * the given pixel formats should be used to suffer the least amount of loss.
> >>> + *
> >>> + * If one of the destination formats is PIX_FMT_NONE the other pixel format (if valid) will be
> >>
> >>> + * returned. If two destination pixel formats have similar losses, the one with smallest
> >>> + * average bit depth will be chosen.
> >>
> >> It is probably better not to restrict the API this way
> >
> > How else should I chose from two fmts with identical loss? Or should I
> > return any one of them, or PIX_FMT_NONE? The old function did it this
> > way (returned the one with smallest loss). Or did you mean about
> > PIX_FMT_NONE.
> 
> Never mind,  think I understand. Remove it from the API but have the
> function still do it this way. Fixed in attached.
> >>
> >>
> >>> + *
> >>> + * @code
> >>> + * src_pix_fmt = PIX_FMT_YUV420P;
> >>> + * dst_pix_fmt1= PIX_FMT_RGB24;
> >>> + * dst_pix_fmt2= PIX_FMT_GRAY8;
> >>> + * dst_pix_fmt3= PIX_FMT_RGB8;
> >>> + * loss= FF_LOSS_CHROMA; // don't care about chroma loss, so chroma loss will be ignored.
> >>> + * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, alpha, &loss);
> >>> + * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt, dst_pix_fmt3, src_pix_fmt, alpha, &loss);
> >>> + * @endcode
> >>> + *
> >>> + * @param[in] dst_pix_fmt1 One of the two destination pixel formats to choose from
> >>> + * @param[in] dst_pix_fmt2 The other of the two destination pixel formats to choose from
> >>> + * @param[in] src_pix_fmt Source pixel format
> >>> + * @param[in] has_alpha Whether the source pixel format alpha channel is used.
> >>> + * @param[in, out] loss_ptr Combination of loss flags. In: selects which of the losses to ignore, i.e.
> >>> + *                               NULL or value of zero means we care about all losses. Out: the loss
> >>> + *                               that occurs when converting from src to selected dst pixel format.
> >>> + * @return The best pixel format to convert to or -1 if none was found.
> >>> + */
> >>> +enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2,
> >>> +                                            enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
> >>> +
> >>>  #define FF_ALPHA_TRANSP       0x0001 /* image has some totally transparent pixels */
> >>
> >> this doesnt compile
> > Sorry, forgot the semicolon. Will fix it.
> >
> > Thanks,Matt
> >
> 
> I'm also re-attaching the patch to remove the unused "find best pix
> fmt1" function from my previous email for easier access.

it seems this one doesnt apply cleanly anymore


[...]
>  avcodec.h    |   33 +++++++++++++++++++++++++++++++++
>  imgconvert.c |   49 ++++++++++++++++++++++++++++++++++++-------------
>  2 files changed, 69 insertions(+), 13 deletions(-)
> 95413805a93e6eb4da46b290a0b64eec7f140771  0001-Adds-a-new-pix-fmt-function-that-selects-the-best-de.patch
> From 7e215a4324bbfeed65a04313014d44df5c4dc29c Mon Sep 17 00:00:00 2001
> From: Matthew Einhorn <moiein2000 at gmail.com>
> Date: Fri, 26 Aug 2011 13:03:50 -0400
> Subject: [PATCH] Adds a new pix fmt function that selects the best dest fmt
>  from among 2 formats to convert to, given a certain src
>  format.
> 
> Similar to avcodec_find_best_pix_fmt(), but instead only compares two destination
> pix fmts and selects one of these fmts as the best dest format when converting from
> a given source format. Also, as opposed to avcodec_find_best_pix_fmt() which supports
> only the first 64 defined pixel formats, this supports as input any of the defined
> pixel formats.
> 
> Also replaces the old function to rely on the new function.

applied, thanks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No snowflake in an avalanche ever feels responsible. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110827/5c09693d/attachment.asc>


More information about the ffmpeg-devel mailing list