LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ffmpeg stream and record at the same time (https://www.linuxquestions.org/questions/linux-newbie-8/ffmpeg-stream-and-record-at-the-same-time-4175646632/)

kzo81 01-21-2019 05:28 AM

ffmpeg stream and record at the same time
 
Hi,

I'd like to stream and record my laptop's audio input at the same time.

Streaming works perfectly with this ffserver config file:
Code:

HTTPPort 4444
HTTPBindAddress 0.0.0.0
MaxHTTPConnections 10
MaxClients 10
MaxBandwidth 1024
CustomLog -

<Feed audio.ffm>
File /tmp/audio.ffm
FileMaxSize 100M
</Feed>

##################################################################

<Stream audio>
Feed audio.ffm
Format mp2
Audiocodec libmp3lame
AudioBitRate 56
AudioChannels 2
AudioSampleRate 44100
NoVideo
#StartSendOnKey
</Stream>


<Stream stat.html>
Format status

#ACL allow localhost

FaviconURL http://pond1.gladstonefamily.net:8080/favicon.ico
</Stream>

Than I start ffserver:
Code:

ffserver -f /etc/ffserver.conf &
And start ffmpeg:

Code:

ffmpeg -f alsa -i hw:0,0 http://localhost:4444/audio.ffm | tee arecord -f cd -r 44100 -d 10 test1.wav
The streaming works nicely but tge test.wav file never gets created for some reason.

pan64 01-21-2019 05:55 AM

you cannot tee into arecord that way. And also I cannot think arecord can handle stdin like this.

kzo81 01-21-2019 06:44 AM

Quote:

Originally Posted by pan64 (Post 5951605)
you cannot tee into arecord that way. And also I cannot think arecord can handle stdin like this.

I know, that's an issue, thanks.
There must be a workaround for this. I'm testing with a 2 fifos now:
Code:

#!/bin/bash

s="streaming"
r="recording"

cd /tmp/ || exit 1

if [ -p "$s" ]; then
        rm "$s"
fi
mkfifo "$s"

if [ -p "$r" ]; then
        rm "$r"
fi
mkfifo "$r"

ffmpeg -f alsa -i hw:0,0 -f wav pipe:1 > "$s" -f wav pipe:1 > "$r"

exit 0

And then I would record and stream from the 2 fifos:

Code:

ffmpeg -i /tmp/recording -t 00:00:10 /tmp/test.wav
Code:

ffmpeg -i /tmp/streaming http://localhost:4444/audio.ffm
Here is the output of ffprobe for the 2 fifos:
https://pastebin.com/6MU6mYsA


All times are GMT -5. The time now is 06:23 AM.