Using ffmpeg to record what comes from the web browser

Technical issues/questions of an intermediate or advanced nature.
User avatar
francois
Contributor
Contributor
Posts: 6433
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus nemesis
Location: Le printemps, le printemps, le printemps... ... l'hiver s'essoufle.

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.
Prendre son temps, profiter de celui qui passe.

donald
Full of knowledge
Full of knowledge
Posts: 2061
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: 6433
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus nemesis
Location: Le printemps, le printemps, le printemps... ... l'hiver s'essoufle.

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. ;)
Prendre son temps, profiter de celui qui passe.

donald
Full of knowledge
Full of knowledge
Posts: 2061
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: 6433
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus nemesis
Location: Le printemps, le printemps, le printemps... ... l'hiver s'essoufle.

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.
Prendre son temps, profiter de celui qui passe.

donald
Full of knowledge
Full of knowledge
Posts: 2061
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.

Kulle
Warlord
Warlord
Posts: 591
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

Re: Using ffmpeg to record what comes from the web browser

Post#7 by Kulle » 04 Feb 2019, 08:10

Hi Donald,
both commands

Code: Select all

ffmpeg -f alsa -ac 2 -i pulse output.wav
ffmpeg -f alsa -ac 2 -i pulse -acodec libmp3lame -ab 320k output.mp3
did not work for me.
The files output.wav and output.mp3 are generated.
But when you play the files:
no sound!
What can this be?

Kulle
Warlord
Warlord
Posts: 591
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

Re: Using ffmpeg to record what comes from the web browser

Post#8 by Kulle » 04 Feb 2019, 08:39

I also tried the command

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

When I play the file output.mkv:
Picture is available, but no sound

Kulle
Warlord
Warlord
Posts: 591
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

Re: Using ffmpeg to record what comes from the web browser

Post#9 by Kulle » 04 Feb 2019, 14:50

In porteus 3.2 I received the error message:
libavresample.so.3 no such file
although the module ffmpeg-3.2.4-x86.64.xzm was loaded and activated!
Is a newer version of ffmpeg needed?

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

Re: Using ffmpeg to record what comes from the web browser

Post#10 by donald » 04 Feb 2019, 16:54

Kulle wrote:
04 Feb 2019, 08:10
Hi Donald,
both commands

Code: Select all

ffmpeg -f alsa -ac 2 -i pulse output.wav
ffmpeg -f alsa -ac 2 -i pulse -acodec libmp3lame -ab 320k output.mp3
did not work for me.
The files output.wav and output.mp3 are generated.
But when you play the files:
no sound!
What can this be?
Hi Kulle

Yep, this was done in 3.2.2 - However, the strings do also work with
port 4.0 - tested in XFCE 64 bit - but we have to do some preparation
because of the "weird" behavior of pulseaudio.

HowTo
Click the volume icon > Audio Mixer - select the Recording tab -
(surprise) it is empty, now what?...leave it open.

Open a terminal > put in the command e.g
ffmpeg -f alsa -ac 2 -i pulse output.wav
but do not execute it yet.

Play a music file...while playing it, switch to the terminal and hit ENTER -
Ffmpeg start to record and the Recording tab in
the Audio mixer shows it.

As a last step click the device and select Monitor of ....
Image

Once this has been done Ffmpeg is able to record the sound.

btw
bear in mind, first play the sound, then start recording.. ;)

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Re: Using ffmpeg to record what comes from the web browser

Post#11 by Rava » 04 Feb 2019, 22:40

francois wrote:
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.
Try https://9xbuddy.app/ , you can download from almost any video hosting site using 9xbuddy.
Cheers!
Yours Rava

Kulle
Warlord
Warlord
Posts: 591
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

Re: Using ffmpeg to record what comes from the web browser

Post#12 by Kulle » 05 Feb 2019, 09:27

Hi Donald,
Many Thanks, it worked now.
I have noticed now:
ffmpeg is a very powerful tool, it can be used for many purposes

Kulle
Warlord
Warlord
Posts: 591
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

Re: Using ffmpeg to record what comes from the web browser

Post#13 by Kulle » 05 Feb 2019, 10:08

Hi Rava,
Thanks for pointing to 9xbud.com.
There are always new possibilities that you did not know before.

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Using ffmpeg to record what comes from the web browser

Post#14 by Rava » 05 Feb 2019, 10:23

^
I know, though, it is hard to say if every website they support is really being 100% on the legal side. Probably https://9xbuddy.app/ themselves not even get into trouble, since they do not host any files, they just provide you with the downloadable links to the video or audio files themselves. And I presume for the video or audio file hosting original site, it all looks like you are streaming the file through your browser, not downloading it. :unknown: But I am not sure about that, I have not seen any technical information on 9xbuddy that tells us one way or the other. Image

And with some music video files, I already encountered some on youtube where you can only download the mp3, but not the mp4 or any other video format, due to copyrighted material. If that makes sense I don't know, but in my case I wanted a mp4 with the added subtitles, cause I am not very good with Japanese and you hardly get a music player that would display subtitles for mp3. At least I don't know of any that does.
Cheers!
Yours Rava

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

Re: Using ffmpeg to record what comes from the web browser

Post#15 by donald » 05 Feb 2019, 16:01

Kulle wrote:
05 Feb 2019, 09:27
Hi Donald,
Many Thanks, it worked now.
Great
I have noticed now:
ffmpeg is a very powerful tool, it can be used for many purposes
One can find a lot of useful command examples to convert/extract audio/video
using FFmpeg.

FFmpeg also has a neat video player onboard, named FFplay -- already tried?
Example:

Code: Select all

guest@porteus:~$ ffplay -autoexit -nostats -hide_banner ./Downloads/video.mp4
where
-autoexit = close window after playing the video
-nostats = do not display statistics (in terminal)
-hide_banner = no version info etc.

Basic controls while playing:
  • q, ESC = quit
    f = toggle full screen
    p, SPC = pause
    m = toggle mute
    9, 0 = decrease and increase volume respectively
    s = activate frame-step mode
    left/right = seek backward/forward 10 seconds
    down/up = seek backward/forward 1 minute
    page down/page up = seek backward/forward 10 minutes
    right mouse click = seek to percentage in file corresponding to fraction of width
    left double-click = toggle full screen
This is just an example to get a first impression of FFplay.
I have set this player as default for video files in XFCE -- no terminal interaction required--
One can do this via "custom actions" or via "open with.." entry in thunar,
or for specified filetypes.

[setting for individual video filetypes:]
rightclick a video file (*.mpg, *.mp4, *.webM etc.)
> open with other application > Use a custom command > ffplay -autoexit -nostats %f
> check Use as default for this kind of file > done

If you want to add another (video) file type;
rightclick the file > open with other application and select FFplay
which is now in the list.

now you can simply (double) click the chosen file type to play it.. B)

you can add an icon if you wish:
open /home/guest/.local/share/applications/userapp-ffplay-....desktop in mousepad
and add Icon=gnome-mplayer (for example)

Post Reply