Using ffmpeg to record what comes from the web browser

Technical issues/questions of an intermediate or advanced nature.
Post Reply
User avatar
francois
Contributor
Contributor
Posts: 5226
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus artix
Location: C'est l'hiver: la neige soudainement est là à Montréal.

Using ffmpeg to record what comes from the web browser

Post#1 by francois » 07 Jan 2018, 14:19

I am trying to record with ffmpeg an interview from a radio station here in Montreal:

Here is the data for my card:

Code: Select all

fl@fl-Satellite-Z930:~$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC269VC Analog [ALC269VC Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
fl@fl-Satellite-Z930:~$


I have some recording, but only my breathing and the noises that I make with:

Code: Select all

ffmpeg -f alsa -i hw:0 -t 30 out.wav
I would like the music from my web browser to be recorded. Any suggestion appreciated.
Thanks.
Carpe diem.

donald
Full of knowledge
Full of knowledge
Posts: 1259
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

Using ffmpeg to record what comes from the web browser

Post#2 by donald » 07 Jan 2018, 16:24

If your cpu is powerful enough, try:

Code: Select all

guest@porteus:~/Public$  ffmpeg -f alsa -ac 2 -i pulse output.wav
or as mp3:

Code: Select all

guest@porteus:~/Public$  ffmpeg -f alsa -ac 2 -i pulse -acodec libmp3lame -ab 320k output.mp3
HowTo:
open a terminal, paste in the ffmpeg command line but do not execute yet
start playing the source > execute the command line....

Tested:
recorded the audio while playing a youtube video in Pale Moon. B)

User avatar
francois
Contributor
Contributor
Posts: 5226
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus artix
Location: C'est l'hiver: la neige soudainement est là à Montréal.

Using ffmpeg to record what comes from the web browser

Post#3 by francois » 09 Jan 2018, 02:42

Hello donald. Thanks for responding promptly. I am recording now with your help. I am very happy with that possibility. My son will be very happy to listen to that recording of that researcher that we have here in Montreal, a specialist in artificial intelligence, Joshua Bengio. :D

By any mean, would you have in the same vein to record clips or video, that is video and sound? I hope that I do not abuse. ;)
Carpe diem.

donald
Full of knowledge
Full of knowledge
Posts: 1259
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

Using ffmpeg to record what comes from the web browser

Post#4 by donald » 09 Jan 2018, 09:19

Hi francois

For recording the whole screen (audio + video) you can use (e.g.)

Code: Select all

ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 25 -s 1360x768 -i :0.0 -vcodec libx264 -preset ultrafast output.mkv
Most important is the resolution.
If you want to capture your entire desktop, then you have to enter the screen resolution you’re working at.
Note, in 3.2.2 (32 bit) the h264 encoder does not work correct - install a better version.
(x264-20170225-i486-1_slonly.xzm in my case)

It is also possible to capture a specific area of the screen by specifying a capture size that is smaller than the resolution.
You can offset this area by adding +X,Y after :0.0 like this: -s 800x600 -i :0.0+200,100
This will capture a rectangle of 800×600 with an X offset of 200 pixels and a Y offset of 100 pixels.
(the offset starting point is the top-left corner of the screen -- if you offset the capture area out of the screen
it will give you an error)

How to get the exact size and coordinates of a specific window I want to capture:
Use a command called “xwininfo“. -- get the module via USM from slackware (37 kB)
run this command and then click on the window that you want to capture.
It will then print the window information to the terminal - what you need are the following lines:

Code: Select all

Absolute upper-left X:
Absolute upper-left Y:
Width:
Height:
If the command, for example, prints:

Code: Select all

Absolute upper-left X: 383
Absolute upper-left Y: 184
Width: 665
Height: 486
Then, you will adapt it to FFmpeg like this:

Code: Select all

-s 664x486 -i :0.0+383,184
Note that 664 is used instead of 665 for the width since ffmpeg only accepts resolutions divisible by 2.

This command line will print the information you’ll be needing:

Code: Select all

xwininfo | grep -e Width -e Height -e Absolute
run the command and click the window you need to capture to get the info you need.

It's always possible to create more complicated/sophisticated ffmpeg command lines.
Personally i would try to (somehow) download the original source file rather than to capture the screen.

User avatar
francois
Contributor
Contributor
Posts: 5226
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus artix
Location: C'est l'hiver: la neige soudainement est là à Montréal.

Using ffmpeg to record what comes from the web browser

Post#5 by francois » 09 Jan 2018, 10:00

In fact, I would prefer to download the original source file. I imagine that it should provide the maximum video resolution which is not limited to the screen that you have on the linux box. You would have a way to find or dig the original source file, whether from the web?
Thanks.
Carpe diem.

donald
Full of knowledge
Full of knowledge
Posts: 1259
Joined: 17 Jun 2013, 13:17
Distribution: Porteus 3.2.2 XFCE 32bit
Location: Germany

Using ffmpeg to record what comes from the web browser

Post#6 by donald » 09 Jan 2018, 10:30

Well, it depends - maybe, maybe not.
youtube-dl might be able to fetch the file.
If not, rightclick the (web) page select "view page info / view page source",
dig through the lines to find a address/path of the file you want.
If you find one, try to download the file with wget.

Post Reply