MCPcopy Create free account
hub / github.com/HandBrake/HandBrake / hb_ff_set_sample_fmt

Function hb_ff_set_sample_fmt

libhb/hbffmpeg.c:750–793  ·  view source on GitHub ↗

* Set sample format to the request format if supported by the codec. * The planar/packed variant of the requested format is the next best thing. */

Source from the content-addressed store, hash-verified

748 * The planar/packed variant of the requested format is the next best thing.
749 */
750void hb_ff_set_sample_fmt(AVCodecContext *context, const AVCodec *codec,
751 enum AVSampleFormat request_sample_fmt)
752{
753 if (context != NULL && codec != NULL && codec->type == AVMEDIA_TYPE_AUDIO)
754 {
755 const enum AVSampleFormat *sample_fmts = NULL;
756 if (avcodec_get_supported_config(context, NULL,
757 AV_CODEC_CONFIG_SAMPLE_FORMAT,
758 0, (const void **)&sample_fmts, NULL) == 0 && sample_fmts != NULL)
759 {
760 const enum AVSampleFormat *fmt;
761 enum AVSampleFormat next_best_fmt;
762
763 next_best_fmt = (av_sample_fmt_is_planar(request_sample_fmt) ?
764 av_get_packed_sample_fmt(request_sample_fmt) :
765 av_get_planar_sample_fmt(request_sample_fmt));
766
767 context->request_sample_fmt = AV_SAMPLE_FMT_NONE;
768
769 for (fmt = sample_fmts; *fmt != AV_SAMPLE_FMT_NONE; fmt++)
770 {
771 if (*fmt == request_sample_fmt)
772 {
773 context->request_sample_fmt = request_sample_fmt;
774 break;
775 }
776 else if (*fmt == next_best_fmt)
777 {
778 context->request_sample_fmt = next_best_fmt;
779 }
780 }
781
782 /*
783 * When encoding and AVCodec.sample_fmts exists, avcodec_open2()
784 * will error out if AVCodecContext.sample_fmt isn't set.
785 */
786 if (context->request_sample_fmt == AV_SAMPLE_FMT_NONE)
787 {
788 context->request_sample_fmt = sample_fmts[0];
789 }
790 context->sample_fmt = context->request_sample_fmt;
791 }
792 }
793}
794
795int hb_av_can_use_zscale(enum AVPixelFormat pix_fmt,
796 int in_width, int in_height,

Callers 3

encavcodecaInitFunction · 0.85
decavcodecaInitFunction · 0.85
decavcodecaBSInfoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected