[Libav-user] Encoding pcm_s32le

יוסף אלון yos104104 at gmail.com
Sun Apr 9 09:17:32 EEST 2017


I am trying to encode a file to pcm s32le.
I use the decodeing_encodeing.c example but I always recieve the folowing
Error:
[pcm_s32le @ 0x11d0e00] Specified sample format 48000 is invalid or not
supported
Could not open codec

The function is (Its not all the function, I marked what I have changed in
yellow:

static void audio_encode_example(const char *filename)
{
    AVCodec *codec;
    AVCodecContext *c= NULL;
    AVFrame *frame;
    AVPacket pkt;
    int i, j, k, ret, got_output;
    int buffer_size;
    FILE *f;
    uint16_t *samples;
    float t, tincr;

    printf("Encode audio file %s\n", filename);

    /* find the Wav encoder */
    codec = avcodec_find_encoder(AV_CODEC_ID_PCM_S32LE);
    if (!codec) {
        fprintf(stderr, "Codec not found\n");
        exit(1);
    }

    c = avcodec_alloc_context3(codec);
    if (!c) {
        fprintf(stderr, "Could not allocate audio codec context\n");
        exit(1);
    }

    /* put sample parameters */
    c->bit_rate = 64000;
    /* check that the encoder supports S32LE pcm input */
    c->sample_fmt =  AV_SAMPLE_FMT_S32;
    if (!check_sample_fmt(codec, c->sample_fmt)) {
        fprintf(stderr, "Encoder does not support sample format %s",
                av_get_sample_fmt_name(c->sample_fmt));
        exit(1);
    }
    printf("\n");

    /* select other audio parameters supported by the encoder */
    c->sample_rate    = select_sample_rate(codec);
    c->channel_layout = select_channel_layout(codec);
    c->channels       =
av_get_channel_layout_nb_channels(c->channel_layout);

    /* open it */
    if (avcodec_open2(c, codec, NULL) < 0) {
        fprintf(stderr, "Could not open codec\n");
        exit(1);
    }

The error is from avcodec_open2.
Allso with the original example It didnt worked for me (With
AV_CODEC_ID_MP2 and AV_SAMPLE_FMT_S16) and said the same error.

-- 
Yosef Alon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20170409/e3534e08/attachment.html>


More information about the Libav-user mailing list