[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 05:02:55 CEST 2011


On Fri, Aug 26, 2011 at 09:52:40PM -0400, Matthew Einhorn wrote:
> On Fri, Aug 26, 2011 at 7:00 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> > 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
> 
> I'm attaching the same patch regenerated from a clean git branch. Not
> sure why the previous one didn't work.

locally applied will be in the next git push unless something fails

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored awnser#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- 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/4bde6887/attachment.asc>


More information about the ffmpeg-devel mailing list