FFmpeg
Loading...
Searching...
No Matches
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
33int 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
59 if (!ctx)
60 return AVERROR(ENOMEM);
61
62 ctx->sample_rate = sample_rate;
63 const void *sample_fmts;
65 if (ret < 0) {
66 fprintf(stderr, "avcodec_get_supported_config failed: %d\n", ret);
68 return 1;
69 }
70 ctx->sample_fmt = sample_fmts ? *(const enum AVSampleFormat*)sample_fmts : AV_SAMPLE_FMT_S16;
72
73 ret = avcodec_open2(ctx, codec, NULL);
74 if (ret < 0) {
75 fprintf(stderr, "avcodec_open2 failed: %d\n", ret);
77 return 1;
78 }
79
80 printf("%s bit_rate=%"PRId64" block_align=%d bits_per_coded_sample=%d frame_size=%d\n",
81 codec->name, ctx->bit_rate, ctx->block_align,
82 ctx->bits_per_coded_sample, ctx->frame_size);
83
85 return 0;
86}
static enum AVSampleFormat sample_fmts[]
Definition adpcmenc.c:933
channels
Definition aptx.h:31
Libavcodec external API header.
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
__device__ int printf(const char *,...)
int main
Definition dovi_rpuenc.c:38
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
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition options.c:149
const AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition allcodecs.c:1013
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
int avcodec_get_supported_config(const AVCodecContext *avctx, const AVCodec *codec, enum AVCodecConfig config, unsigned flags, const void **out, int *out_num)
Retrieve a list of all supported values for a given configuration type.
Definition avcodec.c:818
@ AV_CODEC_CONFIG_SAMPLE_FORMAT
AVSampleFormat, terminated by AV_SAMPLE_FMT_NONE.
Definition avcodec.h:2576
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#define AVERROR(e)
Definition error.h:45
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition samplefmt.h:58
main external API structure.
Definition avcodec.h:443
AVCodec.
Definition codec.h:175
const char * name
Name of the codec implementation.
Definition codec.h:182
static AVFormatContext * ctx
Definition movenc.c:49