FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/tests/encinfo.c
Date: 2026-08-19 01:31:13
Exec Total Coverage
Lines: 22 35 62.9%
Functions: 1 1 100.0%
Branches: 8 16 50.0%

Line Branch Exec Source
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"
31 #include "libavutil/channel_layout.h"
32
33 2 int main(int argc, char **argv)
34 {
35 const AVCodec *codec;
36 AVCodecContext *ctx;
37 2 int sample_rate = 44100;
38 2 int channels = 2;
39 int ret;
40
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (argc < 2) {
42 fprintf(stderr, "Usage: %s <codec_name> [sample_rate] [channels]\n",
43 argv[0]);
44 return 1;
45 }
46
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (argc >= 3)
48 sample_rate = atoi(argv[2]);
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (argc >= 4)
50 channels = atoi(argv[3]);
51
52 2 codec = avcodec_find_encoder_by_name(argv[1]);
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!codec) {
54 fprintf(stderr, "Encoder '%s' not found\n", argv[1]);
55 return 1;
56 }
57
58 2 ctx = avcodec_alloc_context3(codec);
59
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!ctx)
60 return AVERROR(ENOMEM);
61
62 2 ctx->sample_rate = sample_rate;
63 const void *sample_fmts;
64 2 ret = avcodec_get_supported_config(ctx, NULL, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, &sample_fmts, NULL);
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0) {
66 fprintf(stderr, "avcodec_get_supported_config failed: %d\n", ret);
67 avcodec_free_context(&ctx);
68 return 1;
69 }
70
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 ctx->sample_fmt = sample_fmts ? *(const enum AVSampleFormat*)sample_fmts : AV_SAMPLE_FMT_S16;
71 2 av_channel_layout_default(&ctx->ch_layout, channels);
72
73 2 ret = avcodec_open2(ctx, codec, NULL);
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret < 0) {
75 fprintf(stderr, "avcodec_open2 failed: %d\n", ret);
76 avcodec_free_context(&ctx);
77 return 1;
78 }
79
80 2 printf("%s bit_rate=%"PRId64" block_align=%d bits_per_coded_sample=%d frame_size=%d\n",
81 2 codec->name, ctx->bit_rate, ctx->block_align,
82 2 ctx->bits_per_coded_sample, ctx->frame_size);
83
84 2 avcodec_free_context(&ctx);
85 2 return 0;
86 }
87