/* * utils for libavcodec * Copyright (c) 2001 Fabrice Bellard * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
data = (enum AVMatrixEncoding*)side_data->data;
*data = matrix_encoding;
return 0;
}
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[AV_NUM_DATA_POINTERS])
{ int i; int w_align = 1; int h_align = 1;
AVPixFmtDescriptor const *desc = av_pix_fmt_desc_get(s->pix_fmt);
switch (s->pix_fmt) { case AV_PIX_FMT_YUV420P: case AV_PIX_FMT_YUYV422: case AV_PIX_FMT_YVYU422: case AV_PIX_FMT_UYVY422: case AV_PIX_FMT_YUV422P: case AV_PIX_FMT_YUV440P: case AV_PIX_FMT_YUV444P: case AV_PIX_FMT_GBRP: case AV_PIX_FMT_GBRAP: case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_GRAY16BE: case AV_PIX_FMT_GRAY16LE: case AV_PIX_FMT_YUVJ420P: case AV_PIX_FMT_YUVJ422P: case AV_PIX_FMT_YUVJ440P: case AV_PIX_FMT_YUVJ444P: case AV_PIX_FMT_YUVA420P: case AV_PIX_FMT_YUVA422P: case AV_PIX_FMT_YUVA444P: case AV_PIX_FMT_YUV420P9LE: case AV_PIX_FMT_YUV420P9BE: case AV_PIX_FMT_YUV420P10LE: case AV_PIX_FMT_YUV420P10BE: case AV_PIX_FMT_YUV420P12LE: case AV_PIX_FMT_YUV420P12BE: case AV_PIX_FMT_YUV420P14LE: case AV_PIX_FMT_YUV420P14BE: case AV_PIX_FMT_YUV420P16LE: case AV_PIX_FMT_YUV420P16BE: case AV_PIX_FMT_YUVA420P9LE: case AV_PIX_FMT_YUVA420P9BE: case AV_PIX_FMT_YUVA420P10LE: case AV_PIX_FMT_YUVA420P10BE: case AV_PIX_FMT_YUVA420P16LE: case AV_PIX_FMT_YUVA420P16BE: case AV_PIX_FMT_YUV422P9LE: case AV_PIX_FMT_YUV422P9BE: case AV_PIX_FMT_YUV422P10LE: case AV_PIX_FMT_YUV422P10BE: case AV_PIX_FMT_YUV422P12LE: case AV_PIX_FMT_YUV422P12BE: case AV_PIX_FMT_YUV422P14LE: case AV_PIX_FMT_YUV422P14BE: case AV_PIX_FMT_YUV422P16LE: case AV_PIX_FMT_YUV422P16BE: case AV_PIX_FMT_YUVA422P9LE: case AV_PIX_FMT_YUVA422P9BE: case AV_PIX_FMT_YUVA422P10LE: case AV_PIX_FMT_YUVA422P10BE: case AV_PIX_FMT_YUVA422P12LE: case AV_PIX_FMT_YUVA422P12BE: case AV_PIX_FMT_YUVA422P16LE: case AV_PIX_FMT_YUVA422P16BE: case AV_PIX_FMT_YUV440P10LE: case AV_PIX_FMT_YUV440P10BE: case AV_PIX_FMT_YUV440P12LE: case AV_PIX_FMT_YUV440P12BE: case AV_PIX_FMT_YUV444P9LE: case AV_PIX_FMT_YUV444P9BE: case AV_PIX_FMT_YUV444P10LE: case AV_PIX_FMT_YUV444P10BE: case AV_PIX_FMT_YUV444P12LE: case AV_PIX_FMT_YUV444P12BE: case AV_PIX_FMT_YUV444P14LE: case AV_PIX_FMT_YUV444P14BE: case AV_PIX_FMT_YUV444P16LE: case AV_PIX_FMT_YUV444P16BE: case AV_PIX_FMT_YUVA444P9LE: case AV_PIX_FMT_YUVA444P9BE: case AV_PIX_FMT_YUVA444P10LE: case AV_PIX_FMT_YUVA444P10BE: case AV_PIX_FMT_YUVA444P12LE: case AV_PIX_FMT_YUVA444P12BE: case AV_PIX_FMT_YUVA444P16LE: case AV_PIX_FMT_YUVA444P16BE: case AV_PIX_FMT_GBRP9LE: case AV_PIX_FMT_GBRP9BE: case AV_PIX_FMT_GBRP10LE: case AV_PIX_FMT_GBRP10BE: case AV_PIX_FMT_GBRP12LE: case AV_PIX_FMT_GBRP12BE: case AV_PIX_FMT_GBRP14LE: case AV_PIX_FMT_GBRP14BE: case AV_PIX_FMT_GBRP16LE: case AV_PIX_FMT_GBRP16BE: case AV_PIX_FMT_GBRAP12LE: case AV_PIX_FMT_GBRAP12BE: case AV_PIX_FMT_GBRAP16LE: case AV_PIX_FMT_GBRAP16BE:
w_align = 16; //FIXME assume 16 pixel per macroblock
h_align = 16 * 2; // interlaced needs 2 macroblocks height if (s->codec_id == AV_CODEC_ID_BINKVIDEO)
w_align = 16*2; break; case AV_PIX_FMT_YUV411P: case AV_PIX_FMT_YUVJ411P: case AV_PIX_FMT_UYYVYY411:
w_align = 32;
h_align = 16 * 2; break; case AV_PIX_FMT_YUV410P: if (s->codec_id == AV_CODEC_ID_SVQ1) {
w_align = 64;
h_align = 64;
} elseif (s->codec_id == AV_CODEC_ID_SNOW) {
w_align = 16;
h_align = 16;
} break; case AV_PIX_FMT_RGB555: if (s->codec_id == AV_CODEC_ID_RPZA) {
w_align = 4;
h_align = 4;
} if (s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
w_align = 8;
h_align = 8;
} break; case AV_PIX_FMT_PAL8: case AV_PIX_FMT_BGR8: case AV_PIX_FMT_RGB8: if (s->codec_id == AV_CODEC_ID_SMC ||
s->codec_id == AV_CODEC_ID_CINEPAK) {
w_align = 4;
h_align = 4;
} if (s->codec_id == AV_CODEC_ID_JV ||
s->codec_id == AV_CODEC_ID_ARGO ||
s->codec_id == AV_CODEC_ID_INTERPLAY_VIDEO) {
w_align = 8;
h_align = 8;
} if (s->codec_id == AV_CODEC_ID_MJPEG ||
s->codec_id == AV_CODEC_ID_MJPEGB ||
s->codec_id == AV_CODEC_ID_LJPEG ||
s->codec_id == AV_CODEC_ID_SMVJPEG ||
s->codec_id == AV_CODEC_ID_AMV ||
s->codec_id == AV_CODEC_ID_SP5X ||
s->codec_id == AV_CODEC_ID_JPEGLS) {
w_align = 8;
h_align = 2*8;
} break; case AV_PIX_FMT_BGR24: if ((s->codec_id == AV_CODEC_ID_MSZH) ||
(s->codec_id == AV_CODEC_ID_ZLIB)) {
w_align = 4;
h_align = 4;
} break; case AV_PIX_FMT_RGB24: if (s->codec_id == AV_CODEC_ID_CINEPAK) {
w_align = 4;
h_align = 4;
} break; case AV_PIX_FMT_BGR0: if (s->codec_id == AV_CODEC_ID_ARGO) {
w_align = 8;
h_align = 8;
} break; default: break;
}
if (s->codec_id == AV_CODEC_ID_IFF_ILBM) {
w_align = FFMAX(w_align, 16);
}
*width = FFALIGN(*width, w_align);
*height = FFALIGN(*height, h_align); if (s->codec_id == AV_CODEC_ID_H264 || s->lowres ||
s->codec_id == AV_CODEC_ID_VC1 || s->codec_id == AV_CODEC_ID_WMV3 ||
s->codec_id == AV_CODEC_ID_VP5 || s->codec_id == AV_CODEC_ID_VP6 ||
s->codec_id == AV_CODEC_ID_VP6F || s->codec_id == AV_CODEC_ID_VP6A
) { // some of the optimized chroma MC reads one line too much // which is also done in mpeg decoders with lowres > 0
*height += 2;
// H.264 uses edge emulation for out of frame motion vectors, for this // it requires a temporary area large enough to hold a 21x21 block, // increasing witdth ensure that the temporary area is large enough, // the next rounded up width is 32
*width = FFMAX(*width, 32);
} if (s->codec_id == AV_CODEC_ID_SVQ3) {
*width = FFMAX(*width, 32);
}
for (i = 0; i < 4; i++)
linesize_align[i] = STRIDE_ALIGN;
}
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height)
{ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt); int chroma_shift = desc->log2_chroma_w; int linesize_align[AV_NUM_DATA_POINTERS]; int align;
int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, enum AVSampleFormat sample_fmt, const uint8_t *buf, int buf_size, int align)
{ int ch, planar, needed_size, ret = 0;
if (id == AV_CODEC_ID_NONE) return"none";
cd = avcodec_descriptor_get(id); if (cd) return cd->name;
av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id);
codec = avcodec_find_decoder(id); if (codec) return codec->name;
codec = avcodec_find_encoder(id); if (codec) return codec->name; return"unknown_codec";
}
constchar *av_get_profile_name(const AVCodec *codec, int profile)
{ const AVProfile *p; if (profile == AV_PROFILE_UNKNOWN || !codec->profiles) return NULL;
for (p = codec->profiles; p->profile != AV_PROFILE_UNKNOWN; p++) if (p->profile == profile) return p->name;
if (profile == AV_PROFILE_UNKNOWN || !desc || !desc->profiles) return NULL;
for (p = desc->profiles; p->profile != AV_PROFILE_UNKNOWN; p++) if (p->profile == profile) return p->name;
return NULL;
}
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
{ switch (codec_id) { case AV_CODEC_ID_DFPWM: return 1; case AV_CODEC_ID_8SVX_EXP: case AV_CODEC_ID_8SVX_FIB: case AV_CODEC_ID_ADPCM_ARGO: case AV_CODEC_ID_ADPCM_CT: case AV_CODEC_ID_ADPCM_IMA_ALP: case AV_CODEC_ID_ADPCM_IMA_AMV: case AV_CODEC_ID_ADPCM_IMA_APC: case AV_CODEC_ID_ADPCM_IMA_APM: case AV_CODEC_ID_ADPCM_IMA_EA_SEAD: case AV_CODEC_ID_ADPCM_IMA_OKI: case AV_CODEC_ID_ADPCM_IMA_WS: case AV_CODEC_ID_ADPCM_IMA_SSI: case AV_CODEC_ID_ADPCM_G722: case AV_CODEC_ID_ADPCM_YAMAHA: case AV_CODEC_ID_ADPCM_AICA: return 4; case AV_CODEC_ID_DSD_LSBF: case AV_CODEC_ID_DSD_MSBF: case AV_CODEC_ID_DSD_LSBF_PLANAR: case AV_CODEC_ID_DSD_MSBF_PLANAR: case AV_CODEC_ID_PCM_ALAW: case AV_CODEC_ID_PCM_MULAW: case AV_CODEC_ID_PCM_VIDC: case AV_CODEC_ID_PCM_S8: case AV_CODEC_ID_PCM_S8_PLANAR: case AV_CODEC_ID_PCM_SGA: case AV_CODEC_ID_PCM_U8: case AV_CODEC_ID_SDX2_DPCM: case AV_CODEC_ID_CBD2_DPCM: case AV_CODEC_ID_DERF_DPCM: case AV_CODEC_ID_WADY_DPCM: return 8; case AV_CODEC_ID_PCM_S16BE: case AV_CODEC_ID_PCM_S16BE_PLANAR: case AV_CODEC_ID_PCM_S16LE: case AV_CODEC_ID_PCM_S16LE_PLANAR: case AV_CODEC_ID_PCM_U16BE: case AV_CODEC_ID_PCM_U16LE: return 16; case AV_CODEC_ID_PCM_S24DAUD: case AV_CODEC_ID_PCM_S24BE: case AV_CODEC_ID_PCM_S24LE: case AV_CODEC_ID_PCM_S24LE_PLANAR: case AV_CODEC_ID_PCM_U24BE: case AV_CODEC_ID_PCM_U24LE: return 24; case AV_CODEC_ID_PCM_S32BE: case AV_CODEC_ID_PCM_S32LE: case AV_CODEC_ID_PCM_S32LE_PLANAR: case AV_CODEC_ID_PCM_U32BE: case AV_CODEC_ID_PCM_U32LE: case AV_CODEC_ID_PCM_F32BE: case AV_CODEC_ID_PCM_F32LE: case AV_CODEC_ID_PCM_F24LE: case AV_CODEC_ID_PCM_F16LE: return 32; case AV_CODEC_ID_PCM_F64BE: case AV_CODEC_ID_PCM_F64LE: case AV_CODEC_ID_PCM_S64BE: case AV_CODEC_ID_PCM_S64LE: return 64; default: return 0;
}
}
int av_get_bits_per_sample(enum AVCodecID codec_id)
{ switch (codec_id) { case AV_CODEC_ID_DFPWM: return 1; case AV_CODEC_ID_ADPCM_SBPRO_2: return 2; case AV_CODEC_ID_ADPCM_SBPRO_3: return 3; case AV_CODEC_ID_ADPCM_SBPRO_4: case AV_CODEC_ID_ADPCM_IMA_WAV: case AV_CODEC_ID_ADPCM_IMA_XBOX: case AV_CODEC_ID_ADPCM_IMA_QT: case AV_CODEC_ID_ADPCM_SWF: case AV_CODEC_ID_ADPCM_MS: return 4; default: return av_get_exact_bits_per_sample(codec_id);
}
}
staticint get_audio_frame_duration(enum AVCodecID id, int sr, int ch, int ba,
uint32_t tag, int bits_per_coded_sample, int64_t bitrate,
uint8_t * extradata, int frame_size, int frame_bytes)
{ int bps = av_get_exact_bits_per_sample(id); int framecount = (ba > 0 && frame_bytes / ba > 0) ? frame_bytes / ba : 1;
/* codecs with a fixed packet duration */ switch (id) { case AV_CODEC_ID_ADPCM_ADX: return 32; case AV_CODEC_ID_ADPCM_IMA_QT: return 64; case AV_CODEC_ID_ADPCM_EA_XAS: return 128; case AV_CODEC_ID_AMR_NB: case AV_CODEC_ID_EVRC: case AV_CODEC_ID_GSM: case AV_CODEC_ID_QCELP: case AV_CODEC_ID_RA_288: return 160; case AV_CODEC_ID_AMR_WB: case AV_CODEC_ID_GSM_MS: return 320; case AV_CODEC_ID_MP1: return 384; case AV_CODEC_ID_ATRAC1: return 512; case AV_CODEC_ID_ATRAC9: case AV_CODEC_ID_ATRAC3: if (framecount > INT_MAX/1024) return 0; return 1024 * framecount; case AV_CODEC_ID_ATRAC3P: return 2048; case AV_CODEC_ID_MP2: case AV_CODEC_ID_MUSEPACK7: return 1152; case AV_CODEC_ID_AC3: return 1536; case AV_CODEC_ID_FTR: return 1024;
}
if (sr > 0) { /* calc from sample rate */ if (id == AV_CODEC_ID_TTA) return 256ll * sr / 245; elseif (id == AV_CODEC_ID_DST) return 588ll * sr / 44100; elseif (id == AV_CODEC_ID_BINKAUDIO_DCT) { if (sr / 22050 > 22) return 0; return (480 << (sr / 22050));
}
if (id == AV_CODEC_ID_MP3) return sr <= 24000 ? 576 : 1152;
}
if (ba > 0) { /* calc from block_align */ if (id == AV_CODEC_ID_SIPR) { switch (ba) { case 20: return 160; case 19: return 144; case 29: return 288; case 37: return 480;
}
} elseif (id == AV_CODEC_ID_ILBC) { switch (ba) { case 38: return 160; case 50: return 240;
}
}
}
if (frame_bytes > 0) { /* calc from frame_bytes only */ if (id == AV_CODEC_ID_TRUESPEECH) return 240 * (frame_bytes / 32); if (id == AV_CODEC_ID_NELLYMOSER) return 256 * (frame_bytes / 64); if (id == AV_CODEC_ID_RA_144) return 160 * (frame_bytes / 20); if (id == AV_CODEC_ID_APTX) return 4 * (frame_bytes / 4); if (id == AV_CODEC_ID_APTX_HD) return 4 * (frame_bytes / 6);
if (bps > 0) { /* calc from frame_bytes and bits_per_coded_sample */ if (id == AV_CODEC_ID_ADPCM_G726 || id == AV_CODEC_ID_ADPCM_G726LE) return frame_bytes * 8 / bps;
}
if (ch > 0 && ch < INT_MAX/16) { /* calc from frame_bytes and channels */ switch (id) { case AV_CODEC_ID_FASTAUDIO: return frame_bytes / (40 * ch) * 256; case AV_CODEC_ID_ADPCM_IMA_MOFLEX: return (frame_bytes - 4 * ch) / (128 * ch) * 256; case AV_CODEC_ID_ADPCM_AFC: return frame_bytes / (9 * ch) * 16; case AV_CODEC_ID_ADPCM_PSX: case AV_CODEC_ID_ADPCM_DTK:
frame_bytes /= 16 * ch; if (frame_bytes > INT_MAX / 28) return 0; return frame_bytes * 28; case AV_CODEC_ID_ADPCM_4XM: case AV_CODEC_ID_ADPCM_IMA_ACORN: case AV_CODEC_ID_ADPCM_IMA_DAT4: case AV_CODEC_ID_ADPCM_IMA_ISS: return (frame_bytes - 4 * ch) * 2 / ch; case AV_CODEC_ID_ADPCM_IMA_SMJPEG: return (frame_bytes - 4) * 2 / ch; case AV_CODEC_ID_ADPCM_IMA_AMV: return (frame_bytes - 8) * 2; case AV_CODEC_ID_ADPCM_THP: case AV_CODEC_ID_ADPCM_THP_LE: if (extradata) return frame_bytes * 14LL / (8 * ch); break; case AV_CODEC_ID_ADPCM_XA: return (frame_bytes / 128) * 224 / ch; case AV_CODEC_ID_INTERPLAY_DPCM: return (frame_bytes - 6 - ch) / ch; case AV_CODEC_ID_ROQ_DPCM: return (frame_bytes - 8) / ch; case AV_CODEC_ID_XAN_DPCM: return (frame_bytes - 2 * ch) / ch; case AV_CODEC_ID_MACE3: return 3 * frame_bytes / ch; case AV_CODEC_ID_MACE6: return 6 * frame_bytes / ch; case AV_CODEC_ID_PCM_LXF: return 2 * (frame_bytes / (5 * ch)); case AV_CODEC_ID_IAC: case AV_CODEC_ID_IMC: return 4 * frame_bytes / ch;
}
if (tag) { /* calc from frame_bytes, channels, and codec_tag */ if (id == AV_CODEC_ID_SOL_DPCM) { if (tag == 3) return frame_bytes / ch; else return frame_bytes * 2 / ch;
}
}
/* Fall back on using frame_size */ if (frame_size > 1 && frame_bytes) return frame_size;
//For WMA we currently have no other means to calculate duration thus we //do it here by assuming CBR, which is true for all known cases. if (bitrate > 0 && frame_bytes > 0 && sr > 0 && ba > 1) { if (id == AV_CODEC_ID_WMAV1 || id == AV_CODEC_ID_WMAV2) return (frame_bytes * 8LL * sr) / bitrate;
}
return 0;
}
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
{ int channels = avctx->ch_layout.nb_channels; int duration;
unsignedint av_xiphlacing(unsignedchar *s, unsignedint v)
{ unsignedint n = 0;
while (v >= 0xff) {
*s++ = 0xff;
v -= 0xff;
n++;
}
*s = v;
n++; return n;
}
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
{ int i; for (i = 0; i < size && !(tab[i][0] == a && tab[i][1] == b); i++) ; return i;
}
const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *avcodec, int index)
{ const FFCodec *const codec = ffcodec(avcodec); int i; if (!codec->hw_configs || index < 0) return NULL; for (i = 0; i <= index; i++) if (!codec->hw_configs[i]) return NULL; return &codec->hw_configs[index]->public;
}
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
{ int ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.