LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   extract audio from streaming (https://www.linuxquestions.org/questions/linux-general-1/extract-audio-from-streaming-4175648199/)

drudox 02-13-2019 01:50 AM

extract audio from streaming
 
Hi everybody !
I would just know which is the easiest way to record part of audio from a streaming's film that is free in the channel site (Rai italy)

thanks in advance

ondoho 02-13-2019 06:23 AM

the easiest way is to simply download the stream and post-process it to extract audio only.
have you tried if you can do this with youtube-dl?

drudox 02-13-2019 06:27 AM

no I didn't but audacity look works well capturing the audio trace, there is no such a tool from command line ?

ondoho 02-13-2019 06:35 AM

youtube-dl is a cli tool.

it would help to give an example of what you are trying to capture. a link.

and why not stick with audacity if it works for you.

////// 02-13-2019 07:22 AM

i have used Streamripper to rip audio streams (IIRC i were using vlc to listen music and ripped it with Streamripper)

Quote:

[root@localhost vile]# dnf search streamripper
Last metadata expiration check: 0:14:24 ago on Wed 13 Feb 2019 03:07:28 PM EET.
========================================================= Name Exactly Matched: streamripper ==========================================================
streamripper.x86_64 : Shoutcast and icecast compatible streams recorder
[root@localhost vile]#
EDIT: it would help if you would post what u are trying to rip.
EDIT2: i missed that you were looking for commandline program, steamripper is _NOT_ commandline.

teckk 02-14-2019 02:16 PM

Quote:

there is no such a tool from command line ?
Let me find a free video that says it's free.....google-ing
Ok
"This video has been licensed to ShareTV for distribution purposes"

Example:
https://sharetv.com/shows/days_of_our_lives

Days of our Lives
Season 54, Episode #99 - S54 E99 Tuesday, February 12, 2019
https://sharetv.com/watch/1465778

Get the video, part that you desire.
Code:

#user agent
agent="Mozilla/5.0 (Windows NT 10.0; WOW_64; rv:64.0) Gecko/20100101 Firefox/64.0"

#Get segments 30-35 for this example
curl -A "$agent" https://nbchls-prod.nbcuni.com/tve-adstitch/647/19/02/08/3904302/F2AA39F23B6EF83F2DC2A9358F53F95DFC2073A6F67FB-[30-35].ts -o - >> DaysLives.ts

Check the video
Code:

ffprobe ~/DaysLives.ts
....
Input #0, mpegts, from '~/DaysLives.ts':
  Duration: 00:00:54.05, start: 262.694000, bitrate: 1619 kb/s
  Program 1
    Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 44100 Hz, stereo, fltp, 74 kb/s
    Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 960x540, Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc

Run it through ffmpeg to make a .mp4
Code:

ffmpeg -i DaysLives.ts -c:a copy -c:v copy DaysLives.mp4
Drop the video, keep just the audio
Code:

ffmpeg -i DaysLives.ts -vn -c:a copy DaysLives.m4a

ondoho 02-16-2019 06:07 AM

^ with youtube-dl it's just one command:
Code:

youtube-dl -x https://sharetv.com/watch/1465778

teckk 02-16-2019 12:53 PM

You are absolutely right @ondoho. I forget about youtube-dl away from youtube.
That works just fine after the video urls are dug out. And the formats available
are found. I've got so use to finding the .m3u8 for html5 videos and using curl
to concatenate segments to file. Thanks.

Code:

list=(
http://www.shoutfactorytv.com/dennis-the-menace/.......
http://www.shoutfactorytv.com/dennis-the-menace/.......
http://www.shoutfactorytv.com/dennis-the-menace/.......
)

agent="Mozilla/5.0 (Windows NT 10.0; WOW_64; rv:64.0) Gecko/20100101 Firefox/64.0"

num=1
for i in "${list[@]}"; do
    youtube-dl --user-agent "$agent" -f hls-1008 "$i" -o Dennis_"$num".mp4
    sleep 30
    num=$(($num + 1))
done

Footer:
Stop and click on a few ads on those pages so the website owner will
get some ad revenue. If you appreciate what they are doing and want
them to stay in business. The more ads you click on the better.

Sorry, I have a hard time feeling sorry for google if all the ads
don't get viewed for a youtube video. They have ads from one end
of the internet to the other. So does amazon.

ondoho 02-16-2019 04:10 PM

Quote:

Originally Posted by teckk (Post 5962929)
Code:

list=(
http://www.shoutfactorytv.com/dennis-the-menace/.......
http://www.shoutfactorytv.com/dennis-the-menace/.......
http://www.shoutfactorytv.com/dennis-the-menace/.......
)

agent="Mozilla/5.0 (Windows NT 10.0; WOW_64; rv:64.0) Gecko/20100101 Firefox/64.0"

num=1
for i in "${list[@]}"; do
    youtube-dl --user-agent "$agent" -f hls-1008 "$i" -o Dennis_"$num".mp4
    sleep 30
    num=$(($num + 1))
done


it must be a long time since you looked at youtube-dl's man page:
what you did up there, you don't need a script for:
  • it can take more than one URL on the command line
  • it defaults to downloading the highest possible quality anyhow
  • it has extensive formatting options for the output files

teckk 02-17-2019 08:30 AM

You are right again. I hadn't been using youtube-dl for anything other
that an occasional utube vid. And had not read man youtube-dl
for a good while.
Code:

-a, --batch-file FILE
--autonumber-start NUMBER

That is nifty for the web sites that it will work with.
Thanks again.

This gave me the segment playlist so that one could select which
segments to get if you want a partial video.
Code:

curl $(youtube-dl -g <url>)
I could then list the desired segments in a batch file and use the
-a switch. I think that you could also use regex.

The OP said "streaming's film" and "record part of audio"

Another way to get that audio would be to dump what's
coming through your sound card to file. Make a audio loopback device.
Look at modprobe snd-aloop, modifying your ~/.asoundrc
then dump the audio to file when you want.
Example:
Code:

ffmpeg -f alsa -i hw:1,1 -c:a aac -b:a 32k -vn capture.m4a

ondoho 02-17-2019 10:48 AM

thank you for recognizing the awesomeness of youtube-dl.
just one more comment from me: they are running the neverending race against media website maintainers always changing their sites to push us hackers out.
updates come in almost daily on their github repo.
it is one of the few applications i recommend to use a git version of, over anything that's in your repos.

Quote:

Originally Posted by teckk (Post 5963194)
Another way to get that audio would be to dump what's
coming through your sound card to file. Make a audio loopback device.
Look at modprobe snd-aloop, modifying your ~/.asoundrc

did you ever get that to work?:eek:
to me alsa is like a book with seven seals.

teckk 02-17-2019 11:43 AM

Quote:

did you ever get that to work?
Yes.

I turned on an older machine that I have, and it has one of
those sound devices that is hardware broken on purpose so that
you can't capture the stream through it. I think that a lot
of sound devices are like that.

This is an arch linux box with a nvidia chip for everything.

Code:

lspci | grep 'Audio'
00:05.0 Audio device: NVIDIA Corporation MCP61 High Definition Audio (rev a2)

So the answer is a virtual loopback device.

First make a config file for alsa.

~/.loop_asoundrc
Code:

pcm.!default {
  type asym
  playback.pcm "LoopAndReal"
  #capture.pcm "looprec"
  capture.pcm "hw:0,0"
}

pcm.looprec {
    type hw
    card "Loopback"
    device 1
    subdevice 0
}


pcm.LoopAndReal {
  type plug
  slave.pcm mdev
  route_policy "duplicate"
}


pcm.mdev {
  type multi
  slaves.a.pcm pcm.MixReale
  slaves.a.channels 2
  slaves.b.pcm pcm.MixLoopback
  slaves.b.channels 2
  bindings.0.slave a
  bindings.0.channel 0
  bindings.1.slave a
  bindings.1.channel 1
  bindings.2.slave b
  bindings.2.channel 0
  bindings.3.slave b
  bindings.3.channel 1
}


pcm.MixReale {
  type dmix
  ipc_key 1024
  slave {
    pcm "hw:0,0"
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

pcm.MixLoopback {
  type dmix
  ipc_key 1025
  slave {
    pcm "hw:Loopback,0,0"
    rate 48000
    #rate 44100
    periods 128
    period_time 0
    period_size 1024 # must be power of 2
    buffer_size 8192
  }
}

Then when I want to use it I simply copy that file to the right
place and modprobe snd-loop module.
Code:

mv ~/.loop_asoundrc ~/.asoundrc && sudo modprobe snd-aloop
Then capture what I want, to output format I want.
Code:

ffmpeg -f alsa -i hw:1,1 -c:a libmp3lame -b:a 32k -vn capture.mp3
Then when done
Code:

mv ~/.asoundrc ~/.loop_asoundrc && sudo modprobe -r snd-aloop
You need to start ffmpeg grabbing before you start the sound stream or no
capture.

And yes, I just checked all of that, it still works fine.

It's not the best way to get audio, to reencode something that has already
been encoded.

If you want you can
Code:

ffmpeg -f alsa -i hw:1,1 -c:a pcm_s16le capture.wav
Code:

mplayer capture.wav
.....
Opening audio decoder: [pcm] Uncompressed PCM audio decoder
AUDIO: 48000 Hz, 2 ch, s16le, 1536.0 kbit/100.00% (ratio: 192000->192000)
Selected audio codec: [pcm] afm: pcm (Uncompressed PCM)

Anyway, if all else fails, you can capture the stream going through
your sound device.

ondoho 02-18-2019 01:05 AM

Thanks a lot for this understandable explanation!
I'll make sure to bookmark it for future reference.

But while it is like that, you cannot listen to the sound, correct?

teckk 02-18-2019 06:11 AM

Yes, you can listen while you are recording. You have to start ffmpeg capturing
before starting the sound stream though, or you get a blank file.

To the OP:
Web browsers cache video in their cache directory. You can look for it there and
then dump the audio from it. For a segmented video it looks like Palemoon dumps
the segments in it's cache, look somewhere like:
Code:

~/.cache/moonchild productions/pale moon/123456.default/cache/entries/
Firefox does the same. Which means there is a plugin that will get the video
out of it's cache.

Any browser or python script using PyQt4-5, WebEngine, WebKit cache them too.
Code:

ffprobe ~/.cache/insp/Cache/f_0000c6
....
Input #0, mpegts, from '~/.cache/insp/Cache/f_0000c6':
  Duration: 00:00:11.33, start: 11.275433, bitrate: 1119 kb/s

Quote:

I would just know which is the easiest way
Which ever way listed in this thread that you like.
And then there is python with it's acres of modules for it.
mplayer and mpv will both dump streams to file with -dumpstream
and --stream-dump=. ffmpeg will dump a stream to file with -c:copy
youtube-dl dumps to file. curl supports regex in a url so that you
can continue to dump segments to file with the same connection. With wget
you will have to loop on the segments to get them all. mplayer supports playlists
with -playlist, you can combine that with -dumpstream -dumpfile.
Web browsers have plugins to get the video out of it's cache.
Or if you don't like any of that, dump the stream coming through the sound
card to file.

Happy dumping.


All times are GMT -5. The time now is 01:58 PM.