62 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
76 static inline int ff_fast_malloc(
void *ptr,
unsigned int *
size,
size_t min_size,
int zero_realloc)
81 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
132 static int initialized = 0;
134 if (initialized != 0)
148 return codec && codec->
decode;
178 #define INTERNAL_BUFFER_SIZE (32 + 1)
279 w_align =
FFMAX(w_align, 8);
282 *width =
FFALIGN(*width, w_align);
283 *height =
FFALIGN(*height, h_align);
289 for (i = 0; i < 4; i++)
301 align =
FFMAX(linesize_align[0], linesize_align[3]);
302 linesize_align[1] <<= chroma_shift;
303 linesize_align[2] <<= chroma_shift;
304 align =
FFMAX3(align, linesize_align[1], linesize_align[2]);
305 *width =
FFALIGN(*width, align);
310 int buf_size,
int align)
312 int ch, planar, needed_size, ret = 0;
317 if (buf_size < needed_size)
331 sample_fmt, align)) < 0) {
361 frame->
data[0], buf_size, 0);
370 "internal audio buffer used\n", frame);
412 int h_chroma_shift, v_chroma_shift;
439 for (i = 0; i < 4; i++)
440 unaligned |= picture.
linesize[i] % stride_align[i];
447 for (i = 0; i < 3 && picture.
data[i + 1]; i++)
448 size[i] = picture.
data[i + 1] - picture.
data[i];
449 size[i] = tmpsize - (picture.
data[i] - picture.
data[0]);
451 memset(buf->
base, 0,
sizeof(buf->
base));
452 memset(buf->
data, 0,
sizeof(buf->
data));
454 for (i = 0; i < 4 && size[i]; i++) {
455 const int h_shift = i == 0 ? 0 : h_chroma_shift;
456 const int v_shift = i == 0 ? 0 : v_chroma_shift;
463 memset(buf->
base[i], 128, size[i]);
475 if (size[1] && !size[2])
591 av_log(s,
AV_LOG_WARNING,
"Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n",
633 for (i = 0; i < count; i++) {
634 int r =
func(c, (
char *)arg + i * size);
645 for (i = 0; i < count; i++) {
646 int r =
func(c, arg, i, 0);
668 #if LIBAVCODEC_VERSION_MAJOR >= 55
675 memset(frame, 0,
sizeof(
AVFrame));
707 if (!frame || !*frame)
718 #define MAKE_ACCESSORS(str, name, type, field) \
719 type av_##name##_get_##field(const str *s) { return s->field; } \
720 void av_##name##_set_##field(str *s, type v) { s->field = v; }
737 memset(sub, 0,
sizeof(*sub));
764 #if FF_API_AVCODEC_OPEN
791 if ((!codec && !avctx->
codec)) {
795 if ((codec && avctx->
codec && codec != avctx->
codec)) {
797 "but %s passed to avcodec_open2()\n", avctx->
codec->
name, codec->
name);
801 codec = avctx->
codec;
865 avctx->
codec = codec;
885 "The %s '%s' is experimental but experimental codecs are not enabled, "
886 "add '-strict %d' if you want to use it.\n",
891 codec_string, codec2->
name);
903 av_log(avctx,
AV_LOG_WARNING,
"Warning: not compiled with thread support, using thread emulation\n");
924 av_log(avctx,
AV_LOG_ERROR,
"The maximum value for lowres supported by the decoder is %d\n",
946 av_log(avctx,
AV_LOG_ERROR,
"Specified sample format %s is invalid or not supported\n",
961 av_log(avctx,
AV_LOG_ERROR,
"Specified pixel format %s is invalid or not supported\n",
1000 "Channel layout '%s' with %d channels does not match number of specified channels %d\n",
1049 else if (channels != avctx->
channels) {
1053 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
1054 "ignoring specified channel layout\n",
1090 if (!avpkt->
data || avpkt->
size < size) {
1101 if (avpkt->
size < size) {
1172 int *got_packet_ptr)
1178 int needs_realloc = !user_pkt.
data;
1180 *got_packet_ptr = 0;
1193 "with more than %d channels, but extended_data is not set.\n",
1208 av_log(avctx,
AV_LOG_ERROR,
"more samples than frame size (avcodec_encode_audio2)\n");
1218 frame = padded_frame;
1230 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1232 if (*got_packet_ptr) {
1247 if (user_pkt.
data) {
1248 if (user_pkt.
size >= avpkt->
size) {
1265 if (needs_realloc && avpkt->
data) {
1268 avpkt->
data = new_data;
1274 if (ret < 0 || !*got_packet_ptr) {
1296 #if FF_API_OLD_ENCODE_AUDIO
1304 int ret, samples_size, got_packet;
1308 pkt.
size = buf_size;
1322 "support this codec\n");
1325 nb_samples = (int64_t)buf_size * 8 /
1328 if (nb_samples >= INT_MAX)
1341 samples_size, 1)) < 0)
1369 return ret ? ret : pkt.
size;
1374 #if FF_API_OLD_ENCODE_VIDEO
1379 int ret, got_packet = 0;
1388 pkt.
size = buf_size;
1405 return ret ? ret : pkt.
size;
1413 int *got_packet_ptr)
1417 int needs_realloc = !user_pkt.
data;
1419 *got_packet_ptr = 0;
1439 ret = avctx->
codec->
encode2(avctx, avpkt, frame, got_packet_ptr);
1444 if (user_pkt.
data) {
1445 if (user_pkt.
size >= avpkt->
size) {
1462 if (!*got_packet_ptr)
1467 if (needs_realloc && avpkt->
data &&
1471 avpkt->
data = new_data;
1477 if (ret < 0 || !*got_packet_ptr)
1509 int64_t reordered_pts, int64_t dts)
1523 pts = reordered_pts;
1540 if (!data || size < 4)
1542 flags = bytestream_get_le32(&data);
1547 avctx->
channels = bytestream_get_le32(&data);
1565 avctx->
width = bytestream_get_le32(&data);
1566 avctx->
height = bytestream_get_le32(&data);
1583 end = side_metadata +
size;
1584 while (side_metadata < end) {
1585 const uint8_t *key = side_metadata;
1586 const uint8_t *val = side_metadata + strlen(key) + 1;
1590 side_metadata = val + strlen(val) + 1;
1598 int *got_picture_ptr,
1610 *got_picture_ptr = 0;
1624 ret = avctx->
codec->
decode(avctx, picture, got_picture_ptr,
1651 if (*got_picture_ptr){
1667 #if FF_API_OLD_DECODE_AUDIO
1669 int *frame_size_ptr,
1673 int ret, got_frame = 0;
1677 "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n");
1679 "avcodec_decode_audio4()\n");
1686 if (ret >= 0 && got_frame) {
1692 if (*frame_size_ptr < data_size) {
1694 "the current frame (%d < %d)\n", *frame_size_ptr, data_size);
1700 if (planar && avctx->
channels > 1) {
1702 for (ch = 1; ch < avctx->
channels; ch++) {
1707 *frame_size_ptr = data_size;
1709 *frame_size_ptr = 0;
1721 int planar, channels;
1746 ret = avctx->
codec->
decode(avctx, frame, got_frame_ptr, &tmp);
1747 if (ret >= 0 && *got_frame_ptr) {
1765 if(side && side_size>=10) {
1810 if (*got_frame_ptr) {
1846 ret = avctx->
codec->
decode(avctx, sub, got_sub_ptr, &tmp);
1939 default :
return id;
1958 return experimental;
2016 return "unknown_codec";
2021 int i,
len, ret = 0;
2023 #define IS_PRINT(x) \
2024 (((x) >= '0' && (x) <= '9') || \
2025 ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z') || \
2026 ((x) == '.' || (x) == ' ' || (x) == '-' || (x) == '_'))
2028 for (i = 0; i < 4; i++) {
2030 IS_PRINT(codec_tag&0xFF) ?
"%c" :
"[%d]", codec_tag&0xFF);
2032 buf_size = buf_size > len ? buf_size - len : 0;
2042 const char *codec_name;
2043 const char *profile =
NULL;
2048 if (!buf || buf_size <= 0)
2062 snprintf(buf, buf_size,
"%s: %s%s", codec_type ? codec_type :
"unknown",
2064 buf[0] ^=
'a' ^
'A';
2066 snprintf(buf + strlen(buf), buf_size - strlen(buf),
" (%s)", profile);
2070 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2071 " (%s / 0x%04X)", tag_buf, enc->
codec_tag);
2077 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2082 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2086 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2094 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2095 " [SAR %d:%d DAR %d:%d]",
2097 display_aspect_ratio.
num, display_aspect_ratio.
den);
2101 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2107 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2108 ", q=%d-%d", enc->
qmin, enc->
qmax);
2113 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2119 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2128 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2131 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2136 snprintf(buf + strlen(buf), buf_size - strlen(buf),
2137 ", %d kb/s", bitrate / 1000);
2168 return FFMPEG_CONFIGURATION;
2173 #define LICENSE_PREFIX "libavcodec license: "
2201 for (j = 0; j < 4; j++) {
2297 if (be < 0 || be > 1)
2299 return map[
fmt][be];
2332 if (bps > 0 && ch > 0 && frame_bytes > 0 && ch < 32768 && bps < 32768)
2333 return (frame_bytes * 8LL) / (bps * ch);
2358 return 256 * sr / 245;
2363 return (480 << (sr / 22050)) / ch;
2371 case 20:
return 160;
2372 case 19:
return 144;
2373 case 29:
return 288;
2374 case 37:
return 480;
2378 case 38:
return 160;
2379 case 50:
return 240;
2384 if (frame_bytes > 0) {
2387 return 240 * (frame_bytes / 32);
2389 return 256 * (frame_bytes / 64);
2391 return 160 * (frame_bytes / 20);
2393 return 240 * (frame_bytes / 24);
2398 return frame_bytes * 8 /
bps;
2405 return frame_bytes / (9 * ch) * 16;
2408 return (frame_bytes - 4 * ch) * 2 / ch;
2410 return (frame_bytes - 4) * 2 / ch;
2412 return (frame_bytes - 8) * 2 / ch;
2414 return (frame_bytes / 128) * 224 / ch;
2416 return (frame_bytes - 6 - ch) / ch;
2418 return (frame_bytes - 8) / ch;
2420 return (frame_bytes - 2 * ch) / ch;
2422 return 3 * frame_bytes / ch;
2424 return 6 * frame_bytes / ch;
2426 return 2 * (frame_bytes / (5 * ch));
2429 return 4 * frame_bytes / ch;
2436 return frame_bytes / ch;
2438 return frame_bytes * 2 / ch;
2444 int blocks = frame_bytes / ba;
2447 return blocks * (1 + (ba - 4 * ch) / (4 * ch) * 8);
2449 return blocks * (((ba - 16) * 2 / 3 * 4) / ch);
2451 return blocks * (1 + (ba - 4 * ch) * 2 / ch);
2453 return blocks * (2 + (ba - 7 * ch) * 2 / ch);
2463 return 2 * (frame_bytes / ((bps * 2 / 8) * ch));
2467 return frame_bytes / ((
FFALIGN(ch, 2) *
bps) / 8);
2469 return 2 * (frame_bytes / ((bps + 4) / 4)) / ch;
2503 for (i = 0; i < size && !(
tab[i][0] == a &&
tab[i][1] ==
b); i++) ;
2510 "version to the newest one from Git. If the problem still "
2511 "occurs, it means that your file has a feature which has not "
2512 "been implemented.\n", feature);
2519 va_list argument_list;
2521 va_start(argument_list, msg);
2526 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
2527 "and contact the ffmpeg-devel mailing list.\n");
2529 va_end(argument_list);
2553 if (hwaccel->
id == codec_id
2554 && hwaccel->
pix_fmt == pix_fmt)
2587 av_log(log_ctx,
AV_LOG_ERROR,
"Insufficient thread locking around avcodec_open/close()\n");
2629 return toupper(x & 0xFF)
2630 + (toupper((x >> 8) & 0xFF) << 8)
2631 + (toupper((x >> 16) & 0xFF) << 16)
2632 + (toupper((x >> 24) & 0xFF) << 24);