将FLV音频流与WAV背景音轨混合,然后转换为带有SoX和FFmpeg的MP3

问题描述:

我正在为合同规定的网站构建基于Flash的录制应用程序。它将记录的语音(通过SWF)流式传输到Red5服务器,然后使用FFmpeg和SoX的组合来编辑带有较低音量背景音乐轨道的人声音频。这一切都必须按需发生,也就是说,当用户“保存”他或她的人声录音时。将FLV音频流与WAV背景音轨混合,然后转换为带有SoX和FFmpeg的MP3

这是我将运行的示例命令。为了保护无辜者,名称已经改变。文件名描述了最终文件的作用:

sox --combine mix -p --no-show-progress --norm "|ffmpeg -i /usr/share/red5/webapps/audiorecorder/stream/SPOKEN_VOICE.flv -t wav pipe:1" /var/www/ufiles/music/BACKGROUND_MUSIC.wav - | ffmpeg -i pipe:1 /var/www/ufiles/recordings/COMPILED_AUDIO_RECORDING.mp3 

当我运行shell命令,这是发生了什么:

$ sox --combine mix -p --no-show-progress --norm "|ffmpeg -i audioStream_1321399534128_21.flv -ar 44100 -ac 2 -t wav pipe:1" wrong.wav - | ffmpeg -i pipe:1 ~/www/trauma101.com/compiled.mp3 
ffmpeg version N-34884-g7575980, Copyright (c) 2000-2011 the FFmpeg developers 
    built on Nov 15 2011 14:06:49 with gcc 4.4.5 
    configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libx264 --enable-x11grab --enable-libspeex 
    libavutil 51. 25. 0/51. 25. 0 
    libavcodec 53. 34. 0/53. 34. 0 
    libavformat 53. 20. 0/53. 20. 0 
    libavdevice 53. 4. 0/53. 4. 0 
    libavfilter 2. 48. 1/2. 48. 1 
    libswscale 2. 1. 0/2. 1. 0 
    libpostproc 51. 2. 0/51. 2. 0 
ffmpeg version N-34884-g7575980, Copyright (c) 2000-2011 the FFmpeg developers 
    built on Nov 15 2011 14:06:49 with gcc 4.4.5 
    configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libx264 --enable-x11grab --enable-libspeex 
    libavutil 51. 25. 0/51. 25. 0 
    libavcodec 53. 34. 0/53. 34. 0 
    libavformat 53. 20. 0/53. 20. 0 
    libavdevice 53. 4. 0/53. 4. 0 
    libavfilter 2. 48. 1/2. 48. 1 
    libswscale 2. 1. 0/2. 1. 0 
    libpostproc 51. 2. 0/51. 2. 0 
[libspeex @ 0x1e36b20] Missing Speex header, assuming defaults. 
Input #0, flv, from 'audioStream_1321399534128_21.flv': 
    Metadata: 
    novideocodec : 0 
    server   : Red5 Server 1.0.0 RC2 Rev: 4295 
    creationdate : Tue Nov 15 15:25:41 PST 2011 
    canSeekToEnd : true 
    Duration: 00:00:06.77, start: 0.000000, bitrate: 43 kb/s 
    Stream #0:0: Audio: speex, 16000 Hz, 1 channels, s16 
Invalid duration specification for t: wav 
sox FAIL formats: can't open input pipe `|ffmpeg -i audioStream_1321399534128_21.flv -ar 44100 -ac 2 -t wav pipe:1': premature EOF 

我认为这个问题是从FLV的转换而产生WAV在FFmpeg中,并且由于它被传入,导致整个过程失败。我总是得到这个持续时间的警告,但是当FFmpeg输出到一个.wav文件并且单独运行SoX命令时,我仍然可以从SoX获得一个WAV并手动将其转换为MP3。我想在一行中完成所有这些工作,在应用程序之间传输数据。

我该怎么办?

问题是在这里:

sox FAIL formats: can't open input pipe 

我假设你想sox从管道读,标准化和转换为wav。在这种情况下,mix参数是多余的。像这样的东西会这样做:

sox -p -t wav - gain -n | ...