<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Kevin,<div><br></div><div>I don't know about a general reference for codec params but</div><div>here is how it is done for MP2 encoder in the FFMPEG decoding_encoding.c example.</div><div>They generate a tone and encode it in mp2.</div><div>Maybe it could be a starting point.</div><div>All I've done with libav has been from examples. There is very little to no documentation online.</div><div>Good luck.</div><div><br></div><div>____________________________________________</div><div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">static void audio_encode_example(const char *filename)</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">{</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    AVCodec *codec;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    AVCodecContext *c= NULL;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    AVFrame *frame;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    AVPacket pkt;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    int i, j, k, ret, got_output;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    int buffer_size;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    FILE *f;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    uint16_t *samples;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    float t, tincr;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    printf("Encode audio file %s\n", filename);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* find the MP2 encoder */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    codec = avcodec_find_encoder(AV_CODEC_ID_MP2);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (!codec) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Codec not found\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    c = avcodec_alloc_context3(codec);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (!c) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Could not allocate audio codec context\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* put sample parameters */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    c->bit_rate = 64000;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* check that the encoder supports s16 pcm input */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    c->sample_fmt = AV_SAMPLE_FMT_S16;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (!check_sample_fmt(codec, c->sample_fmt)) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Encoder does not support sample format %s",</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">                av_get_sample_fmt_name(c->sample_fmt));</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; color: rgb(238, 232, 228); min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* select other audio parameters supported by the encoder */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    c->sample_rate    = select_sample_rate(codec);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    c->channel_layout = select_channel_layout(codec);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    c->channels       = av_get_channel_layout_nb_channels(c->channel_layout);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* open it */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (avcodec_open2(c, codec, NULL) < 0) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Could not open codec\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    f = fopen(filename, "wb");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (!f) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Could not open %s\n", filename);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* frame containing input raw audio */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    frame = av_frame_alloc();</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (!frame) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Could not allocate audio frame\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    frame->nb_samples     = c->frame_size;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    frame->format         = c->sample_fmt;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    frame->channel_layout = c->channel_layout;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* the codec gives us the frame size, in samples,</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">     * we calculate the size of the samples buffer in bytes */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    buffer_size = av_samples_get_buffer_size(NULL, c->channels, c->frame_size,</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">                                             c->sample_fmt, 0);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (buffer_size < 0) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Could not get sample buffer size\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    samples = av_malloc(buffer_size);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (!samples) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Could not allocate %d bytes for samples buffer\n",</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">                buffer_size);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* setup the data pointers in the AVFrame */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    ret = avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt,</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">                                   (const uint8_t*)samples, buffer_size, 0);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    if (ret < 0) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        fprintf(stderr, "Could not setup audio frame\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* encode a single tone sound */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    t = 0;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    tincr = 2 * M_PI * 440.0 / c->sample_rate;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    for (i = 0; i < 200; i++) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        av_init_packet(&pkt);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        pkt.data = NULL; // packet data will be allocated by the encoder</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        pkt.size = 0;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        for (j = 0; j < c->frame_size; j++) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            samples[2*j] = (int)(sin(t) * 10000);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            for (k = 1; k < c->channels; k++)</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">                samples[2*j + k] = samples[2*j];</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            t += tincr;</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        /* encode the samples */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        ret = avcodec_encode_audio2(c, &pkt, frame, &got_output);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        if (ret < 0) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            fprintf(stderr, "Error encoding audio frame\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        if (got_output) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            fwrite(pkt.data, 1, pkt.size, f);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            av_free_packet(&pkt);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    /* get the delayed frames */</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    for (got_output = 1; got_output; i++) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        ret = avcodec_encode_audio2(c, &pkt, NULL, &got_output);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        if (ret < 0) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            fprintf(stderr, "Error encoding frame\n");</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            exit(1);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        if (got_output) {</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            fwrite(pkt.data, 1, pkt.size, f);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">            av_free_packet(&pkt);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">        }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    }</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    fclose(f);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo; min-height: 16px;"><br></div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    av_freep(&samples);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    av_frame_free(&frame);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    avcodec_close(c);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">    av_free(c);</div><div style="margin: 0px; font-size: 14px; font-family: AppleMyungjo;">}</div></div><div><br></div><div><div><div>Le 18 juin 2015 à 16:04, Kevin J. Brooks <<a href="mailto:kbrooks@r2c-ss.com">kbrooks@r2c-ss.com</a>> a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite">
  
    <meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
  
  <div bgcolor="#FFFFFF" text="#000000">
    Can someone point me to a reference where I can learn how to set up
    the codec parameters?  Even if it is only setting up for WMAV2, but
    I do need to record both audio and video.<br>
    <br>
    On 6/17/2015 5:53 PM, Kevin J. Brooks wrote:<br>
    <blockquote cite="mid:5581FA82.3080709@r2c-ss.com" type="cite">
      <meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
      I changed the Audio codec to WMAV2, and left the rest of the
      AudioCodec settings the same Now the program crashes at this line
      in the QtMel code:<br>
      <br>
      int outSize = avcodec_encode_audio(<span style=" font-weight:600;">m_audioStream</span>-><span style=" font-weight:600;">codec</span>, <span style="
        font-weight:600;">m_audioOutputBuffer</span>, <span style="
        font-weight:600;">m_audioOutputBufferSize</span>, (short
      *)samples.data<span style=" color:#ffff00;"><font>())</font>;</span><br>
      <br>
      In debug the error staates "Stopped in thread 2 by:Exception at
      0x66364c62, cod:0xc0000005: write access violation at:0x1,
      flags=0x0 (first chance).<br>
      <br>
      I suspect I don't have the audio settings set write, but I am not
      sure how to set them for WMAV2.<br>
      <br>
      <br>
      <br>
      On 6/17/2015 4:30 PM, Kevin J. Brooks wrote:<br>
      <blockquote cite="mid:5581E6F9.8050408@r2c-ss.com" type="cite">
        <meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
        I am setting the AudioCodec to MP3,  I am using the pre-built
        libraries the code I have the causes the issue is from the code
        for the QtMEL library.  What I am posting here is the Audio
        Codec setup for the QtMel object.  I hope it helps.<br>
        <br>
        BTW I am using H264 for the Video Codec.  If I record video
        only, it does work, it is only if I try to add sound that it
        fails.<br>
        <span style=" color:#646482;"> </span><span style="
          color:#aaff00;"><br>
          <font>CR2CAudioFormat</font></span> format;
        <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    format.setChannelCount(2);</pre>
        <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    format.setSampleRate(44100);</pre>
        <pre style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    format.setFormat(CR2CAudioFormat::SignedInt16);</pre>
        <br>
        I really don't have a preference for the codec, I just need to
        know how to set it up properly. I am totally new at recording
        video and audio.<br>
        <br>
        <div class="moz-cite-prefix">
          <meta http-equiv="content-type" content="text/html;
            charset=windows-1252">
          On 6/17/2015 1:08 AM, Taha Ansari wrote:<br>
        </div>
        <blockquote cite="mid:CAK2cdgBVRZMzPmPP_H8A6BXpmDRRqQ5qxRWxFqMr=pAC2gDRHA@mail.gmail.com" type="cite">
          <div dir="ltr">On Wed, Jun 17, 2015 at 2:17 AM, Gonzalo
            Garramuno <span dir="ltr"><<a moz-do-not-send="true" href="mailto:ggarra13@gmail.com" target="_blank">ggarra13@gmail.com</a>></span>
            wrote:<br>
            <div class="gmail_extra">
              <div class="gmail_quote">
                <blockquote class="gmail_quote" style="margin:0 0 0
                  .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 16/06/15 09:06, Kevin J. Brooks wrote:<br>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      Yes I am.  For more information, I am developing
                      on Windoze 7.<br>
                    </blockquote>
                  </span> avcodec_open2 can fail if you lack the library
                  for the codec you want to decode or encode.  For
                  example, libx264.  The libraries in <a moz-do-not-send="true" href="http://ffmpeg.zeranoe.com/" rel="noreferrer" target="_blank">ffmpeg.zeranoe.com</a> contain all
                  codecs, but they are GPL only.  You should try them
                  first and see if the problem goes away.  If it does,
                  you know you have to compile ffmpeg with different
                  flags.<span class="HOEnZb"></span><br>
                </blockquote>
              </div>
              <br>
            </div>
            <div class="gmail_extra">Since he mentions Windows 7, I
              assume he is using pre-built packages from zeranoe site
              (as you mention). These builds contain proprietary
              codec(s) like x264 (non GPL).<br>
              <br>
            </div>
            <div class="gmail_extra">@Kevin: maybe you have some bare
              minimum code with you that can produce this error, which
              people can have a look? <br>
            </div>
          </div>
          <br>
          <fieldset class="mimeAttachmentHeader"></fieldset>
          <br>
          <pre wrap="">_______________________________________________
Libav-user mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://ffmpeg.org/mailman/listinfo/libav-user">http://ffmpeg.org/mailman/listinfo/libav-user</a>
</pre>
        </blockquote>
        <br>
        <br>
        <fieldset class="mimeAttachmentHeader"></fieldset>
        <br>
        <pre wrap="">_______________________________________________
Libav-user mailing list
<a moz-do-not-send="true" class="moz-txt-link-abbreviated" href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://ffmpeg.org/mailman/listinfo/libav-user">http://ffmpeg.org/mailman/listinfo/libav-user</a>
</pre>
      </blockquote>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Libav-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a>
<a class="moz-txt-link-freetext" href="http://ffmpeg.org/mailman/listinfo/libav-user">http://ffmpeg.org/mailman/listinfo/libav-user</a>
</pre>
    </blockquote>
    <br>
  </div>

_______________________________________________<br>Libav-user mailing list<br><a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>http://ffmpeg.org/mailman/listinfo/libav-user<br></blockquote></div><br></div></body></html>