<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Dear all<br>
    <br>
    I am having some issues in creating a G711 audio mkv container with
    libavcodec on windows.<br>
    I set the codec context (header) like this: <br>
    c->codec_id = CODEC_ID_PCM_ALAW;<br>
    c->codec_type = CODEC_TYPE_AUDIO;<br>
    c->bit_rate = 64000;<br>
    c->sample_rate = 8000;<br>
    c->channels = 1;<br>
    c->frame_size = 2650;<br>
    c->channel_layout = 1;<br>
    waveFormatEX = malloc(sizeof(WAVEFORMATEXTENSIBLE) +
    FF_INPUT_BUFFER_PADDING_SIZE);<br>
    waveFormatEX->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;<br>
    waveFormatEX->Format.nChannels = 1;<br>
    waveFormatEX->Format.nSamplesPerSec = 8000; <br>
    waveFormatEX->Format.wBitsPerSample = 16;<br>
    waveFormatEX->Format.nBlockAlign = 2;<br>
    waveFormatEX->Format.nAvgBytesPerSec = 16000;<br>
    waveFormatEX->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);<br>
    waveFormatEX->Samples.wSamplesPerBlock = 0;<br>
    waveFormatEX->dwChannelMask = KSAUDIO_SPEAKER_MONO;<br>
    waveFormatEX->SubFormat = KSDATAFORMAT_SUBTYPE_ALAW;<br>
    c->extradata = (uint8_t*)waveFormatEX;            <br>
    c->extradata_size = waveFormatEX->Format.cbSize;<br>
    <br>
    The mkv container is created, ffplay can play it without problems:<br>
    <br>
    This is the what ffplay outputs when playing the file:<br>
    <br>
    Input #0, matroska,webm, from 'c:\Users\alex\Bus
    standard-37-Enregistreur Xebra3<br>
    --2016-09-15(0h 1m 0s)\Cam 1 Flux audio.mkv':<br>
      Metadata:<br>
        encoder         : Lavf52.78.1<br>
      Duration: 00:01:52.00, start: 0.000000, bitrate: 34 kb/s<br>
        Stream #0:0: Audio: pcm_alaw ([6][0][0][0] / 0x0006), 8000 Hz, 1
    channels, s<br>
    16, 64 kb/s (default)<br>
        Stream #0:1(fra): Subtitle: subrip (default)<br>
       8.94 M-A: -0.000 fd=   0 aq=  421KB vq=    0KB sq=    0B f=0/0<br>
    <br>
    The sound can be heard witthout problems. The file should have ~ 1
    minute, but ffplay say the duration is 1:52<br>
    <br>
    The vlc player instead has issues in playing the file. The sound is
    heard but with "gaps", something related to pts?<br>
    This is the info from vlc about the file:<br>
    Type: Audio<br>
    Codec: PCM ALAW(alaw)<br>
    Channels: Mono<br>
    Sample rate: 8000 Hz<br>
    Bits per sample: 16<br>
    And here are some warnings while playing the file:<br>
    <span style=" font-style:italic; color:#00008b;">core</span><span
      style=" font-style:italic; color:#008000;"> warning: </span>playback
    way too early (-170000): playing silence
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
      margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span
        style=" font-style:italic; color:#00008b;">core</span><span
        style=" font-style:italic; color:#808080;"> debug: </span>inserting
      1360 zeroes</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
      margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span
        style=" font-style:italic; color:#00008b;">core</span><span
        style=" font-style:italic; color:#008000;"> warning: </span>playback
      way too early (-150000): playing silence</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
      margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span
        style=" font-style:italic; color:#00008b;">core</span><span
        style=" font-style:italic; color:#808080;"> debug: </span>inserting
      1200 zeroes</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
      margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span
        style=" font-style:italic; color:#00008b;">core</span><span
        style=" font-style:italic; color:#008000;"> warning: </span>playback
      way too early (-170000): playing silence</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
      margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span
        style=" font-style:italic; color:#00008b;">core</span><span
        style=" font-style:italic; color:#808080;"> debug: </span>inserting
      1360 zeroes</p>
    <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px;
      margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span
        style=" font-style:italic; color:#00008b;">core</span><span
        style=" font-style:italic; color:#008000;"> warning: </span>playback
      way too early (-150000): playing silence</p>
    <br>
    <br>
    Can somebody please guide how to properly set G.711
    (CODEC_ID_PCM_ALAW) in libavcodec?<br>
    Thank you a lot for reading this long post<br>
  </body>
</html>