Author Topic: Problem with aac format recording  (Read 916 times)

doka

  • Posts: 5
Problem with aac format recording
« on: 1 Aug '18 - 13:19 »
I can record HLS (Http Live Streaming) using "DOWNLOADPROC Delegate of BassHls.BASS_HLS_StreamCreateURL Method".
It works fine in "TS file" of station A.
However, I can record "AAC file" of station B, but noise occures in the connection part of aac file. (Chunks are every 5 seconds, and noise enters every 5 seconds).
TS file header:47 40 00 10 00 00 B0 0D 00 01 C1 00 00 00 01 E2....
AAC file header:49 44 33 04 00 00 00 00 00 3F 50 52 49 56 00 00....
Is there anything to consider?

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: Problem with aac format recording
« Reply #1 on: 1 Aug '18 - 13:59 »
If I understand correctly, you are using a DOWNLOADPROC callback to write a HLS stream to a file, and the written file contains a little noise every 5 seconds when you play it back? If so, please give the HLS stream URL to have a look at.

doka

  • Posts: 5
Re: Problem with aac format recording
« Reply #2 on: 1 Aug '18 - 15:47 »
High Ian.
That is exactly right.

This is the URL.
http://radiko.jp/
(https://rpaa.smartstream.ne.jp/so/playlist.m3u8?station_id=TBS&l=15&lsid=&type=b)
Request header requires
X-Radiko-AuthToken: ....<token>....
X-Radiko-AreaId: JP 13
but,It is only access from Japan?

This is no problem.
https://nhkradioakr1-i.akamaihd.net/hls/live/511633/1-r1/1-r1-01.m3u8

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: Problem with aac format recording
« Reply #3 on: 1 Aug '18 - 17:33 »
OK. If the stream is only available in Japan then I won't be able to try it myself and I may need to send you a debug BASSHLS version to get more info. First, can you show what your DOWNLOADPROC function looks like?

doka

  • Posts: 5
Re: Problem with aac format recording
« Reply #4 on: 2 Aug '18 - 11:39 »
Thanks Ian.
Here is a part of my code.
I referred some sample code, but I have not made any major changes.
bass.dll: 2.4.13.8
bass_aac.dll: 2.4.5.8
basshls.dll: 2.4.1.1
BASS.NET: 2.4.13.1
Code: [Select]
class Program
{
  ....
  static FileStream fs = null;
  static DOWNLOADPROC DownloadProc;
  static byte[] data;
  ....

  static void Main(string[] args)
  {
    init_BASS();
    init_Load();
    RadikoAuth();
   
    RecStart();
             
    Console.Write("Press any key to stop ...");
    Console.ReadKey(true);
    Closing();
  }

  static void init_BASS()
  {
    BassNet.Registration("....", "....");
    if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
    {
       Console.WriteLine("error");
    }
  }
       
  static void init_Load()
  {
    rdkMasterFileURL = @"https://......./";
    aacPlugIn = Bass.BASS_PluginLoad("bass_aac.dll");
    hlsPlugIn = Bass.BASS_PluginLoad("basshls.dll");
  }
       
  static void RecStart()
  {
    DownloadProc = new DOWNLOADPROC(HlsDownload);
    Bass.BASS_SetConfigString(BASSConfig.BASS_CONFIG_NET_AGENT, UA);
    recstream = BassHls.BASS_HLS_StreamCreateURL(uri, BASSFlag.BASS_DEFAULT, DownloadProc, IntPtr.Zero);
    if (recstream != 0)
    {
      Bass.BASS_ChannelSetAttribute(recstream, BASSAttribute.BASS_ATTRIB_VOL, 1f);
      Bass.BASS_ChannelPlay(recstream, false);
    }
    else
    {
      Console.WriteLine(Bass.BASS_ErrorGetCode());
    }
  }

  static void HlsDownload(IntPtr buffer, int length, IntPtr user)
  {
    if (fs == null)
    {
      fs = File.OpenWrite(DateTime.Now.ToString("hhmmss")+"output.aac");
    }
    if (buffer == IntPtr.Zero)
    {
      fs.Flush();
      fs.Close();
    }
    else
    {
      if (data == null || data.Length < length)
        data = new byte[length];
      Marshal.Copy(buffer, data, 0, length);
      fs.Write( data, 0, length );
    }
  }
           
  static void RadikoAuth()
  {
    ...get AuthToken and IndexFile(= uri) process...
  }

  static void Closing()
  {
    ...free BASS process...
  }
}

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: Problem with aac format recording
« Reply #5 on: 2 Aug '18 - 15:00 »
That looks mostly fine, but one small change you could make is to ignore the data when length=0 (that indicates HTTP headers):

Code: [Select]
    if (buffer == IntPtr.Zero)
    {
      fs.Flush();
      fs.Close();
    }
    else if (length > 0)
    {
      if (data == null || data.Length < length)
        data = new byte[length];
      Marshal.Copy(buffer, data, 0, length);
      fs.Write( data, 0, length );
    }

If the problem still happens then I will send you a debug BASSHLS version for more info.

doka

  • Posts: 5
Re: Problem with aac format recording
« Reply #6 on: 3 Aug '18 - 11:46 »
Thank you Ian.
I tried it according to your advice, but unfortunately I have not yet solved it.
There is no noise during playback, so every Bassdll has no problem at all.
So, I understand that it is only a matter of writing downloaded data to a file.
However, although there is no problem with the ts file, I do not know well that this aac file causes problems.

Code: [Select]
<MasterFile(m3u8)>
#EXTM3U
#EXT-X-VERSION:6
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=52973,CODECS="mp4a.40.5"
https://rpaa.smartstream.ne.jp/medialist....../

<IndexFile(m3u8)>
#EXTM3U
#EXT-X-VERSION:6
#EXT-X-TARGETDURATION:5
#EXT-X-ALLOW-CACHE:NO
#EXT-X-MEDIA-SEQUENCE:329099
#EXT-X-DISCONTINUITY-SEQUENCE:0
#EXT-X-PROGRAM-DATE-TIME:2018-08-03T13:16:40.000+09:00
#EXTINF:5.035,
https://rpaa.smartstream.ne.jp/segments/..../VMc64EHmoRKbYYUNiwoS.aac
#EXT-X-PROGRAM-DATE-TIME:2018-08-03T13:16:45.021+09:00
#EXTINF:4.992,
https://rpaa.smartstream.ne.jp/segments/..../teLDN3XbK8qeTGYtUF4U.aac
#EXT-X-PROGRAM-DATE-TIME:2018-08-03T13:16:50.021+09:00
#EXTINF:4.992,
https://rpaa.smartstream.ne.jp/segments/..../frVzuYjps7p7d7Rsbih7.aac

Code: [Select]
<a part of VMc64EHmoRKbYYUNiwoS.aac>

 ADDRESS   00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F   0123456789ABCDEF
------------------------------------------------------------------------------
 00000000  49 44 33 04 00 00 00 00 00 3F 50 52 49 56 00 00   ID3......?PRIV..
 00000010  00 35 00 00 63 6F 6D 2E 61 70 70 6C 65 2E 73 74   .5..com.apple.st
 00000020  72 65 61 6D 69 6E 67 2E 74 72 61 6E 73 70 6F 72   reaming.transpor
 00000030  74 53 74 72 65 61 6D 54 69 6D 65 73 74 61 6D 70   tStreamTimestamp
 00000040  00 00 00 00 1D 08 AA 99 00 FF F9 58 90 1F 22 5C   ...........X.."\
 00000050  21 1A 4F FE FF FF FF FE 82 0F 67 93 90 98 56 2A   !.O.......g...V*
 00000060  13 08 54 B0 CC 92 0C 96 34 83 17 31 A7 0C D5 55   ..T.....4..1...U
 00000070  86 C3 50 D6 15 03 99 A2 69 A8 D2 E5 F4 BE 56 1B   ..P.....i.....V.
 00000080  FA 1E 8C 0B 09 D8 37 82 25 E0 B8 EA 97 65 E8 0B   ......7.%....e..
 00000090  8A 65 8E 5F 5B D6 C9 6C 3C 27 33 1C 6C 67 70 67   .e._[..l<'3.lgpg
 000000A0  7B FA 0B A6 4F CB 5B 2C 26 27 35 6D F3 F7 5C 50   {...O.[,&'5m..\P
 000000B0  A3 A7 3B 46 5E 8F 93 87 14 1A 17 F7 7B 5A 32 CD   ..;F^.......{Z2.
 000000C0  BD B6 9F FA 8B 03 45 8B 1A 61 36 17 EA BB F9 40   ......E..a6....@
 000000D0  7A 3F F5 12 11 5B 95 9D 92 3B 88 8A A6 00 C3 F2   z?...[...;......
 000000E0  F9 81 A0 01 3C 93 0E 6D D0 8C 53 53 99 10 07 6E   ....<..m..SS...n
 000000F0  20 A2 40 B8 2A 00 5D 00 05 08 1E 02 2A 02 08 C0    .@.*.].....*...
 00000100  62 10 18 A4 00 D0 BF 64 86 98 13 B6 E8 78 D7 A1   b......d.....x..
 00000110  94 1E 52 C0 CC 17 F6 18 22 44 11 BA 8B D0 84 D0   ..R....."D......
 00000120  12 10 0B 84 00 29 CB CA 81 97 92 00 0D A0 0B 06   .....)..........
 00000130  F0 2E C8 3B 90 08 41 4A 25 10 E7 CF 81 E3 03 08   ...;..AJ%.......
 00000140  30 0E FF F9 58 90 20 A2 58 21 1A 55 1B 16 D3 05   0...X. .X!.U....
 00000150  42 40 EC 90 1B 08 0C 4C 95 97 AD B7 ED 28 00 5B   B@.....L.....(.[
 00000160  31 AE 2A 79 DF 09 42 B3 BA 8B C4 31 33 60 73 B9   1.*y..B....13`s.
 00000170  B4 FE 96 99 68 46 93 58 84 71 71 CF A0 95 8D 54   ....hF.X.qq....T
 00000180  BB 50 3A 18 91 46 73 20 1D 07 45 21 62 E6 E8 84   .P:..Fs ..E!b...
 00000190  63 85 72 33 D4 81 CE 75 59 89 A5 88 DB F1 B2 F1   c.r3...uY.......
 000001A0  EB F7 E5 59 B6 E1 39 C2 E0 E8 AA 8B 7C 09 69 7F   ...Y..9.....|.i.
 000001B0  91 E8 CD 34 C8 A7 CD F1 08 A2 BA 03 5E A9 5C CC   ...4........^.\.
 000001C0  DE 4A 07 07 80 F3 F3 97 62 C8 23 18 BE 0D 95 47   .J......b.#....G
 000001D0  E2 DE 45 15 7F 2C 3B F6 85 8E 5B 6C CF BC 42 F8   ..E..,;...[l..B.
 000001E0  E6 D6 44 21 2C 4F 13 FB A5 C9 1E 98 70 D4 4C C7   ..D!,O......p.L.
 000001F0  00 8C 88 42 FD F7 26 02 FC 62 8C B4 67 89 20 31   ...B..&..b..g. 1

Ian @ un4seen

  • Administrator
  • Posts: 21211
Re: Problem with aac format recording
« Reply #7 on: 3 Aug '18 - 14:46 »
Ah, I think I see what it is now. That stream contains ID3v2 tags at the start of each chunk, which are passed to the DOWNLOADPROC. But the BASS_AAC add-on doesn't expect to see ID3v2 tags in the middle of a file, so it looks like corruption and there's a discontinuation during playback of the recorded file. Here's a BASSHLS update that makes it optional to receive ID3v2 tags in a DOWNLOADPROC:

   www.un4seen.com/stuff/basshls.zip

The new option is called BASS_CONFIG_HLS_DOWNLOADPROC_TAGS, which can be set via BASS_SetConfig (0=disabled, 1=enabled). The default is 0 (disabled) so you shouldn't need to do anything to make things work in your case. Let me know if you do still have the problem with it.

doka

  • Posts: 5
Re: Problem with aac format recording
« Reply #8 on: 3 Aug '18 - 15:19 »
I tried it , the noise disappeared somewhere.
The problem was solved! :) :) :)

I really thank you Ian!!!