FFmpeg
encinfo.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * Print encoder properties (bit_rate, block_align, bits_per_coded_sample,
21  * frame_size) after init.
22  * Useful for verifying that encoders correctly set their codec parameters.
23  *
24  * Usage: encinfo <codec_name> [sample_rate] [channels]
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include "libavcodec/avcodec.h"
32 
33 int main(int argc, char **argv)
34 {
35  const AVCodec *codec;
37  int sample_rate = 44100;
38  int channels = 2;
39  int ret;
40 
41  if (argc < 2) {
42  fprintf(stderr, "Usage: %s <codec_name> [sample_rate] [channels]\n",
43  argv[0]);
44  return 1;
45  }
46 
47  if (argc >= 3)
48  sample_rate = atoi(argv[2]);
49  if (argc >= 4)
50  channels = atoi(argv[3]);
51 
52  codec = avcodec_find_encoder_by_name(argv[1]);
53  if (!codec) {
54  fprintf(stderr, "Encoder '%s' not found\n", argv[1]);
55  return 1;
56  }
57 
58  ctx = avcodec_alloc_context3(codec);
59  if (!ctx)
60  return AVERROR(ENOMEM);
61 
62  ctx->sample_rate = sample_rate;
63  ctx->sample_fmt = codec->sample_fmts ? codec->sample_fmts[0] : AV_SAMPLE_FMT_S16;
65 
66  ret = avcodec_open2(ctx, codec, NULL);
67  if (ret < 0) {
68  fprintf(stderr, "avcodec_open2 failed: %d\n", ret);
70  return 1;
71  }
72 
73  printf("%s bit_rate=%"PRId64" block_align=%d bits_per_coded_sample=%d frame_size=%d\n",
74  codec->name, ctx->bit_rate, ctx->block_align,
75  ctx->bits_per_coded_sample, ctx->frame_size);
76 
78  return 0;
79 }
AVCodec
AVCodec.
Definition: codec.h:172
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
printf
__device__ int printf(const char *,...)
main
int main(int argc, char **argv)
Print encoder properties (bit_rate, block_align, bits_per_coded_sample, frame_size) after init.
Definition: encinfo.c:33
AVFormatContext::bit_rate
int64_t bit_rate
Total stream bitrate in bit/s, 0 if not available.
Definition: avformat.h:1456
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
channels
channels
Definition: aptx.h:31
NULL
#define NULL
Definition: coverity.c:32
avcodec_free_context
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
Definition: options.c:164
avcodec_open2
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
Definition: avcodec.c:144
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:841
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
AVCodec::sample_fmts
attribute_deprecated enum AVSampleFormat * sample_fmts
Definition: codec.h:204
avcodec.h
ret
ret
Definition: filter_design.txt:187
AVCodecContext
main external API structure.
Definition: avcodec.h:443
channel_layout.h
avcodec_find_encoder_by_name
const AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: allcodecs.c:1068