How To Use FFMPEG To Screencast from any Puppy Distro

How to do things, solutions, recipes, tutorials
Message
Author
Icyos

How To Use FFMPEG To Screencast from any Puppy Distro

#1 Post by Icyos »

Hi All

If you want to make videos in Puppy Linux to upload to youtube etc, then just open your terminal and bash the following code in.

#!/bin/sh
var="$(xrandr | grep '*')"
IFS=" "
set -- $var
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s $1 -r 25 -i :0.0 -sameq /root/test.avi

FFMPEG will now record your desktop and your Mic + Sound input as well, just use CTRL+C to end the recording.

This will give you a big file of nice quality, I would suggest you use FFConvert to shrink it down to a few megs so you can upload it quicker to youtube.

This means you dont need to install apps like xvdcap or recordmydesktop as you can do it straight from FFMPEG.
Last edited by Icyos on Tue 17 Jan 2012, 11:56, edited 1 time in total.

User avatar
Amgine
Posts: 231
Joined: Thu 22 Sep 2011, 01:27
Location: Washington State

Re: How To Use FFMPEG To Screencast from any Puppy Distro

#2 Post by Amgine »

Icyos wrote:Hi All

If you want to make videos in Puppy Linux to upload to youtube etc, then just open your terminal and bash the following code in..
Cool! I downloaded "Recordmydesktop" after watching one of your videos "Puppy Linux 5.28 Part 1 & Pt2" (Yesterday.) I will try this, thanks...

User avatar
Amgine
Posts: 231
Joined: Thu 22 Sep 2011, 01:27
Location: Washington State

#3 Post by Amgine »

I tried it, very nice. But I can not view the videos from Puppy, but I can from a different puppy build and my main OS. It does the same for "record my desktop" I am using 5.2.8 004

Icyos

#4 Post by Icyos »

Hi Buddy

I dont use the updates and I have no problems I am using 5.28 with no update added, and mplayer plays the original files back no problems at all.

I will add the 004 update and let you know. Thanks for your kind words re me youtube.

Icyos

#5 Post by Icyos »

Hi I have upgraded my 5.28 to 004 and my mplayer works just fine so please can you post some screen shots of your issue and I will try to help you resolve it.

User avatar
Amgine
Posts: 231
Joined: Thu 22 Sep 2011, 01:27
Location: Washington State

#6 Post by Amgine »

Thank you for the reply..

Here is a quick video.

http://flic.kr/p/bbUhca

User avatar
Amgine
Posts: 231
Joined: Thu 22 Sep 2011, 01:27
Location: Washington State

#7 Post by Amgine »

I have decided to re do my USB, I was hoping to know what went wrong but no big deal.

Thank you

Edit:

It works fine now.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#8 Post by Karl Godt »

I'm excited !

the ffmpeg line runs good on puppy 511 which had ffmpeg 0.5.2 installed without x11grab support .

i have compiled 7.11 and 9.1 with x11grab and can see the screen capture in mplayer . gxine-059 does not want to play .avi videos , but thats it .

will have to check it on Puppy 4 series where i could not get it to work until now .

***

this is the console output of v.7.11 which apparently compiled with a larger amount of warnings than 9.1 :

Code: Select all

./ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s 1000x900 -r 25 -i :0.0 -sameq /root/test2.avi
ffmpeg version 0.7.11, Copyright (c) 2000-2011 the FFmpeg developers
built on Jan 13 2012 23:04:34 with gcc 4.4.3
configuration: --disable-yasm --enable-sram --enable-pic --enable-zlib --enable-bzlib --enable-gpl --enable-x11grab

libavutil 50. 43. 0 / 50. 43. 0
libavcodec 52.123. 0 / 52.123. 0
libavformat 52.111. 0 / 52.111. 0
libavdevice 52. 5. 0 / 52. 5. 0
libavfilter 1. 80. 0 / 1. 80. 0
libswscale 0. 14. 1 / 0. 14. 1
libpostproc 51. 2. 0 / 51. 2. 0

[alsa @ 0x8dd2e00] Estimating duration from bitrate, this may be inaccurate
Input #0, alsa, from 'hw:0,0':
Duration: N/A, start: 4539.999955, bitrate: N/A
Stream #0.0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s

[x11grab @ 0x8dccfc0] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1000 height: 900
[x11grab @ 0x8dccfc0] shared memory extension found
[x11grab @ 0x8dccfc0] Estimating duration from bitrate, this may be inaccurate

Input #1, x11grab, from ':0.0':
Duration: N/A, start: 1326499552.323660, bitrate: 720000 kb/s
Stream #1.0: Video: rawvideo, bgra, 1000x900, 720000 kb/s, 25 tbr, 1000k tbn, 25 tbc
Incompatible pixel format 'bgra' for codec 'mpeg4', auto-selecting format 'yuv420p'

[buffer @ 0x8dcce60] w:1000 h:900 pixfmt:bgra tb:1/1000000 sar:0/1 sws_param:
[buffersink @ 0x8dd2d60] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x8dd48a0] w:1000 h:900 fmt:bgra -> w:1000 h:900 fmt:yuv420p flags:0x4

Output #0, avi, to '/root/test2.avi':
Metadata:
ISFT : Lavf52.111.0
Stream #0.0: Video: mpeg4, yuv420p, 1000x900, q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream #0.1: Audio: mp2, 48000 Hz, 2 channels, s16, 64 kb/s
Stream mapping:
Stream #1.0 -> #0.0
Stream #0.0 -> #0.1

Press [q] to stop, [?] for help
frame= 6 fps= 0 q=0.0 size= 573kB time=00:00:00.48 bitrate=9781.2kbits/s
frame= 11 fps= 10 q=0.0 size= 773kB time=00:00:01.05 bitrate=5998.5kbits/s
.
.
.

*****

:!:

User avatar
Dingo
Posts: 1437
Joined: Tue 11 Dec 2007, 17:48
Location: somewhere at the end of rainbow...
Contact:

#9 Post by Dingo »

I just compiled ffmpeg 0.9.1 in Puppy 3.01 but command is not working. it returns to me this error

Code: Select all

ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s 1000x900 -r 25 -i :0.0 -sameq /root/test2.avi
ffmpeg version 0.9.1, Copyright (c) 2000-2012 the FFmpeg developers
  built on Jan 14 2012 03:39:21 with gcc 4.1.2
  configuration: --prefix=/usr --disable-yasm --enable-sram --enable-pic --enable-zlib --enable-bzlib --enable-gpl --enable-x11grab
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 42. 4 / 53. 42. 4
  libavformat  53. 24. 2 / 53. 24. 2
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Unknown input format: 'alsa'
replace .co.cc with .info to get access to stuff I posted in forum
dropbox 2GB free
OpenOffice for Puppy Linux

User avatar
Amgine
Posts: 231
Joined: Thu 22 Sep 2011, 01:27
Location: Washington State

#10 Post by Amgine »

Dingo wrote:I just compiled ffmpeg 0.9.1 in Puppy 3.01 but command is not working. it returns to me this error

Code: Select all

ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s 1000x900 -r 25 -i :0.0 -sameq /root/test2.avi
ffmpeg version 0.9.1, Copyright (c) 2000-2012 the FFmpeg developers
  built on Jan 14 2012 03:39:21 with gcc 4.1.2
  configuration: --prefix=/usr --disable-yasm --enable-sram --enable-pic --enable-zlib --enable-bzlib --enable-gpl --enable-x11grab
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 42. 4 / 53. 42. 4
  libavformat  53. 24. 2 / 53. 24. 2
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Unknown input format: 'alsa'
Do you have alsa mixer installed?

User avatar
pemasu
Posts: 5474
Joined: Wed 08 Jul 2009, 12:26
Location: Finland

#11 Post by pemasu »

# ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s 1000x900 -r 25 -i :0.0 -sameq /root/test2.avi
ffmpeg version 0.9.1.git-5387f99 Copyright (c) 2000-2012 the FFmpeg developers
built on Jan 12 2012 00:48:53 with gcc 4.4.5

configuration: --prefix=/usr --cpu=i686 --enable-libmp3lame --enable-libx264 --enable-libfaac --enable-pthreads --enable-small --enable-postproc --enable-libvorbis --enable-gpl --enable-shared --enable-nonfree --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-debug --enable-bzlib --enable-zlib --enable-libspeex --enable-version3 --enable-runtime-cpudetect --enable-x11grab --enable-libdc1394 --enable-libschroedinger --enable-libtheora --enable-libxvid --enable-swscale --enable-libvpx
libavutil 51. 34.100 / 51. 34.100
libavcodec 53. 54.100 / 53. 54.100
libavformat 53. 29.100 / 53. 29.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 58.100 / 2. 58.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
libpostproc 51. 2.100 / 51. 2.100
[alsa @ 0x8065b20] Estimating duration from bitrate, this may be inaccurate
Input #0, alsa, from 'hw:0,0':
Duration: N/A, start: 1326535071.946597, bitrate: N/A
Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[x11grab @ 0x8060020] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1000 height: 900
[x11grab @ 0x8060020] shared memory extension found
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 139 (MIT-SHM)
Minor opcode of failed request: 4 (X_ShmGetImage)
Serial number of failed request: 11
Current serial number in output stream: 11

Second try:
# ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s 1280x800 -r 25 -i :0.0 -sameq /root/test2.avi
ffmpeg version 0.9.1.git-5387f99 Copyright (c) 2000-2012 the FFmpeg developers

X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 139 (MIT-SHM)
Minor opcode of failed request: 4 (X_ShmGetImage)
Serial number of failed request: 11
Current serial number in output stream: 11

Third try:
# ffmpeg -f alsa -:ac 2 -i hw:0,0 -f x11grab -s 1280x600 -r 25 -i :0.0 -sameq /root/test2.avi
[alsa @ 0x8065b20] Estimating duration from bitrate, this may be inaccurate
Input #0, alsa, from 'hw:0,0':
Duration: N/A, start: 1326535124.738427, bitrate: N/A
Stream #0:0: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s
[x11grab @ 0x8060020] device: :0.0 -> display: :0.0 x: 0 y: 0 width: 1280 height: 600
[x11grab @ 0x8060020] shared memory extension found
[x11grab @ 0x8060020] Estimating duration from bitrate, this may be inaccurate
Input #1, x11grab, from ':0.0':
Duration: N/A, start: 1326535124.834443, bitrate: 614400 kb/s
Stream #1:0: Video: rawvideo (BGRA / 0x41524742), bgra, 1280x600, 614400 kb/s, 25 tbr, 1000k tbn, 25 tbc
File '/root/test2.avi' already exists. Overwrite ? [y/N] y
Incompatible pixel format 'bgra' for codec 'mpeg4', auto-selecting format 'yuv420p'
[buffer @ 0x8065820] w:1280 h:600 pixfmt:bgra tb:1/1000000 sar:0/1 sws_param:
[buffersink @ 0x806a640] auto-inserting filter 'auto-inserted scale 0' between the filter 'src' and the filter 'out'
[scale @ 0x806aba0] w:1280 h:600 fmt:bgra -> w:1280 h:600 fmt:yuv420p flags:0x4
Output #0, avi, to '/root/test2.avi':
Metadata:
ISFT : Lavf53.29.100
Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1280x600, q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, 2 channels, s16, 128 kb/s
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo -> mpeg4)
Stream #0:0 -> #0:1 (pcm_s16le -> libmp3lame)
Press [q] to stop, [?] for help
[alsa @ 0x8065b20] ALSA buffer xrun.
frame= 414 fps= 25 q=0.0 Lsize= 11045kB time=00:00:16.56 bitrate=5463.8kbits/s dup=0 drop=16
video:10942kB audio:65kB global headers:0kB muxing overhead 0.343342%

So...it seems to be dependent of the selected screen resolution.

User avatar
pemasu
Posts: 5474
Joined: Wed 08 Jul 2009, 12:26
Location: Finland

#12 Post by pemasu »

# ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -r 30 -s 1366x700 -i :0.0 -aspect 16:9 -vcodec libx264 -threads auto screencast.avi

That works for me with ffmpeg-0.9.1 also. It produces good video quality due to libx264. Of course you need that lib to be installed...and that your ffmpeg has been compiled supporting it.

Output #0, avi, to 'screencast.avi':
Metadata:
ISFT : Lavf53.29.100
Stream #0:0: Video: h264 (H264 / 0x34363248), yuv420p, 1366x700 [SAR 215:236 DAR 29369:16520], q=-1--1, 30 tbn, 30 tbc
Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, 2 channels, s16, 128 kb/s
Stream mapping:
Stream #1:0 -> #0:0 (rawvideo -> libx264)
Stream #0:0 -> #0:1 (pcm_s16le -> libmp3lame)

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#13 Post by Karl Godt »

The commandline has to work , otherwise i get crazy error messages like
#Unable to find a suitable output format for '-f' :lol:

Screen resolution not being larger than actual is important as pemasu states .

The configure script autodetects headers in /usr/include .

If no alsa headers , no alsa !

I had the same with BSD kernel headers installed .
/usr/include/dev from it gave
/usr/include/dev/bktr/ioctl_meteor.h:185: error: expected specifier-qualifier-list before 'caddr_t'
which i could not solve .
renaming /usr/include/dev to /usr/include/dev.ffmpeg.backup
AND running ./configure $MYPARAMETERS again
did not find /usr/include/dev/ and now ffmpeg finally compiled .

The sound headers should be in /usr/include/alsa .
alsactl -v
alsactl version 1.0.20

would roughly correct show which alsa lib version is installed .

By getting /usr/include/dev out of the way i got ffmpeg to compile on 4.3 and x11grab working .
Also gxine-059 shows the avi format .

*****
./configure should show these parameters at the very end :

Code: Select all

Enabled indevs:
alsa			fbdev			v4l2
bktr			v4l			x11_grab_device
dv1394

Enabled outdevs:
alsa			sdl
I can't find a ./configure parameter to force alsa ie --enable-indev=alsa .

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#14 Post by Karl Godt »

funny thing is ffmpeg recognizes the output format because of the outputfile.extension .

Code: Select all

 ./ffmpeg -f x11grab -s 1023x767 -r 25 -i :0.0 -sameq /root/test3.flv
works for me to create a flash file .

gxine renders it 45degrees deformed .

FlashVideo File is approx. 50% larger in size than AudioVideoInterleave File .

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#15 Post by Karl Godt »

Hmmm . the codeline does not work for me in a script ... ffmpeg seems not to like ' ' spaces but tabs :

This test script works for me , i have also set filetype none in geany

Code: Select all

#!/bin/bash
#http://murga-linux.com/puppy/viewtopic.php?t=75139

#modprobe -l | grep nls |sed 's#\..*##g' |rev|cut -f 1 -d '/'|rev|while read m ; do modprobe -v $m;done

echo DBG $LANG
export LANG=C
echo DBG $LANG
var="$(xrandr | grep '*')"
echo DBG "$var"
IFS=' '
set -- $var
#export $@
export IFS=' '
echo DBG "IFS='$IFS'"
echo DBG $LANG

if [ -f ./ffmpeg -a -x ./ffmpeg ];then
FFMPEG='./ffmpeg'
elif [ -f /usr/local/bin/ffmpeg -a -x /usr/local/bin/ffmpeg ];then
FFMPEG='/usr/local/bin/ffmpeg'
else
FFMPEG=`which ffmpeg`
fi

ALSACAP=`$FFMPEG -formats 2>/dev/null|grep alsa`
X11GRABCAP=`$FFMPEG -formats 2>/dev/null|grep x11grab`

if [ ! "$ALSACAP" ];then
echo "ERROR , format 'alsa' not supported by $FFMPEG" ;exit 21
elif [ ! "$X11GRABCAP" ];then
echo "ERROR , format 'x11grab' not supported by $FFMPEG" ;exit 23
else
echo "OK , both formats supported by $FFMPEG : 'alsa' 'x11grab'"
fi

FFMPEGVERSION=`$FFMPEG -version 2>/dev/null |head -n1 |cut -f 2 -d ' '`
if [ ! "$FFMPEGVERSION" ];then
echo "ERROR , could not determine version of $FFMPEG"
exit 25;fi

c=0
if [ -e /root/test.$FFMPEGVERSION.avi ];then
c=$((c+1))
while [ -e /root/test.$FFMPEGVERSION.$c.avi ];do c=$((c+1));done
mv  /root/test.$FFMPEGVERSION.avi /root/test.$FFMPEGVERSION.$c.avi
fi
echo DBG "$@"
RESOLUTION="$1"
echo DBG $RESOLUTION

#xterm -hold -e
#vte -c
#sakura -e
echo
xterm -hold -e \
"$FFMPEG"\
	-f alsa -ac 2 -i hw:0,0\
	-f x11grab -s $RESOLUTION -r 25 -i :0.0\
	-sameq\
	/root/test.$FFMPEGVERSION.avi\
 && RV="$?" || RV="$?"
echo "$FFMPEG -f alsa -ac 2 -i hw:0,0 -f x11grab -s $RESOLUTION -r 25 -i :0.0 -sameq /root/test.$FFMPEGVERSION.avi
RETURNS : '$RV'"
exit $RV

User avatar
Amgine
Posts: 231
Joined: Thu 22 Sep 2011, 01:27
Location: Washington State

#16 Post by Amgine »

Is there a way to set up a short delay?

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#17 Post by Karl Godt »

Code: Select all

DELAY='5s'
sleep $DELAY
ffmpeg $MYVARS
OR

Code: Select all

k='';c=0
echo "Press any key to start ffmpeg"
until [ "$k" ] ; do
sleep 1s;c=$((c+1));echo -ne "\r$c "
read -t1 -n1 k
done
echo
ffmpeg $MYVARS

User avatar
Amgine
Posts: 231
Joined: Thu 22 Sep 2011, 01:27
Location: Washington State

#18 Post by Amgine »

Karl Godt wrote:

Code: Select all

DELAY='5s'
sleep $DELAY
ffmpeg $MYVARS
OR

Code: Select all

k='';c=0
echo "Press any key to start ffmpeg"
until [ "$k" ] ; do
sleep 1s;c=$((c+1));echo -ne "\r$c "
read -t1 -n1 k
done
echo
ffmpeg $MYVARS
Thank you! :)

Icyos

#19 Post by Icyos »

Hi All

This is my final entry after trying many variations out.

#!/bin/sh
var="$(xrandr | grep '*')"
IFS=" "
set -- $var
ffmpeg -f alsa -ac 2 -i hw:0,0 -f x11grab -s $1 -r 30 -i :0.0 -sameq /root/test.avi

I have found 30 frames to be the optimal and it produces the best visual quality, I have tested this on Puppies 5.25/5.28 & 5.31 Slacko, I have now moved to Slacko as my main operating system as I just love it to bits.

I hope all of you trying to get this to work with older Puppies are successful please contact me if I can help you in any way.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#20 Post by Karl Godt »

MORE frames = MORE MB

I had forgotten that it ran for 40 minutes and the avi file became 1,15GB ( -s 1280x1024 -r 25 ) :shock:

No luck with mp4 format either , still very very large .
Would be nice to get more extensions to work andor to decrease the filesize .

Could not get 9.1 compile on one Puppy431 installation but 7.11 and 8.10 compiled .

yasm >=0.8 needed to enable yasm and the source compiled fine but it seems not to have any effect .

Despite --enable-x11grab some other configure options disable it
and the binary does not include x11grab though ffmpeg -help says so .
The first time i compiled source i had to look into the /tmp/* folders for hints .
After installing several header and library packages it worked .

Post Reply