如何从url录制aac音频?

Ger*_*Cas 2 ffmpeg audio-recording audio-streaming

我从似乎是 mp3 源的 URL 成功录制音频,发送此命令。

$ ffmpeg -y -t "00:01:00" -i $url1 -c copy url1.mp3
ffmpeg version N-93762-ge384f6f2f9 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7.4.0 (GCC)
configuration:
libavutil      56. 26.100 / 56. 26.100
libavcodec     58. 52.100 / 58. 52.100
libavformat    58. 27.103 / 58. 27.103
libavdevice    58.  7.100 / 58.  7.100
libavfilter     7. 50.100 /  7. 50.100
libswscale      5.  4.100 /  5.  4.100
libswresample   3.  4.100 /  3.  4.100
Input #0, mp3, from 'http://someurl1:1234':
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试从另一个似乎是 AAC 音频源的 URL 进行录制时,出现错误。

$ ffmpeg -y -t "00:01:00" -i $url2 -c copy url2.mp3
ffmpeg version N-93762-ge384f6f2f9 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 7.4.0 (GCC)
configuration:
libavutil      56. 26.100 / 56. 26.100
libavcodec     58. 52.100 / 58. 52.100
libavformat    58. 27.103 / 58. 27.103
libavdevice    58.  7.100 / 58.  7.100
libavfilter     7. 50.100 /  7. 50.100
libswscale      5.  4.100 /  5.  4.100
libswresample   3.  4.100 /  3.  4.100
Input #0, aac, from 'http://someurl2:1234':
Metadata:
    icy-notice1     : <BR>This stream requires <a href="http://www.winamp.com">Winamp</a><BR>
    icy-notice2     : SHOUTcast DNAS/posix(linux x64) v2.5.5.733<BR>
    icy-name        : some name
    icy-genre       : Talk
    icy-br          : 48
    icy-sr          : 22050
    icy-url         :
    icy-pub         : 0
    StreamTitle     : some title
Duration: N/A, bitrate: 47 kb/s
    Stream #0:0: Audio: aac (HE-AACv2), 44100 Hz, stereo, fltp, 47 kb/s
[mp3 @ 0x80003c280] Invalid audio stream. Exactly one MP3 audio stream is required.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
Stream #0:0 -> #0:0 (copy)
    Last message repeated 1 times
Run Code Online (Sandbox Code Playgroud)

如果我尝试将其另存为 aac 文件,我会收到以下消息:

$ ffmpeg -y -t "00:01:00" -i $url2 -c copy url2.aac
ffmpeg version N-93762-ge384f6f2f9 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7.4.0 (GCC)
  configuration:
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 52.100 / 58. 52.100
  libavformat    58. 27.103 / 58. 27.103
  libavdevice    58.  7.100 / 58.  7.100
  libavfilter     7. 50.100 /  7. 50.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
Input #0, aac, from 'http://someurl2:1234':
  Metadata:
    icy-notice1     : <BR>This stream requires <a href="http://www.winamp.com">Winamp</a><BR>
    icy-notice2     : SHOUTcast DNAS/posix(linux x64) v2.5.5.733<BR>
    icy-name        : some name
    icy-genre       : Talk
    icy-br          : 48
    icy-sr          : 22050
    icy-url         :
    icy-pub         : 0
    StreamTitle     : some title
  Duration: N/A, bitrate: 48 kb/s
    Stream #0:0: Audio: aac (HE-AACv2), 44100 Hz, stereo, fltp, 48 kb/s
Output #0, adts, to 'url2.aac':
  Metadata:
    icy-notice1     : <BR>This stream requires <a href="http://www.winamp.com">Winamp</a><BR>
    icy-notice2     : SHOUTcast DNAS/posix(linux x64) v2.5.5.733<BR>
    icy-name        : some name
    icy-genre       : Talk
    icy-br          : 48
    icy-sr          : 22050
    icy-url         :
    icy-pub         : 0
    StreamTitle     : some title
    encoder         : Lavf58.27.103
    Stream #0:0: Audio: aac (HE-AACv2), 44100 Hz, stereo, fltp, 48 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=       0kB time=00:00:00.00 bitrate=N/A speed=   0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)
Run Code Online (Sandbox Code Playgroud)

当URL中的源音频是aac时如何录制?有没有办法在录制之前识别它是mp3还是aac?提前致谢

Pam*_*ile 5

在您的第一个命令中,使用-c copy是错误的,因为您需要从aac (HE-AACv2)重新编码为mp3

请参阅 ffmpeg文档

特殊值副本(仅输出),指示流不被重新编码

我建议你尝试这个:

ffmpeg -y -t "00:01:00" -i [stream URL] -codec:a libmp3lame output.mp3
Run Code Online (Sandbox Code Playgroud)

不幸的是,我无法根据您在评论 ( ) 中提供的 URL 对其进行测试http://dreamsiteradiocp4.com:8120/: Connection refused,但它成功地与fmstream.org上列出的 AAC 流配合使用。

参考:video.stackexchange.com