Archive for December, 2008

ffmpeg – capture screenshot from a video file

1
ffmpeg -i /my_video_file_dir/video.flv -y -f image2 -ss 8 -sameq -t 0.001 -s 320*240 /image_dir/screenshot.jpg

320*240 : image dimension is 320 pixels width and 240 pixels height
-ss 8 : screenshot will be taken at 8 second after video starts.

  • Share/Save/Bookmark

Linux ffmpeg audio conversion – MP3 to FLV

Want to play MP3 files on your website? The best and most common way is using flash video file which compress audio and video better for internet use like YouTube. Here is the instruction I used ffmpeg to convert MP3 to FLV file.

ffmpeg – a program that allow convert audio in numerous formats.

Installing ffmpeg
edit / etc/yum.repos.d/CentOS-Base.repo , add following lines at the end of file

1
2
3
4
[dag]
name=Dag RPM Repository for Centos
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
enabled=1

run this command

1
yum install ffmpeg

Convert MP3 to FLV

1
ffmpeg -y -i /home/song.mp3 -f flv -acodec mp3 -ab 64 -ac 1 /home/song.flv
  • Share/Save/Bookmark

Sending text message (SMS) to your mobile phone from your server via GMail SMTP using PHP

In some cases I need to send a warning message or a notice to my cell phone when certain tasks are done or caught some unexpected errors by server cronjob. This is a quite exciting feature, I don’t need to sit in front of my computer to do the boring monitoring job.

With some googling, there is something called Email to SMS Gateway (here is the gateway list) that allow you to send an Email to phone company, and phone company automatically delivery the Email content as text message to the cell phone owner. In my case, for example, I need to send SMS to cell phone number 416-999-9999 and phone carrier is Rogers. Regarding to the gateway list, means I should send Email to 4169999999@pcs.rogers.com

My first thought about sending out Email is using simple PHP mail() function. Unluckily, the Email sent out couldn’t pass phone carrier’s spam filter (Not exactly know what happened, my guess is my domain can’t pass Reverse DNS checking).

With some googling again for sloving send out Email issue, I found out GMail accounts can actually be used as an SMTP server. If this is working, that means phone carrier directly receive email from GMail (email from GMail won’t be spam, right?).

Here’s a code snippet on how to do it. In the code, I used PHPMailer class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 
require("class.phpmailer.php");
 
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
 
$mail->Username = "YOUR_GMAIL_ACCOUNT@gmail.com"; // SMTP username
$mail->Password = "YOUR_GMAIL_LOGIN_PASSWORD"; // SMTP password
 
$from_email = "example@example.com"; //Reply to this email ID
$to_email="4169999999@pcs.rogers.com"; // Recipients email ID
$to_name="to_this_name"; // Recipient's name
 
$mail->From = $from_email;
$mail->FromName = "from_this_name";
$mail->AddAddress($to_email,$to_name=);
$mail->AddReplyTo($from_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
 
$mail->Subject = "TEXT_MESSAGE_SUBJECT";
$mail->Body = "TEXT_MESSAGE_CONTENT"; //HTML Body
$mail->AltBody = "TEXT_MESSAGE_CONTENT"; //Text Body
 
$mail->Send();

Have fun!

  • Share/Save/Bookmark

Simple helloworld c++ program to test noexec tmp partition

1
2
3
4
5
6
7
#include <iostream>
 
int main()
{
  std::cout << "Hello world, compiled with g++ on linux" << std::endl;
  return 0;
}

compile this and move to your secured tmp partition and execute it. If you get a permission error, tmp partition is mounted correctly with noexec.

  • Share/Save/Bookmark

Synchronize linux date and time using ntpdate

ntpdate synchronize and set computers’ date and time via Network Time Protocol (NTP) server(s).

1
/usr/sbin/ntpdate -u 0.fedora.pool.ntp.org

0.fedora.pool.ntp.org is NTP server. If this server is not working, find another one.

  • Share/Save/Bookmark