Discussion:
[Libav-user] G.711 audio in mkv container
Alex Grosu
2016-09-23 11:13:27 UTC
Permalink
Dear all

I am having some issues in creating a G711 audio mkv container with
libavcodec on windows.
I set the codec context (header) like this:
c->codec_id = CODEC_ID_PCM_ALAW;
c->codec_type = CODEC_TYPE_AUDIO;
c->bit_rate = 64000;
c->sample_rate = 8000;
c->channels = 1;
c->frame_size = 2650;
c->channel_layout = 1;
waveFormatEX = malloc(sizeof(WAVEFORMATEXTENSIBLE) +
FF_INPUT_BUFFER_PADDING_SIZE);
waveFormatEX->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
waveFormatEX->Format.nChannels = 1;
waveFormatEX->Format.nSamplesPerSec = 8000;
waveFormatEX->Format.wBitsPerSample = 16;
waveFormatEX->Format.nBlockAlign = 2;
waveFormatEX->Format.nAvgBytesPerSec = 16000;
waveFormatEX->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);
waveFormatEX->Samples.wSamplesPerBlock = 0;
waveFormatEX->dwChannelMask = KSAUDIO_SPEAKER_MONO;
waveFormatEX->SubFormat = KSDATAFORMAT_SUBTYPE_ALAW;
c->extradata = (uint8_t*)waveFormatEX;
c->extradata_size = waveFormatEX->Format.cbSize;

The mkv container is created, ffplay can play it without problems:

This is the what ffplay outputs when playing the file:

Input #0, matroska,webm, from 'c:\Users\alex\Bus
standard-37-Enregistreur Xebra3
--2016-09-15(0h 1m 0s)\Cam 1 Flux audio.mkv':
Metadata:
encoder : Lavf52.78.1
Duration: 00:01:52.00, start: 0.000000, bitrate: 34 kb/s
Stream #0:0: Audio: pcm_alaw ([6][0][0][0] / 0x0006), 8000 Hz, 1
channels, s
16, 64 kb/s (default)
Stream #0:1(fra): Subtitle: subrip (default)
8.94 M-A: -0.000 fd= 0 aq= 421KB vq= 0KB sq= 0B f=0/0

The sound can be heard witthout problems. The file should have ~ 1
minute, but ffplay say the duration is 1:52

The vlc player instead has issues in playing the file. The sound is
heard but with "gaps", something related to pts?
This is the info from vlc about the file:
Type: Audio
Codec: PCM ALAW(alaw)
Channels: Mono
Sample rate: 8000 Hz
Bits per sample: 16
And here are some warnings while playing the file:
corewarning: playback way too early (-170000): playing silence

coredebug: inserting 1360 zeroes

corewarning: playback way too early (-150000): playing silence

coredebug: inserting 1200 zeroes

corewarning: playback way too early (-170000): playing silence

coredebug: inserting 1360 zeroes

corewarning: playback way too early (-150000): playing silence



Can somebody please guide how to properly set G.711 (CODEC_ID_PCM_ALAW)
in libavcodec?
Thank you a lot for reading this long post
Alex Grosu
2016-09-23 11:16:09 UTC
Permalink
One correction,

c->frame_size = 2560 (not 2650, typo)

Sorry for this
Post by Alex Grosu
Dear all
I am having some issues in creating a G711 audio mkv container with
libavcodec on windows.
c->codec_id = CODEC_ID_PCM_ALAW;
c->codec_type = CODEC_TYPE_AUDIO;
c->bit_rate = 64000;
c->sample_rate = 8000;
c->channels = 1;
c->frame_size = 2650;
c->channel_layout = 1;
waveFormatEX = malloc(sizeof(WAVEFORMATEXTENSIBLE) +
FF_INPUT_BUFFER_PADDING_SIZE);
waveFormatEX->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
waveFormatEX->Format.nChannels = 1;
waveFormatEX->Format.nSamplesPerSec = 8000;
waveFormatEX->Format.wBitsPerSample = 16;
waveFormatEX->Format.nBlockAlign = 2;
waveFormatEX->Format.nAvgBytesPerSec = 16000;
waveFormatEX->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);
waveFormatEX->Samples.wSamplesPerBlock = 0;
waveFormatEX->dwChannelMask = KSAUDIO_SPEAKER_MONO;
waveFormatEX->SubFormat = KSDATAFORMAT_SUBTYPE_ALAW;
c->extradata = (uint8_t*)waveFormatEX;
c->extradata_size = waveFormatEX->Format.cbSize;
Input #0, matroska,webm, from 'c:\Users\alex\Bus
standard-37-Enregistreur Xebra3
encoder : Lavf52.78.1
Duration: 00:01:52.00, start: 0.000000, bitrate: 34 kb/s
Stream #0:0: Audio: pcm_alaw ([6][0][0][0] / 0x0006), 8000 Hz, 1
channels, s
16, 64 kb/s (default)
Stream #0:1(fra): Subtitle: subrip (default)
8.94 M-A: -0.000 fd= 0 aq= 421KB vq= 0KB sq= 0B f=0/0
The sound can be heard witthout problems. The file should have ~ 1
minute, but ffplay say the duration is 1:52
The vlc player instead has issues in playing the file. The sound is
heard but with "gaps", something related to pts?
Type: Audio
Codec: PCM ALAW(alaw)
Channels: Mono
Sample rate: 8000 Hz
Bits per sample: 16
corewarning: playback way too early (-170000): playing silence
coredebug: inserting 1360 zeroes
corewarning: playback way too early (-150000): playing silence
coredebug: inserting 1200 zeroes
corewarning: playback way too early (-170000): playing silence
coredebug: inserting 1360 zeroes
corewarning: playback way too early (-150000): playing silence
Can somebody please guide how to properly set G.711
(CODEC_ID_PCM_ALAW) in libavcodec?
Thank you a lot for reading this long post
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Alex Grosu
2016-09-23 11:19:29 UTC
Permalink
Arghh, I forgot to add in my previous mail these settings :

c->sample_fmt = SAMPLE_FMT_S16;

c->flags = CODEC_FLAG_GLOBAL_HEADER;
Post by Alex Grosu
One correction,
c->frame_size = 2560 (not 2650, typo)
Sorry for this
Post by Alex Grosu
Dear all
I am having some issues in creating a G711 audio mkv container with
libavcodec on windows.
c->codec_id = CODEC_ID_PCM_ALAW;
c->codec_type = CODEC_TYPE_AUDIO;
c->bit_rate = 64000;
c->sample_rate = 8000;
c->channels = 1;
c->frame_size = 2650;
c->channel_layout = 1;
waveFormatEX = malloc(sizeof(WAVEFORMATEXTENSIBLE) +
FF_INPUT_BUFFER_PADDING_SIZE);
waveFormatEX->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
waveFormatEX->Format.nChannels = 1;
waveFormatEX->Format.nSamplesPerSec = 8000;
waveFormatEX->Format.wBitsPerSample = 16;
waveFormatEX->Format.nBlockAlign = 2;
waveFormatEX->Format.nAvgBytesPerSec = 16000;
waveFormatEX->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);
waveFormatEX->Samples.wSamplesPerBlock = 0;
waveFormatEX->dwChannelMask = KSAUDIO_SPEAKER_MONO;
waveFormatEX->SubFormat = KSDATAFORMAT_SUBTYPE_ALAW;
c->extradata = (uint8_t*)waveFormatEX;
c->extradata_size = waveFormatEX->Format.cbSize;
Input #0, matroska,webm, from 'c:\Users\alex\Bus
standard-37-Enregistreur Xebra3
encoder : Lavf52.78.1
Duration: 00:01:52.00, start: 0.000000, bitrate: 34 kb/s
Stream #0:0: Audio: pcm_alaw ([6][0][0][0] / 0x0006), 8000 Hz, 1
channels, s
16, 64 kb/s (default)
Stream #0:1(fra): Subtitle: subrip (default)
8.94 M-A: -0.000 fd= 0 aq= 421KB vq= 0KB sq= 0B f=0/0
The sound can be heard witthout problems. The file should have ~ 1
minute, but ffplay say the duration is 1:52
The vlc player instead has issues in playing the file. The sound is
heard but with "gaps", something related to pts?
Type: Audio
Codec: PCM ALAW(alaw)
Channels: Mono
Sample rate: 8000 Hz
Bits per sample: 16
corewarning: playback way too early (-170000): playing silence
coredebug: inserting 1360 zeroes
corewarning: playback way too early (-150000): playing silence
coredebug: inserting 1200 zeroes
corewarning: playback way too early (-170000): playing silence
coredebug: inserting 1360 zeroes
corewarning: playback way too early (-150000): playing silence
Can somebody please guide how to properly set G.711
(CODEC_ID_PCM_ALAW) in libavcodec?
Thank you a lot for reading this long post
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Alex Grosu
2016-09-23 11:31:21 UTC
Permalink
Ok, I figured it out. The frame_size should not have been set to 2560,
but instead let it in the initial state (0). After that, the frames are
coming with 1280 as frame_size

So anyway, for anyone who want to put G7111 audio codec in a mkv
container (Windows), here is the header:

c->codec_id = CODEC_ID_PCM_ALAW;
c->codec_type = CODEC_TYPE_AUDIO;

c->sample_fmt = SAMPLE_FMT_S16;

c->flags = CODEC_FLAG_GLOBAL_HEADER;

c->bit_rate = 64000;
c->sample_rate = 8000;
c->channels = 1;
c->channel_layout = 1;
waveFormatEX = malloc(sizeof(WAVEFORMATEXTENSIBLE) +
FF_INPUT_BUFFER_PADDING_SIZE);
waveFormatEX->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
waveFormatEX->Format.nChannels = 1;
waveFormatEX->Format.nSamplesPerSec = 8000;
waveFormatEX->Format.wBitsPerSample = 16;
waveFormatEX->Format.nBlockAlign = 2;
waveFormatEX->Format.nAvgBytesPerSec = 16000;
waveFormatEX->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);
waveFormatEX->Samples.wSamplesPerBlock = 0;
waveFormatEX->dwChannelMask = KSAUDIO_SPEAKER_MONO;
waveFormatEX->SubFormat = KSDATAFORMAT_SUBTYPE_ALAW;
c->extradata = (uint8_t*)waveFormatEX;
c->extradata_size = waveFormatEX->Format.cbSize;


This is working for me
Post by Alex Grosu
c->sample_fmt = SAMPLE_FMT_S16;
c->flags = CODEC_FLAG_GLOBAL_HEADER;
Post by Alex Grosu
One correction,
c->frame_size = 2560 (not 2650, typo)
Sorry for this
Post by Alex Grosu
Dear all
I am having some issues in creating a G711 audio mkv container with
libavcodec on windows.
c->codec_id = CODEC_ID_PCM_ALAW;
c->codec_type = CODEC_TYPE_AUDIO;
c->bit_rate = 64000;
c->sample_rate = 8000;
c->channels = 1;
c->frame_size = 2650;
c->channel_layout = 1;
waveFormatEX = malloc(sizeof(WAVEFORMATEXTENSIBLE) +
FF_INPUT_BUFFER_PADDING_SIZE);
waveFormatEX->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
waveFormatEX->Format.nChannels = 1;
waveFormatEX->Format.nSamplesPerSec = 8000;
waveFormatEX->Format.wBitsPerSample = 16;
waveFormatEX->Format.nBlockAlign = 2;
waveFormatEX->Format.nAvgBytesPerSec = 16000;
waveFormatEX->Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE);
waveFormatEX->Samples.wSamplesPerBlock = 0;
waveFormatEX->dwChannelMask = KSAUDIO_SPEAKER_MONO;
waveFormatEX->SubFormat = KSDATAFORMAT_SUBTYPE_ALAW;
c->extradata = (uint8_t*)waveFormatEX;
c->extradata_size = waveFormatEX->Format.cbSize;
Input #0, matroska,webm, from 'c:\Users\alex\Bus
standard-37-Enregistreur Xebra3
encoder : Lavf52.78.1
Duration: 00:01:52.00, start: 0.000000, bitrate: 34 kb/s
Stream #0:0: Audio: pcm_alaw ([6][0][0][0] / 0x0006), 8000 Hz, 1
channels, s
16, 64 kb/s (default)
Stream #0:1(fra): Subtitle: subrip (default)
8.94 M-A: -0.000 fd= 0 aq= 421KB vq= 0KB sq= 0B f=0/0
The sound can be heard witthout problems. The file should have ~ 1
minute, but ffplay say the duration is 1:52
The vlc player instead has issues in playing the file. The sound is
heard but with "gaps", something related to pts?
Type: Audio
Codec: PCM ALAW(alaw)
Channels: Mono
Sample rate: 8000 Hz
Bits per sample: 16
corewarning: playback way too early (-170000): playing silence
coredebug: inserting 1360 zeroes
corewarning: playback way too early (-150000): playing silence
coredebug: inserting 1200 zeroes
corewarning: playback way too early (-170000): playing silence
coredebug: inserting 1360 zeroes
corewarning: playback way too early (-150000): playing silence
Can somebody please guide how to properly set G.711
(CODEC_ID_PCM_ALAW) in libavcodec?
Thank you a lot for reading this long post
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Alex Grosu
2016-10-03 10:52:52 UTC
Permalink
Dear all

I am having some issues with time decoding H.264 frames with libavcodec.
I am receiving 1920x1080 frames at 25 FPS, thus a frame should be
displayed each 40 ms. But the decoding time per frame is between 55 ms
and 83 ms, way too much.
I am thinking at the following strategy: create 4 threads, each thread
will decode a I-Frame slice (composed by SPS and PPS and IDR + all NACs
until the next SPS&PPS&IDR). In theory, this should work on a >4CPUs
processor.
My question is: is there any other way in handling this kind of situation?

Kind regards
Alex
Carl Eugen Hoyos
2016-10-03 11:45:32 UTC
Permalink
I am having some issues with time decoding H.264 frames with libavcodec. I
am receiving 1920x1080 frames at 25 FPS, thus a frame should be displayed
each 40 ms. But the decoding time per frame is between 55 ms and 83 ms, way
too much.
I am thinking at the following strategy: create 4 threads, each thread will
decode a I-Frame slice (composed by SPS and PPS and IDR + all NACs until the
next SPS&PPS&IDR). In theory, this should work on a >4CPUs processor.
My question is: is there any other way in handling this kind of situation?
FFmpeg already contains a multi-threaded H.264 decoder: While it scales badly
I don't expect a wrapper implementation to work much better.
(Unless you really have full control over gop size, in this case you know
something that the FFmpeg decoder cannot know.)

Carl Eugen
Alex Grosu
2016-10-03 11:55:52 UTC
Permalink
Hi Carl

I built libavcodec some time ago on Windows and I am calling the API
functions from my C app. (avcodec_find_decoder, avcodec_open,
avcodec_decode_video2, sws_scale). Now, having big frames with a lot of
details, the time decoding increased > 55 ms, which is greater than the
time a frame should be displayed (40 ms). I have to do some threading
logic programatically, using libavcodec, not from command line. Or maybe
I am not fully understanding your hint

Thank you

Alex
Post by Carl Eugen Hoyos
I am having some issues with time decoding H.264 frames with libavcodec. I
am receiving 1920x1080 frames at 25 FPS, thus a frame should be displayed
each 40 ms. But the decoding time per frame is between 55 ms and 83 ms, way
too much.
I am thinking at the following strategy: create 4 threads, each thread will
decode a I-Frame slice (composed by SPS and PPS and IDR + all NACs until the
next SPS&PPS&IDR). In theory, this should work on a >4CPUs processor.
My question is: is there any other way in handling this kind of situation?
FFmpeg already contains a multi-threaded H.264 decoder: While it scales badly
I don't expect a wrapper implementation to work much better.
(Unless you really have full control over gop size, in this case you know
something that the FFmpeg decoder cannot know.)
Carl Eugen
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Carl Eugen Hoyos
2016-10-03 11:58:30 UTC
Permalink
Post by Alex Grosu
I built libavcodec some time ago on Windows and I am calling the API
functions from my C app. (avcodec_find_decoder, avcodec_open,
avcodec_decode_video2, sws_scale). Now, having big frames with a lot of
details, the time decoding increased > 55 ms, which is greater than the time
a frame should be displayed (40 ms). I have to do some threading logic
programatically, using libavcodec, not from command line.
To which value do you currently set AVCodecContext->thread_count for
decoding?

Please do not top-post here, Carl Eugen
Alex Grosu
2016-10-03 12:26:40 UTC
Permalink
I am just calling avcodec_alloc_context(). This sets thread_count to 1.
I tried set it to 4, but it seems there is no difference. Is there any
other flag I should set along with thread_count?

Thank you

Alex
Post by Carl Eugen Hoyos
Post by Alex Grosu
I built libavcodec some time ago on Windows and I am calling the API
functions from my C app. (avcodec_find_decoder, avcodec_open,
avcodec_decode_video2, sws_scale). Now, having big frames with a lot of
details, the time decoding increased > 55 ms, which is greater than the time
a frame should be displayed (40 ms). I have to do some threading logic
programatically, using libavcodec, not from command line.
To which value do you currently set AVCodecContext->thread_count for
decoding?
Please do not top-post here, Carl Eugen
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Carl Eugen Hoyos
2016-10-04 09:24:11 UTC
Permalink
Post by Alex Grosu
I am just calling avcodec_alloc_context(). This sets thread_count
to 1. I tried set it to 4, but it seems there is no difference.
Do you see the same behaviour with ffmpeg (the application)?

Carl Eugen
Simon Brown
2016-10-04 09:52:42 UTC
Permalink
Post by Alex Grosu
I am just calling avcodec_alloc_context(). This sets thread_count
to 1. I tried set it to 4, but it seems there is no difference.
When I asked about increasing thread count, someone helpfully pointed me
at this thread:
https://ffmpeg.org/pipermail/libav-user/2016-July/009365.html
In particular, points to note are to set thread count BEFORE opening the
codec, and setting
thread count to "auto" seems to work well - but from my tests it defaults
to 1, so does need changing.
Regards,
Simon
Alex Grosu
2016-10-04 14:39:16 UTC
Permalink
Post by Alex Grosu
I am just calling avcodec_alloc_context(). This sets thread_count
to 1. I tried set it to 4, but it seems there is no difference.
When I asked about increasing thread count, someone helpfully pointed
https://ffmpeg.org/pipermail/libav-user/2016-July/009365.html
In particular, points to note are to set thread count BEFORE opening
the codec, and setting
thread count to "auto" seems to work well - but from my tests it
defaults to 1, so does need changing.
Regards,
Simon
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Thank you Simon, I am following the info you gave me
Kind regards
Alex
Alex Grosu
2016-10-13 14:19:35 UTC
Permalink
Hello

Using libavcodec, I would like to implement a logic for reverse playback
(and frame by frame in reverse) in my video player app.
I am thinking to use some buffering method, and store a whole GOP (4
seconds) in a RAM buffer while playing in normal mode. When the user
wants to reverse playback, I will simply use the stored frames,
rendering them backwards and fill the buffer with the previous GOP (on
another thread, of course) while the user uses reverse playback. I am
aware this will be memory consuming, but with current hardware
capabilities...
I do have a second idea. At the moment, I am dropping all the rendered
frames in playback mode. When the user wants to reverse playback, I will
request the previous I-frame and all the P-frames until the current
frame, decode them, fill the buffer and start playing backward. The
previous GOP will be requested while playing backwards, and buffer
fullfilled.

Is there any other point I can start with? Another idea or some hints?

Thank you a lot for reading this
Alex

Alex Grosu
2016-10-04 14:35:34 UTC
Permalink
I am sorry but I am unable to test with the ffmpeg application. I am
receiving the frames from an embedded equipment with a propietary
protocol. My app is decoding this frames, taking the h264 raw data and
send them to the libavcodec. I set up a timing system to see which part
is consuming the time, and it seems that it stays in libavcodec
avcodec_decode_video2 function ~75 % from the total time and ~15 % in
sws_scale function

Alex
Post by Carl Eugen Hoyos
Post by Alex Grosu
I am just calling avcodec_alloc_context(). This sets thread_count
to 1. I tried set it to 4, but it seems there is no difference.
Do you see the same behaviour with ffmpeg (the application)?
Carl Eugen
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Alex Grosu
2016-10-03 15:05:41 UTC
Permalink
Dear Carl
I forgot to tell that the version of my ffmpeg build is old, I can't
find for example "active_thread_type" variable, only thread_count and
thread_opaque. I built the library with --enable-pthreads, I can see
this by calling "avcodec_configuration()"
Thank you for all the help I can get
PS: can you please tell me what you ment by "do not top-post here" ?
Thank you
Alex
Post by Carl Eugen Hoyos
To which value do you currently set AVCodecContext->thread_count for
decoding?
Please do not top-post here, Carl Eugen
_______________________________________________
Libav-user mailing list
http://ffmpeg.org/mailman/listinfo/libav-user
Carl Eugen Hoyos
2016-10-03 18:31:20 UTC
Permalink
Post by Alex Grosu
PS: can you please tell me what you ment by "do not top-post here" ?
What have you done so far to find out?

Carl Eugen
Alex Grosu
2016-10-04 07:08:18 UTC
Permalink
Post by Carl Eugen Hoyos
Post by Alex Grosu
PS: can you please tell me what you ment by "do not top-post here" ?
What have you done so far to find out?
Carl Eugen
_______________________________________________
Post by Alex Grosu
I built libavcodec some time ago on Windows and I am calling the API
functions from my C app. (avcodec_find_decoder, avcodec_open,
avcodec_decode_video2, sws_scale). Now, having big frames with a lot of
details, the time decoding increased > 55 ms, which is greater than the time
a frame should be displayed (40 ms). I have to do some threading logic
programatically, using libavcodec, not from command line.
Hello
Is it better now? I think this is indeed very important, thank you for
letting me know.
Regarding the decoding h264 in a multithreadead manner, is there anyone
who can tell me if it's possible directly from libavocodec or shoud I do
some wrappers (as I orginally thought)?
I also called the function avcodec_thread_init function before
avcodec_open function, no improvement in time decoding frame, still > 50
ms.

Kind regards
Alex
Continue reading on narkive:
Loading...