V
V
Vitaly2016-11-17 10:08:29
Programming
Vitaly, 2016-11-17 10:08:29

How to record a radio stream?

Hello, there is a task:
Continuous recording of the radio with splitting by the hour... Example:
We take a stream (For example: kpradio.hostingradio.ru:8000/russia.radiokp32.mp3 ) and record it permanently, while making a new file every hour. As a result ,
we
get
: breaking every hour. The gap itself can be done on a timer, but I thought that WPF is useless here and you can only get by with the console. Or perhaps there is a ready-made program to automate this process? I found such an example, but how to organize it into several threads at once (5-6) and make a break by the hour?

private void GetStream()
        {
            string now = DateTime.Now.ToLongTimeString();
            now = now.Replace(':', '-');
            fs = new FileStream(now + ".mp3", FileMode.Create);
            WebResponse response = WebRequest.Create(radioStation).GetResponse();
            // Получаем поток порциями в 65536 байтов
            using (Stream stream = response.GetResponseStream())
            {
                byte[] buffer = new byte[65536];
                int read;
                while ((state == true) && ((read = stream.Read(buffer, 0, buffer.Length)) > 0))
                {
                    long pos = fs.Position;
                    fs.Position = fs.Length;
                    fs.Write(buffer, 0, read);
                    fs.Position = pos;
                }
                fs.Flush();
            }
            response.Close();
            fs.Close();
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2016-11-17
@Zarom

Aside from the question, a shell solution under linux using ffmpeg and libmp3lame (adapted to the TS task). The original script writes video from IP cameras. The script is hung up on Cron with frequency of start "once an hour".

#!/bin/sh

STREAM_1_URL="http://kpradio.hostingradio.ru:8000/russia.radiokp32.mp3"
STREAM_2_URL="http://kpradio.hostingradio.ru:8000/russia.radiokp32.mp3"

#Generate paths
name="`date +%d-%m-%Y_%H.%M`"
BASE_PATH='/usr/audiostream'
DATE_PATH=`date +%Y/%m/%d`
STREAM_1_PATH="${BASE_PATH}/stream1/${DATE_PATH}"
STREAM_2_PATH="${BASE_PATH}/stream2/${DATE_PATH}"

##Start recording
#Stream 1
ffmpeg -i $STREAM_1 -codec:a libmp3lame $STREAM_1_PATH/${name}.mp3 <
/dev/null >/dev/null 2>/tmp/stream1.log &

#Stream 2
ffmpeg -i r$STREAM_2 -codec:a libmp3lame -t 610 $STREAM_1_PATH/${name}.mp3 <
/dev/null >/dev/null 2>/tmp/stream2.log &

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question