aws-samples / amazon-kinesis-video-streams-producer-embedded-c

Light-wight Amazon Kinesis Video Streams Producer SDK For FreeRTOS/Embedded Linux
Apache License 2.0
29 stars 18 forks source link

Does this sample support G711 format audio? #13

Closed studycc closed 2 years ago

studycc commented 3 years ago

I'm using kvs_linux sample to push video & audio to KVS now, but i found the audio format only support: typedef enum Mpeg4AudioObjectTypes { AAC_MAIN = 1, AAC_LC = 2, AAC_SSR = 3, AAC_LTP = 4, SBR = 5, AAC_SCALABLE = 6, } Mpeg4AudioObjectTypes_t; Can it possible to support G711(A-low or U-low) format? Or i must switch the audio format to AAC? Please take a look, thanks.

weichihl commented 3 years ago

For G711, you should use PCM codec private data to generate audio codec private data in MKV.

However the kvs console playback use HLS which is not support G711. So It would be difficult to implement and debug G711 because you cannot watch the video in realtime. You have to use MPEG-DASH or other aws cli commands like get-media to check if the video successfully uploaded.

studycc commented 3 years ago

You said the kvs console didn't support the G711 HLS right? But i had tired downloaded the MKV to local PC and played and found there was no sound in the video, was that normal?

weichihl commented 2 years ago

No, it's not normal. However it might be the decoder not supporting it. I tried few media players and found that not all media player support video with G711. The one that I tried and worked is media player classic. Maybe you can try it.

You can use some tools like mkvinfo to check if audio track set correctly. Or using mkvextract to extract audio raw data to see the bytes look like a G711 ones. If there is no sound, then all bytes should be zero. If there are still values in the audio raw data, then there might be issues from microphone or audio input. You can check it by put some random numbers in you g711 buffer when uploading to KVS and see if you can hear noise.

studycc commented 2 years ago

Thanks for you reply. I was using VLC media player, and i make sure about this player support the G711, because i had tried to save audio that capture by my IPC to a file and played it on my PC(G711 format, same with the format that i publish to the KVS), and it sounded normal. In the other hand, i will try use mkvinfo as your suggesst, but i want to check a thing with you: In the source code : /sample/kvs_linux/sample_config.h, there is a configuration named "AUDIO_MPEG_OBJECT_TYPE", what shoud i set when i put G711 audio to the KVS? I can't find any about G711 option in the enum that provided.

weichihl commented 2 years ago

Yes, you have to fill codec ID for G711. You can find a reference here: codec_mappings. It should be "A_PCM/INT/BIG", "A_PCM/INT/LIT", or "A_PCM/FLOAT/IEEE".

studycc commented 2 years ago

Sorry, i'm not very understand. Do you mean i should set codec type to "A_PCM/INT/BIG", "A_PCM/INT/LIT", or "A_PCM/FLOAT/IEEE" for G711? but i can't find these three options in the “https://wiki.multimedia.cx/index.php/MPEG-4_Audio#MPEG-4_Audio”.Does it means MPEG-4-Audio do not support the G711?

weichihl commented 2 years ago

Let me summarize the needed modifications.

  1. Modify codec name. You can modify code name in aac_file_loader.c. The codec name should be one of "A_PCM/INT/BIG", "A_PCM/INT/LIT", and "A_PCM/FLOAT/IEEE".

  2. Modify codec private data. You should replace Mkv_generateAacCodecPrivateData to Mkv_generatePcmCodecPrivateData.

I'm not sure if MPEG-4 support G711. I didn't try it before. What I had tried before is using the settings mentioned earlier and it worked.

studycc commented 2 years ago

I got it, so i think you might had tried to push PCM format audio file to the KVS successful, right? I will try on my side, thanks for your support.

studycc commented 2 years ago

Hello weichihl: I have tried to modify codec name to A_PCM/INT/LIT,but the KVS console (on the AWS server) shows: The type of the media is not supported or could not be determined from the media codec ids: (track 1: V_MPEG4/ISO/AVC), (track 2: A_PCM/INT/LIT).(And i saw the same error when set codec name to "A_PCM/INT/BIG" and “A_PCM/FLOAT/IEEE”)

weichihl commented 2 years ago

Please refer to previous comments. This is expected behavior. You have to download the video to verify the video and audio.

For G711, you should use PCM codec private data to generate audio codec private data in MKV.

However the kvs console playback use HLS which is not support G711. So It would be difficult to implement and debug G711 because you cannot watch the video in realtime. You have to use MPEG-DASH or other aws cli commands like get-media to check if the video successfully uploaded.

studycc commented 2 years ago

I had tried to download the stream from the kvs console, but it also shows error. It seems like the console does not support the G711 then it could not play on the console and could not download the stream.

studycc commented 2 years ago

There is another SDK about KVS that provided by AWS: https://github.com/awslabs/amazon-kinesis-video-streams-producer-c And i found this SDK support the ALAW(G711A) format for audio, and the codec name was “A_MS/ACM“, then i found i could play the media in the AWS's console directly. Then i tried to modify codec name to "A_MS/ACM" as well in embedded-c SDK and found could not play on the console or DASH(i had downloaded the test DASH player : https://github.com/aws-samples/amazon-kinesis-video-streams-media-viewer). But there was no any error message during play on the DASH viewer, and i could saw the video, but there was no any sound, so i though there was some limitation about push ALAW(G711A) format, but i didn't know how to resolve it...

weichihl commented 2 years ago

OK. Let me check it and get back to you soon.

studycc commented 2 years ago

Actually...i think it worked, set codec name to “A_MS/ACM“ and modify the API “Mkv_generateAacCodecPrivateData” to "Mkv_generatePcmCodecPrivateData", i just find i could download the stream from AWS console and play successful. i think i might set the wrong frquence or channelnumber? i don't know..but it works now. I will do more test. Thanks for your support.

weichihl commented 2 years ago

That's a great and thanks for your clarification. I'll close this issue. If you need further help, please feel free to reopen it or create a new one.