2 * AVCodecContext functions for libavcodec
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * AVCodecContext functions for libavcodec
27 #include "libavutil/avassert.h"
28 #include "libavutil/avstring.h"
29 #include "libavutil/bprint.h"
30 #include "libavutil/channel_layout.h"
31 #include "libavutil/fifo.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/mem.h"
34 #include "libavutil/opt.h"
35 #include "libavutil/thread.h"
38 #include "codec_internal.h"
41 #include "frame_thread_encoder.h"
45 int avcodec_default_execute(AVCodecContext
*c
, int (*func
)(AVCodecContext
*c2
, void *arg2
), void *arg
, int *ret
, int count
, int size
)
49 for (i
= 0; i
< count
; i
++) {
50 int r
= func(c
, (char *)arg
+ i
* size
);
58 int avcodec_default_execute2(AVCodecContext
*c
, int (*func
)(AVCodecContext
*c2
, void *arg2
, int jobnr
, int threadnr
), void *arg
, int *ret
, int count
)
62 for (i
= 0; i
< count
; i
++) {
63 int r
= func(c
, arg
, i
, 0);
71 static AVMutex codec_mutex
= AV_MUTEX_INITIALIZER
;
73 static void lock_avcodec(const FFCodec
*codec
)
75 if (!(codec
->caps_internal
& FF_CODEC_CAP_INIT_THREADSAFE
) && codec
->init
)
76 ff_mutex_lock(&codec_mutex
);
79 static void unlock_avcodec(const FFCodec
*codec
)
81 if (!(codec
->caps_internal
& FF_CODEC_CAP_INIT_THREADSAFE
) && codec
->init
)
82 ff_mutex_unlock(&codec_mutex
);
85 static int64_t get_bit_rate(AVCodecContext
*ctx
)
90 switch (ctx
->codec_type
) {
91 case AVMEDIA_TYPE_VIDEO
:
92 case AVMEDIA_TYPE_DATA
:
93 case AVMEDIA_TYPE_SUBTITLE
:
94 case AVMEDIA_TYPE_ATTACHMENT
:
95 bit_rate
= ctx
->bit_rate
;
97 case AVMEDIA_TYPE_AUDIO
:
98 bits_per_sample
= av_get_bits_per_sample(ctx
->codec_id
);
99 if (bits_per_sample
) {
100 bit_rate
= ctx
->sample_rate
* (int64_t)ctx
->ch_layout
.nb_channels
;
101 if (bit_rate
> INT64_MAX
/ bits_per_sample
) {
104 bit_rate
*= bits_per_sample
;
106 bit_rate
= ctx
->bit_rate
;
115 int attribute_align_arg
avcodec_open2(AVCodecContext
*avctx
, const AVCodec
*codec
, AVDictionary
**options
)
118 AVCodecInternal
*avci
;
119 const FFCodec
*codec2
;
121 if (avcodec_is_open(avctx
))
124 if (!codec
&& !avctx
->codec
) {
125 av_log(avctx
, AV_LOG_ERROR
, "No codec provided to avcodec_open2()\n");
126 return AVERROR(EINVAL
);
128 if (codec
&& avctx
->codec
&& codec
!= avctx
->codec
) {
129 av_log(avctx
, AV_LOG_ERROR
, "This AVCodecContext was allocated for %s, "
130 "but %s passed to avcodec_open2()\n", avctx
->codec
->name
, codec
->name
);
131 return AVERROR(EINVAL
);
134 codec
= avctx
->codec
;
135 codec2
= ffcodec(codec
);
137 if ((avctx
->codec_type
!= AVMEDIA_TYPE_UNKNOWN
&& avctx
->codec_type
!= codec
->type
) ||
138 (avctx
->codec_id
!= AV_CODEC_ID_NONE
&& avctx
->codec_id
!= codec
->id
)) {
139 av_log(avctx
, AV_LOG_ERROR
, "Codec type or id mismatches\n");
140 return AVERROR(EINVAL
);
143 avctx
->codec_type
= codec
->type
;
144 avctx
->codec_id
= codec
->id
;
145 avctx
->codec
= codec
;
147 if (avctx
->extradata_size
< 0 || avctx
->extradata_size
>= FF_MAX_EXTRADATA_SIZE
)
148 return AVERROR(EINVAL
);
150 avci
= av_mallocz(sizeof(*avci
));
152 ret
= AVERROR(ENOMEM
);
155 avctx
->internal
= avci
;
157 avci
->buffer_frame
= av_frame_alloc();
158 avci
->buffer_pkt
= av_packet_alloc();
159 if (!avci
->buffer_frame
|| !avci
->buffer_pkt
) {
160 ret
= AVERROR(ENOMEM
);
164 avci
->skip_samples_multiplier
= 1;
166 if (codec2
->priv_data_size
> 0) {
167 if (!avctx
->priv_data
) {
168 avctx
->priv_data
= av_mallocz(codec2
->priv_data_size
);
169 if (!avctx
->priv_data
) {
170 ret
= AVERROR(ENOMEM
);
173 if (codec
->priv_class
) {
174 *(const AVClass
**)avctx
->priv_data
= codec
->priv_class
;
175 av_opt_set_defaults(avctx
->priv_data
);
178 if (codec
->priv_class
&& (ret
= av_opt_set_dict(avctx
->priv_data
, options
)) < 0)
181 avctx
->priv_data
= NULL
;
183 if ((ret
= av_opt_set_dict(avctx
, options
)) < 0)
186 if (avctx
->codec_whitelist
&& av_match_list(codec
->name
, avctx
->codec_whitelist
, ',') <= 0) {
187 av_log(avctx
, AV_LOG_ERROR
, "Codec (%s) not on whitelist \'%s\'\n", codec
->name
, avctx
->codec_whitelist
);
188 ret
= AVERROR(EINVAL
);
192 // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
193 if (!(avctx
->coded_width
&& avctx
->coded_height
&& avctx
->width
&& avctx
->height
&&
194 (avctx
->codec_id
== AV_CODEC_ID_H264
|| avctx
->codec_id
== AV_CODEC_ID_VP6F
|| avctx
->codec_id
== AV_CODEC_ID_DXV
))) {
195 if (avctx
->coded_width
&& avctx
->coded_height
)
196 ret
= ff_set_dimensions(avctx
, avctx
->coded_width
, avctx
->coded_height
);
197 else if (avctx
->width
&& avctx
->height
)
198 ret
= ff_set_dimensions(avctx
, avctx
->width
, avctx
->height
);
203 if ((avctx
->coded_width
|| avctx
->coded_height
|| avctx
->width
|| avctx
->height
)
204 && ( av_image_check_size2(avctx
->coded_width
, avctx
->coded_height
, avctx
->max_pixels
, AV_PIX_FMT_NONE
, 0, avctx
) < 0
205 || av_image_check_size2(avctx
->width
, avctx
->height
, avctx
->max_pixels
, AV_PIX_FMT_NONE
, 0, avctx
) < 0)) {
206 av_log(avctx
, AV_LOG_WARNING
, "Ignoring invalid width/height values\n");
207 ff_set_dimensions(avctx
, 0, 0);
210 if (avctx
->width
> 0 && avctx
->height
> 0) {
211 if (av_image_check_sar(avctx
->width
, avctx
->height
,
212 avctx
->sample_aspect_ratio
) < 0) {
213 av_log(avctx
, AV_LOG_WARNING
, "ignoring invalid SAR: %u/%u\n",
214 avctx
->sample_aspect_ratio
.num
,
215 avctx
->sample_aspect_ratio
.den
);
216 avctx
->sample_aspect_ratio
= (AVRational
){ 0, 1 };
220 if (avctx
->sample_rate
< 0) {
221 av_log(avctx
, AV_LOG_ERROR
, "Invalid sample rate: %d\n", avctx
->sample_rate
);
222 ret
= AVERROR(EINVAL
);
225 if (avctx
->block_align
< 0) {
226 av_log(avctx
, AV_LOG_ERROR
, "Invalid block align: %d\n", avctx
->block_align
);
227 ret
= AVERROR(EINVAL
);
231 #if FF_API_OLD_CHANNEL_LAYOUT
232 FF_DISABLE_DEPRECATION_WARNINGS
233 /* compat wrapper for old-style callers */
234 if (avctx
->channel_layout
&& !avctx
->channels
)
235 avctx
->channels
= av_popcount64(avctx
->channel_layout
);
237 if ((avctx
->channels
> 0 && avctx
->ch_layout
.nb_channels
!= avctx
->channels
) ||
238 (avctx
->channel_layout
&& (avctx
->ch_layout
.order
!= AV_CHANNEL_ORDER_NATIVE
||
239 avctx
->ch_layout
.u
.mask
!= avctx
->channel_layout
))) {
240 if (avctx
->channel_layout
) {
241 av_channel_layout_from_mask(&avctx
->ch_layout
, avctx
->channel_layout
);
243 avctx
->ch_layout
.order
= AV_CHANNEL_ORDER_UNSPEC
;
244 avctx
->ch_layout
.nb_channels
= avctx
->channels
;
247 FF_ENABLE_DEPRECATION_WARNINGS
250 if (avctx
->ch_layout
.nb_channels
> FF_SANE_NB_CHANNELS
) {
251 av_log(avctx
, AV_LOG_ERROR
, "Too many channels: %d\n", avctx
->ch_layout
.nb_channels
);
252 ret
= AVERROR(EINVAL
);
256 avctx
->frame_number
= 0;
257 avctx
->codec_descriptor
= avcodec_descriptor_get(avctx
->codec_id
);
259 if ((avctx
->codec
->capabilities
& AV_CODEC_CAP_EXPERIMENTAL
) &&
260 avctx
->strict_std_compliance
> FF_COMPLIANCE_EXPERIMENTAL
) {
261 const char *codec_string
= av_codec_is_encoder(codec
) ? "encoder" : "decoder";
262 const AVCodec
*codec2
;
263 av_log(avctx
, AV_LOG_ERROR
,
264 "The %s '%s' is experimental but experimental codecs are not enabled, "
265 "add '-strict %d' if you want to use it.\n",
266 codec_string
, codec
->name
, FF_COMPLIANCE_EXPERIMENTAL
);
267 codec2
= av_codec_is_encoder(codec
) ? avcodec_find_encoder(codec
->id
) : avcodec_find_decoder(codec
->id
);
268 if (!(codec2
->capabilities
& AV_CODEC_CAP_EXPERIMENTAL
))
269 av_log(avctx
, AV_LOG_ERROR
, "Alternatively use the non experimental %s '%s'.\n",
270 codec_string
, codec2
->name
);
271 ret
= AVERROR_EXPERIMENTAL
;
275 if (avctx
->codec_type
== AVMEDIA_TYPE_AUDIO
&&
276 (!avctx
->time_base
.num
|| !avctx
->time_base
.den
)) {
277 avctx
->time_base
.num
= 1;
278 avctx
->time_base
.den
= avctx
->sample_rate
;
281 if (av_codec_is_encoder(avctx
->codec
))
282 ret
= ff_encode_preinit(avctx
);
284 ret
= ff_decode_preinit(avctx
);
288 if (CONFIG_FRAME_THREAD_ENCODER
&& av_codec_is_encoder(avctx
->codec
)) {
289 ret
= ff_frame_thread_encoder_init(avctx
);
295 && !(avci
->frame_thread_encoder
&& (avctx
->active_thread_type
&FF_THREAD_FRAME
))) {
296 /* Frame-threaded decoders call FFCodec.init for their child contexts. */
297 lock_avcodec(codec2
);
298 ret
= ff_thread_init(avctx
);
299 unlock_avcodec(codec2
);
304 if (!HAVE_THREADS
&& !(codec2
->caps_internal
& FF_CODEC_CAP_AUTO_THREADS
))
305 avctx
->thread_count
= 1;
307 if (!(avctx
->active_thread_type
& FF_THREAD_FRAME
) ||
308 avci
->frame_thread_encoder
) {
310 lock_avcodec(codec2
);
311 ret
= codec2
->init(avctx
);
312 unlock_avcodec(codec2
);
314 avci
->needs_close
= codec2
->caps_internal
& FF_CODEC_CAP_INIT_CLEANUP
;
318 avci
->needs_close
= 1;
323 if (av_codec_is_decoder(avctx
->codec
)) {
324 if (!avctx
->bit_rate
)
325 avctx
->bit_rate
= get_bit_rate(avctx
);
327 #if FF_API_OLD_CHANNEL_LAYOUT
328 FF_DISABLE_DEPRECATION_WARNINGS
329 /* update the deprecated fields for old-style callers */
330 avctx
->channels
= avctx
->ch_layout
.nb_channels
;
331 avctx
->channel_layout
= avctx
->ch_layout
.order
== AV_CHANNEL_ORDER_NATIVE
?
332 avctx
->ch_layout
.u
.mask
: 0;
334 /* validate channel layout from the decoder */
335 if (avctx
->channel_layout
) {
336 int channels
= av_get_channel_layout_nb_channels(avctx
->channel_layout
);
337 if (!avctx
->channels
)
338 avctx
->channels
= channels
;
339 else if (channels
!= avctx
->channels
) {
341 av_get_channel_layout_string(buf
, sizeof(buf
), -1, avctx
->channel_layout
);
342 av_log(avctx
, AV_LOG_WARNING
,
343 "Channel layout '%s' with %d channels does not match specified number of channels %d: "
344 "ignoring specified channel layout\n",
345 buf
, channels
, avctx
->channels
);
346 avctx
->channel_layout
= 0;
349 if (avctx
->channels
&& avctx
->channels
< 0 ||
350 avctx
->channels
> FF_SANE_NB_CHANNELS
) {
351 ret
= AVERROR(EINVAL
);
354 if (avctx
->bits_per_coded_sample
< 0) {
355 ret
= AVERROR(EINVAL
);
358 FF_ENABLE_DEPRECATION_WARNINGS
361 #if FF_API_AVCTX_TIMEBASE
362 if (avctx
->framerate
.num
> 0 && avctx
->framerate
.den
> 0)
363 avctx
->time_base
= av_inv_q(av_mul_q(avctx
->framerate
, (AVRational
){avctx
->ticks_per_frame
, 1}));
366 if (codec
->priv_class
)
367 av_assert0(*(const AVClass
**)avctx
->priv_data
== codec
->priv_class
);
373 avcodec_close(avctx
);
377 void avcodec_flush_buffers(AVCodecContext
*avctx
)
379 AVCodecInternal
*avci
= avctx
->internal
;
381 if (av_codec_is_encoder(avctx
->codec
)) {
382 int caps
= avctx
->codec
->capabilities
;
384 if (!(caps
& AV_CODEC_CAP_ENCODER_FLUSH
)) {
385 // Only encoders that explicitly declare support for it can be
386 // flushed. Otherwise, this is a no-op.
387 av_log(avctx
, AV_LOG_WARNING
, "Ignoring attempt to flush encoder "
388 "that doesn't support it\n");
392 av_frame_unref(avci
->in_frame
);
394 av_packet_unref(avci
->last_pkt_props
);
395 while (av_fifo_read(avci
->pkt_props
, avci
->last_pkt_props
, 1) >= 0)
396 av_packet_unref(avci
->last_pkt_props
);
398 av_packet_unref(avci
->in_pkt
);
400 avctx
->pts_correction_last_pts
=
401 avctx
->pts_correction_last_dts
= INT64_MIN
;
403 av_bsf_flush(avci
->bsf
);
407 avci
->draining_done
= 0;
408 avci
->nb_draining_errors
= 0;
409 av_frame_unref(avci
->buffer_frame
);
410 av_packet_unref(avci
->buffer_pkt
);
412 if (HAVE_THREADS
&& avctx
->active_thread_type
& FF_THREAD_FRAME
)
413 ff_thread_flush(avctx
);
414 else if (ffcodec(avctx
->codec
)->flush
)
415 ffcodec(avctx
->codec
)->flush(avctx
);
418 void avsubtitle_free(AVSubtitle
*sub
)
422 for (i
= 0; i
< sub
->num_rects
; i
++) {
423 AVSubtitleRect
*const rect
= sub
->rects
[i
];
425 av_freep(&rect
->data
[0]);
426 av_freep(&rect
->data
[1]);
427 av_freep(&rect
->data
[2]);
428 av_freep(&rect
->data
[3]);
429 av_freep(&rect
->text
);
430 av_freep(&rect
->ass
);
432 av_freep(&sub
->rects
[i
]);
435 av_freep(&sub
->rects
);
437 memset(sub
, 0, sizeof(*sub
));
440 av_cold
int avcodec_close(AVCodecContext
*avctx
)
447 if (avcodec_is_open(avctx
)) {
448 AVCodecInternal
*avci
= avctx
->internal
;
450 if (CONFIG_FRAME_THREAD_ENCODER
&&
451 avci
->frame_thread_encoder
&& avctx
->thread_count
> 1) {
452 ff_frame_thread_encoder_free(avctx
);
454 if (HAVE_THREADS
&& avci
->thread_ctx
)
455 ff_thread_free(avctx
);
456 if (avci
->needs_close
&& ffcodec(avctx
->codec
)->close
)
457 ffcodec(avctx
->codec
)->close(avctx
);
458 avci
->byte_buffer_size
= 0;
459 av_freep(&avci
->byte_buffer
);
460 av_frame_free(&avci
->buffer_frame
);
461 av_packet_free(&avci
->buffer_pkt
);
462 if (avci
->pkt_props
) {
463 while (av_fifo_can_read(avci
->pkt_props
)) {
464 av_packet_unref(avci
->last_pkt_props
);
465 av_fifo_read(avci
->pkt_props
, avci
->last_pkt_props
, 1);
467 av_fifo_freep2(&avci
->pkt_props
);
469 av_packet_free(&avci
->last_pkt_props
);
471 av_packet_free(&avci
->in_pkt
);
472 av_frame_free(&avci
->in_frame
);
474 av_buffer_unref(&avci
->pool
);
476 if (avctx
->hwaccel
&& avctx
->hwaccel
->uninit
)
477 avctx
->hwaccel
->uninit(avctx
);
478 av_freep(&avci
->hwaccel_priv_data
);
480 av_bsf_free(&avci
->bsf
);
482 av_channel_layout_uninit(&avci
->initial_ch_layout
);
484 av_freep(&avctx
->internal
);
487 for (i
= 0; i
< avctx
->nb_coded_side_data
; i
++)
488 av_freep(&avctx
->coded_side_data
[i
].data
);
489 av_freep(&avctx
->coded_side_data
);
490 avctx
->nb_coded_side_data
= 0;
492 av_buffer_unref(&avctx
->hw_frames_ctx
);
493 av_buffer_unref(&avctx
->hw_device_ctx
);
495 if (avctx
->priv_data
&& avctx
->codec
&& avctx
->codec
->priv_class
)
496 av_opt_free(avctx
->priv_data
);
498 av_freep(&avctx
->priv_data
);
499 if (av_codec_is_encoder(avctx
->codec
)) {
500 av_freep(&avctx
->extradata
);
501 avctx
->extradata_size
= 0;
502 } else if (av_codec_is_decoder(avctx
->codec
))
503 av_freep(&avctx
->subtitle_header
);
506 avctx
->active_thread_type
= 0;
511 static const char *unknown_if_null(const char *str
)
513 return str
? str
: "unknown";
516 void avcodec_string(char *buf
, int buf_size
, AVCodecContext
*enc
, int encode
)
518 const char *codec_type
;
519 const char *codec_name
;
520 const char *profile
= NULL
;
524 AVRational display_aspect_ratio
;
525 const char *separator
= enc
->dump_separator
? (const char *)enc
->dump_separator
: ", ";
528 if (!buf
|| buf_size
<= 0)
530 av_bprint_init_for_buffer(&bprint
, buf
, buf_size
);
531 codec_type
= av_get_media_type_string(enc
->codec_type
);
532 codec_name
= avcodec_get_name(enc
->codec_id
);
533 profile
= avcodec_profile_name(enc
->codec_id
, enc
->profile
);
535 av_bprintf(&bprint
, "%s: %s", codec_type
? codec_type
: "unknown",
537 buf
[0] ^= 'a' ^ 'A'; /* first letter in uppercase */
539 if (enc
->codec
&& strcmp(enc
->codec
->name
, codec_name
))
540 av_bprintf(&bprint
, " (%s)", enc
->codec
->name
);
543 av_bprintf(&bprint
, " (%s)", profile
);
544 if ( enc
->codec_type
== AVMEDIA_TYPE_VIDEO
545 && av_log_get_level() >= AV_LOG_VERBOSE
547 av_bprintf(&bprint
, ", %d reference frame%s",
548 enc
->refs
, enc
->refs
> 1 ? "s" : "");
551 av_bprintf(&bprint
, " (%s / 0x%04X)",
552 av_fourcc2str(enc
->codec_tag
), enc
->codec_tag
);
554 switch (enc
->codec_type
) {
555 case AVMEDIA_TYPE_VIDEO
:
559 av_bprintf(&bprint
, "%s%s", separator
,
560 enc
->pix_fmt
== AV_PIX_FMT_NONE
? "none" :
561 unknown_if_null(av_get_pix_fmt_name(enc
->pix_fmt
)));
563 av_bprint_chars(&bprint
, '(', 1);
566 /* The following check ensures that '(' has been written
567 * and therefore allows us to erase it if it turns out
568 * to be unnecessary. */
569 if (!av_bprint_is_complete(&bprint
))
572 if (enc
->bits_per_raw_sample
&& enc
->pix_fmt
!= AV_PIX_FMT_NONE
&&
573 enc
->bits_per_raw_sample
< av_pix_fmt_desc_get(enc
->pix_fmt
)->comp
[0].depth
)
574 av_bprintf(&bprint
, "%d bpc, ", enc
->bits_per_raw_sample
);
575 if (enc
->color_range
!= AVCOL_RANGE_UNSPECIFIED
&&
576 (str
= av_color_range_name(enc
->color_range
)))
577 av_bprintf(&bprint
, "%s, ", str
);
579 if (enc
->colorspace
!= AVCOL_SPC_UNSPECIFIED
||
580 enc
->color_primaries
!= AVCOL_PRI_UNSPECIFIED
||
581 enc
->color_trc
!= AVCOL_TRC_UNSPECIFIED
) {
582 const char *col
= unknown_if_null(av_color_space_name(enc
->colorspace
));
583 const char *pri
= unknown_if_null(av_color_primaries_name(enc
->color_primaries
));
584 const char *trc
= unknown_if_null(av_color_transfer_name(enc
->color_trc
));
585 if (strcmp(col
, pri
) || strcmp(col
, trc
)) {
587 av_bprintf(&bprint
, "%s/%s/%s, ", col
, pri
, trc
);
589 av_bprintf(&bprint
, "%s, ", col
);
592 if (enc
->field_order
!= AV_FIELD_UNKNOWN
) {
593 const char *field_order
= "progressive";
594 if (enc
->field_order
== AV_FIELD_TT
)
595 field_order
= "top first";
596 else if (enc
->field_order
== AV_FIELD_BB
)
597 field_order
= "bottom first";
598 else if (enc
->field_order
== AV_FIELD_TB
)
599 field_order
= "top coded first (swapped)";
600 else if (enc
->field_order
== AV_FIELD_BT
)
601 field_order
= "bottom coded first (swapped)";
603 av_bprintf(&bprint
, "%s, ", field_order
);
606 if (av_log_get_level() >= AV_LOG_VERBOSE
&&
607 enc
->chroma_sample_location
!= AVCHROMA_LOC_UNSPECIFIED
&&
608 (str
= av_chroma_location_name(enc
->chroma_sample_location
)))
609 av_bprintf(&bprint
, "%s, ", str
);
611 if (len
== bprint
.len
) {
612 bprint
.str
[len
- 1] = '\0';
615 if (bprint
.len
- 2 < bprint
.size
) {
616 /* Erase the last ", " */
618 bprint
.str
[bprint
.len
] = '\0';
620 av_bprint_chars(&bprint
, ')', 1);
625 av_bprintf(&bprint
, "%s%dx%d", new_line
? separator
: ", ",
626 enc
->width
, enc
->height
);
628 if (av_log_get_level() >= AV_LOG_VERBOSE
&&
629 (enc
->width
!= enc
->coded_width
||
630 enc
->height
!= enc
->coded_height
))
631 av_bprintf(&bprint
, " (%dx%d)",
632 enc
->coded_width
, enc
->coded_height
);
634 if (enc
->sample_aspect_ratio
.num
) {
635 av_reduce(&display_aspect_ratio
.num
, &display_aspect_ratio
.den
,
636 enc
->width
* (int64_t)enc
->sample_aspect_ratio
.num
,
637 enc
->height
* (int64_t)enc
->sample_aspect_ratio
.den
,
639 av_bprintf(&bprint
, " [SAR %d:%d DAR %d:%d]",
640 enc
->sample_aspect_ratio
.num
, enc
->sample_aspect_ratio
.den
,
641 display_aspect_ratio
.num
, display_aspect_ratio
.den
);
643 if (av_log_get_level() >= AV_LOG_DEBUG
) {
644 int g
= av_gcd(enc
->time_base
.num
, enc
->time_base
.den
);
645 av_bprintf(&bprint
, ", %d/%d",
646 enc
->time_base
.num
/ g
, enc
->time_base
.den
/ g
);
650 av_bprintf(&bprint
, ", q=%d-%d", enc
->qmin
, enc
->qmax
);
652 if (enc
->properties
& FF_CODEC_PROPERTY_CLOSED_CAPTIONS
)
653 av_bprintf(&bprint
, ", Closed Captions");
654 if (enc
->properties
& FF_CODEC_PROPERTY_FILM_GRAIN
)
655 av_bprintf(&bprint
, ", Film Grain");
656 if (enc
->properties
& FF_CODEC_PROPERTY_LOSSLESS
)
657 av_bprintf(&bprint
, ", lossless");
660 case AVMEDIA_TYPE_AUDIO
:
661 av_bprintf(&bprint
, "%s", separator
);
663 if (enc
->sample_rate
) {
664 av_bprintf(&bprint
, "%d Hz, ", enc
->sample_rate
);
668 int ret
= av_channel_layout_describe(&enc
->ch_layout
, buf
, sizeof(buf
));
670 av_bprintf(&bprint
, "%s", buf
);
672 if (enc
->sample_fmt
!= AV_SAMPLE_FMT_NONE
&&
673 (str
= av_get_sample_fmt_name(enc
->sample_fmt
))) {
674 av_bprintf(&bprint
, ", %s", str
);
676 if ( enc
->bits_per_raw_sample
> 0
677 && enc
->bits_per_raw_sample
!= av_get_bytes_per_sample(enc
->sample_fmt
) * 8)
678 av_bprintf(&bprint
, " (%d bit)", enc
->bits_per_raw_sample
);
679 if (av_log_get_level() >= AV_LOG_VERBOSE
) {
680 if (enc
->initial_padding
)
681 av_bprintf(&bprint
, ", delay %d", enc
->initial_padding
);
682 if (enc
->trailing_padding
)
683 av_bprintf(&bprint
, ", padding %d", enc
->trailing_padding
);
686 case AVMEDIA_TYPE_DATA
:
687 if (av_log_get_level() >= AV_LOG_DEBUG
) {
688 int g
= av_gcd(enc
->time_base
.num
, enc
->time_base
.den
);
690 av_bprintf(&bprint
, ", %d/%d",
691 enc
->time_base
.num
/ g
, enc
->time_base
.den
/ g
);
694 case AVMEDIA_TYPE_SUBTITLE
:
696 av_bprintf(&bprint
, ", %dx%d", enc
->width
, enc
->height
);
702 if (enc
->flags
& AV_CODEC_FLAG_PASS1
)
703 av_bprintf(&bprint
, ", pass 1");
704 if (enc
->flags
& AV_CODEC_FLAG_PASS2
)
705 av_bprintf(&bprint
, ", pass 2");
707 bitrate
= get_bit_rate(enc
);
709 av_bprintf(&bprint
, ", %"PRId64
" kb/s", bitrate
/ 1000);
710 } else if (enc
->rc_max_rate
> 0) {
711 av_bprintf(&bprint
, ", max. %"PRId64
" kb/s", enc
->rc_max_rate
/ 1000);
715 int avcodec_is_open(AVCodecContext
*s
)
717 return !!s
->internal
;