Capture screen and mic input using FFmpeg and ALSA

ffmpeg-logo

Hi there,

Recently, interesting commands appeared in commandlinefu about x11grab using ffmpeg. All are very interesting commands and they did what I expected in my Debian. But only one thing is missing. While creating a screencast, If I want to speak, that should appear in the capturing stream.

Thanks to alsa and ffmpeg, they have a way to capture my laptop’s in-built mic input. So I customized the existing commands which appeared in commandlinefu and created a small script.

#!/bin/sh
# simple command to capture your screen

OUTPUT="${1:?[usage] screencast.sh OUTPUTFILE}"

getgeometry()
{
        xwininfo -root |
        grep 'geometry' |
        awk '{print $2;}'
}

captureX11()
{
        ffmpeg -f alsa -itsoffset 00:00:02.000 -ac 2 -i hw:0,0 \
                -f x11grab -s $(getgeometry) -r 10 -i :0.0 \
                -sameq -f mp4 \
                -s wvga \
                -y "${OUTPUT}"
}

captureX11

Finally I created my first screencast using ‘screencast.sh’ script. Here is the video

Atlast, I don’t want to install one more app to create screencast. FFmpeg is with me !!!

Aircel GPRS with Linux and Bluetooth

Ah!! finally, I bought a new mobile. its Nokia 2730c,

But my struggle started here with my service provider, My main reason to bought this particular phone is to get Internet access at my home. So that I can #join at anytime. But it was a tough ask with Aircel.

At first, when I inserted my SIM card, lot of activity happens and I got a message from Aircel saying to save a settings message. After that, I received a settings message saying “Pocket Internet”. I already know that there is a service provided by Aircel called “Pocket Internet” to access internet in mobile, But when I searched more about “Pocket Internet”, I came to know that I can’t connect to my PC and browse, because “Pocket Internet” is a WAP service.

So I called CustCare, but as I expected, those guys are dump about what I’m talking, First I asked whether I can connect my PC and use “Pocket Internet” for browsing? but no clear answers from them. After 2 calls, I called one more time, this time, CustCare person informed that I need to configure my phone to access “Aircel GPRS”, he also informed that if your phone is capable, the settings would have already came.

I was shocked, because my Nokia 2730c is a 3G capable mobile, but I didn’t receive ‘Aircel GPRS’ settings, only I received “Pocket Internet” settings. I was nearly at the edge to change my provider. Whenever I call them, they are not at all listening to my words, they simply saying that my mobile is not capable. I got frustrated and stopped calling them, after 2 days, I called them thinking that it would be my last call, thankfully that person responded me in a positive manner, they already have my call history and he is able to understand what my problem is, The exact problem is simple,

“Aircel didn’t have settings for Nokia 2730c, because its a new model”

So, I didn’t receive “Aircel GPRS” settings when I inserted my SIM. Thanks to that person, he raised a ticket to their technical team, and they rectified this issue next day itself. Day after that day, I received “Aircel GPRS” settings. and connected to “Nokia OVI store” using “Aircel GPRS” Access Point in my mobile.

First phase of this struggle is over, here comes the next,

It would have been a simple task if I’m a windows user, connect my mobile to laptop, use PC suite to dial-up and access internet, thats all. But, Its a task up to me to get the ppp settings from Aircel. Thankfully Ubuntu guys have a very good writeup for aircel. It makes easy for me to use ‘pppconfig’ and create ‘/etc/ppp/peers/aircel’ file and ‘etc/chatscripts/aircel’ file. Here is the steps,

root@Debian:/etc/ppp/peers# aptitude install pppconfig
root@Debian:/etc/ppp/peers# pppconfig aircel
select "Create a Connection named aircel" and select "Ok"
select "Dynamic DNS" and select "Ok"
select "PAP" and select "Ok"
give username as "Aircel" and select "Ok"
give password as "aircel" and select "Ok"
pppconfig will give speed of your modem as 115200, use this default
Select "Tone" and select "Ok"
give phone number as *99***1#
Next step will be giving the modem name, I'm going to use /dev/rfcomm0 (bluetooth serial device) so I selected "No" and gave '/dev/rfcomm0' as my modem name.
Finally select "Finished Write files and return to main menu", two files will be created, only will be '/etc/ppp/peers/aircel' and another one is '/etc/chatscripts/aircel'
select "Quit"

Now, I need to modify the ‘/etc/chatscripts/aircel’ file and insert the following lines after ‘ATZ’ init line. These two lines specifies Aircel’s APN aka Access Point Name which is ‘aircelgprs.pr’, I think if you are using Aircel’s postpaid service, then you need to give ‘aircelgprs.po’. But check your mobile’s “Aircel GPRS” settings first, it will clearly tell Access Point Name.

'' "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
'' AT+CGDCONT=1,"IP","aircelgprs.pr"

Here is the final /etc/chatscripts/aircel

# This chatfile was generated by pppconfig 2.3.18.
# Please do not delete any of the comments.  Pppconfig needs them.
#
# ispauth PAP
# abortstring
ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT DELAYED
# modeminit
'' "ATZ"
'' "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0"
'' AT+CGDCONT=1,"IP","aircelgprs.pr"
# ispnumber
OK-AT-OK "ATDT*99***1#"
# ispconnect
CONNECT \d\c
# prelogin

# ispname
# isppassword
# postlogin

# end of pppconfig stuff

And here is the final /etc/ppp/peers/aircel

# This optionfile was generated by pppconfig 2.3.18.
#
#
hide-password
noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/aircel"
debug
/dev/rfcomm0
115200
defaultroute
noipdefault
user "Aircel"
remotename aircel
ipparam aircel

usepeerdns

Now, if you connected your mobile through wire, your mobile will be accessable through any one of /dev/ttyS* or /dev/ttyUSB* devices, you can start ‘pon aircel’ and get connected to net. But I’m going to setup bluetooth, so here is the steps,

root@Debian:/etc/ppp/peers# hcitool scan
root@Debian:/etc/ppp/peers# BDADDR="[type your mobile's bluetooth address here, it will be displayed as the output of above command]"
root@Debian:/etc/ppp/peers# hcitool cc "${BDADDR}"; hcitool auth "${BDADDR}"

Now, your authentication-agent will ask for pin and all, go through it and create a pair. Next step will be detecting the channel to setup a rfcomm bind,

root@Debian:/etc/ppp/peers# sdptool browse "${BDADDR}" | less

In the above command, there will be lot of services your mobile will provide to you, each will have seperate rec handle, name etc., some of them like obex push, obex file transfer, Headset Gateway, Phonebook access etc. You need to see ‘Dial-up Networking’ and note down the RFCOMM channel number. In my mobile, the RFCOMM channel number is ‘1’. So here is the step to bind your mobile’s RFCOMM channel with /dev/rfcomm0 device

root@Debian:/etc/ppp/peers# CHANNEL="[Type your mobile's Dial-up service's RFCOMM channel number]"
root@Debian:/etc/ppp/peers# rfcomm bind rfcomm0 "${BDADDR}" "${CHANNEL}"

‘bind’ will create a communication line between your mobile and /dev/rfcomm0 device. But it will not connect to your mobile until it is opened for reading/writing. You can check current rfcomm devices using following command

root@Debian:/etc/ppp/peers# rfcomm
rfcomm0: 3C:F7:2A:46:19:AB channel 1 clean
root@Debian:/etc/ppp/peers#

Now everything was setup, all you need to do is, type the following command

root@Debian:/etc/ppp/peers# pon aircel

it will start pppd and try to connect, but it will not throw any information in your terminal, you need to watch the activities through ‘tail -f /var/log/syslog’. If everything goes fine, it will establish ppp connection to Aircel. Here is the whole log

Mar 23 02:02:00 Debian bluetoothd[2072]: link_key_request (sba=00:1A:6B:E3:80:D8, dba=3C:F7:2A:46:19:AB)
Mar 23 02:02:01 Debian chat[31061]: abort on (BUSY)
Mar 23 02:02:01 Debian chat[31061]: abort on (NO CARRIER)
Mar 23 02:02:01 Debian chat[31061]: abort on (VOICE)
Mar 23 02:02:01 Debian chat[31061]: abort on (NO DIALTONE)
Mar 23 02:02:01 Debian chat[31061]: abort on (NO DIAL TONE)
Mar 23 02:02:01 Debian chat[31061]: abort on (NO ANSWER)
Mar 23 02:02:01 Debian chat[31061]: abort on (DELAYED)
Mar 23 02:02:01 Debian chat[31061]: send (ATZ^M)
Mar 23 02:02:01 Debian chat[31061]: send (ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0^M)
Mar 23 02:02:02 Debian chat[31061]: send (AT+CGDCONT=1,"IP","aircelgprs.pr"^M)
Mar 23 02:02:02 Debian chat[31061]: expect (OK)
Mar 23 02:02:02 Debian chat[31061]: ATZ^M^M
Mar 23 02:02:02 Debian chat[31061]: OK
Mar 23 02:02:02 Debian chat[31061]:  -- got it
Mar 23 02:02:02 Debian chat[31061]: send (ATDT*99***1#^M)
Mar 23 02:02:02 Debian chat[31061]: expect (CONNECT)
Mar 23 02:02:02 Debian chat[31061]: ^M
Mar 23 02:02:02 Debian chat[31061]: ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0^M^M
Mar 23 02:02:02 Debian chat[31061]: OK^M
Mar 23 02:02:02 Debian chat[31061]: AT+CGDCONT=1,"IP","aircelgprs.pr"^M^M
Mar 23 02:02:02 Debian chat[31061]: OK^M
Mar 23 02:02:04 Debian chat[31061]: ATDT*99***1#^M^M
Mar 23 02:02:04 Debian chat[31061]: CONNECT
Mar 23 02:02:04 Debian chat[31061]:  -- got it
Mar 23 02:02:04 Debian chat[31061]: send (\d)
Mar 23 02:02:05 Debian pppd[31042]: Serial connection established.
Mar 23 02:02:05 Debian pppd[31042]: using channel 9
Mar 23 02:02:05 Debian pppd[31042]: Using interface ppp0
Mar 23 02:02:05 Debian pppd[31042]: Connect: ppp0 <--> /dev/rfcomm0
Mar 23 02:02:05 Debian pppd[31042]: rcvd [LCP ConfReq id=0x0 <auth pap> <mru 1500> <asyncmap 0xa0000>]
Mar 23 02:02:05 Debian pppd[31042]: sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0xcd88324c> <pcomp> <accomp>]
Mar 23 02:02:05 Debian pppd[31042]: sent [LCP ConfAck id=0x0 <auth pap> <mru 1500> <asyncmap 0xa0000>]
Mar 23 02:02:05 Debian pppd[31042]: rcvd [LCP ConfRej id=0x1 <magic 0xcd88324c> <pcomp> <accomp>]
Mar 23 02:02:05 Debian pppd[31042]: sent [LCP ConfReq id=0x2 <asyncmap 0x0>]
Mar 23 02:02:05 Debian pppd[31042]: rcvd [LCP ConfAck id=0x2 <asyncmap 0x0>]
Mar 23 02:02:05 Debian pppd[31042]: sent [LCP EchoReq id=0x0 magic=0x0]
Mar 23 02:02:05 Debian pppd[31042]: sent [PAP AuthReq id=0x1 user="Aircel" password=<hidden>]
Mar 23 02:02:05 Debian pppd[31042]: rcvd [LCP EchoRep id=0x0 magic=0x0]
Mar 23 02:02:05 Debian pppd[31042]: rcvd [PAP AuthAck id=0x1 ""]
Mar 23 02:02:05 Debian pppd[31042]: PAP authentication succeeded
Mar 23 02:02:05 Debian pppd[31042]: sent [CCP ConfReq id=0x1 <deflate 15> <deflate(old#) 15> <bsd v1 15>]
Mar 23 02:02:05 Debian pppd[31042]: sent [IPCP ConfReq id=0x1 <compress VJ 0f 01> <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
Mar 23 02:02:05 Debian pppd[31042]: rcvd [IPCP ConfReq id=0x0 <addr 10.6.6.6>]
Mar 23 02:02:05 Debian pppd[31042]: sent [IPCP ConfAck id=0x0 <addr 10.6.6.6>]
Mar 23 02:02:05 Debian pppd[31042]: rcvd [LCP ProtRej id=0x0 80 fd 01 01 00 0f 1a 04 78 00 18 04 78 00 15 03 2f]
Mar 23 02:02:05 Debian pppd[31042]: Protocol-Reject for 'Compression Control Protocol' (0x80fd) received
Mar 23 02:02:06 Debian pppd[31042]: rcvd [IPCP ConfRej id=0x1 <compress VJ 0f 01>]
Mar 23 02:02:06 Debian pppd[31042]: sent [IPCP ConfReq id=0x2 <addr 0.0.0.0> <ms-dns1 0.0.0.0> <ms-dns3 0.0.0.0>]
Mar 23 02:02:06 Debian pppd[31042]: rcvd [IPCP ConfNak id=0x2 <addr 10.1.6.46> <ms-dns1 202.148.202.3> <ms-dns3 202.148.202.4>]
Mar 23 02:02:06 Debian pppd[31042]: sent [IPCP ConfReq id=0x3 <addr 10.1.6.46> <ms-dns1 202.148.202.3> <ms-dns3 202.148.202.4>]
Mar 23 02:02:06 Debian pppd[31042]: rcvd [IPCP ConfAck id=0x3 <addr 10.1.6.46> <ms-dns1 202.148.202.3> <ms-dns3 202.148.202.4>]
Mar 23 02:02:06 Debian pppd[31042]: Cannot determine ethernet address for proxy ARP
Mar 23 02:02:06 Debian pppd[31042]: local  IP address 10.1.6.46
Mar 23 02:02:06 Debian pppd[31042]: remote IP address 10.6.6.6
Mar 23 02:02:06 Debian pppd[31042]: primary   DNS address 202.148.202.3
Mar 23 02:02:06 Debian pppd[31042]: secondary DNS address 202.148.202.4
Mar 23 02:02:06 Debian pppd[31042]: Script /etc/ppp/ip-up started (pid 31085)
Mar 23 02:02:07 Debian pppd[31042]: Script /etc/ppp/ip-up finished (pid 31085), status = 0x0
Mar 23 02:07:05 Debian pppd[31042]: Terminating on signal 15
Mar 23 02:07:05 Debian pppd[31042]: Connect time 5.0 minutes.
Mar 23 02:07:05 Debian pppd[31042]: Sent 70568 bytes, received 287622 bytes.
Mar 23 02:07:05 Debian pppd[31042]: Script /etc/ppp/ip-down started (pid 32324)
Mar 23 02:07:05 Debian pppd[31042]: sent [LCP TermReq id=0x3 "User request"]
Mar 23 02:07:05 Debian pppd[31042]: rcvd [LCP TermAck id=0x3]
Mar 23 02:07:05 Debian pppd[31042]: Connection terminated.
Mar 23 02:07:05 Debian pppd[31042]: Script /etc/ppp/ip-down finished (pid 32324), status = 0x0
Mar 23 02:07:05 Debian pppd[31042]: Exit.

To stop your pppd, type the following command

root@Debian:/etc/ppp/peers# poff aircel

Finally, once you finished with pppd, release the rfcomm0 bind using the following command,

root@Debian:/etc/ppp/peers# rfcomm release rfcomm0

Thats it. Enjoy old style ‘pppd’ :) Always old tech rules !!!