2012년 6월 15일 금요일

ffmpeg install on Ubuntu 10.04(lucid) LTS



reference
http://ubuntuforums.org/showthread.php?t=786095
http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuideLucid


$ mkdir /home/user0/ffmpeg_packages
$ cd /home/user0/ffmpeg_packages

$ sudo apt-get remove ffmpeg x264 libx264-dev yasm
$ sudo apt-get update

$ wget http://security.ubuntu.com/ubuntu/pool/multiverse/f/faac/libfaac0_1.26-0.1ubuntu2_amd64.deb
$ wget http://security.ubuntu.com/ubuntu/pool/multiverse/f/faac/libfaac-dev_1.26-0.1ubuntu2_amd64.deb

$ dpkg -i libfaac0_1.26-0.1ubuntu2_amd64.deb
$ sudo dpkg -i libfaac-dev_1.26-0.1ubuntu2_amd64.deb

$ sudo apt-get install -y build-essential git-core checkinstall texi2html \
  libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev zlib1g-dev


* yasm
$ cd /home/user0/ffmpeg_packages
$ wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
$ tar xzvf yasm-1.2.0.tar.gz
$ cd yasm-1.2.0
$ ./configure
$ make
$ sudo checkinstall --pkgname=yasm --pkgversion="1.2.0" --backup=no --deldoc=yes --default


* x264
$ cd /home/user0/ffmpeg_packages
$ git clone --depth 1 git://git.videolan.org/x264
$ cd x264
$ ./configure --enable-static
$ make
$ sudo checkinstall --pkgname=x264 --default --pkgversion="3:$(./version.sh | \
    awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes


* LAME
$ cd /home/user0/ffmpeg_packages
$ sudo apt-get remove libmp3lame-dev
$ sudo apt-get install nasm

$ wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
$ tar xzvf lame-3.99.5.tar.gz
$ cd lame-3.99.5
$ ./configure --enable-nasm --disable-shared
$ make
$ sudo checkinstall --pkgname=lame-ffmpeg --pkgversion="3.99.5" --backup=no --default \
    --deldoc=yes


* libvpx
$ cd /home/user0/ffmpeg_packages
$ git clone --depth 1 http://git.chromium.org/webm/libvpx.git
$ cd libvpx
$ ./configure
$ make
$ sudo checkinstall --pkgname=libvpx --pkgversion="$(date +%Y%m%d%H%M)-git" --backup=no \
    --default --deldoc=yes


* ffmpeg
$ cd /home/user0/ffmpeg_packages
$ git clone --depth 1 git://source.ffmpeg.org/ffmpeg
$ cd ffmpeg
$ ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
  --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx \
  --enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab
$ make
$sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(./version.sh)" --backup=no \
  --deldoc=yes --default
$ hash x264 ffmpeg ffplay ffprobe




2012년 6월 14일 목요일

java로 ubuntu 환경에서 /proc/stat을 이용해 CPU 사용량 체크하기


package test;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class CpuRateByCore {
    public static int INTERVAL = 1000;

    public static String[] getCpuUsageByCore() {
        String[] result = null;
        String[] command = { "bash", "-c", "cat /proc/stat | grep 'cpu[0-9]'" };

        Runtime runtime = Runtime.getRuntime();
        BufferedReader reader = null;
        List<CpuInfoVo> prevInfoList = new ArrayList<CpuInfoVo>();
        List<CpuInfoVo> diffInfoList = new ArrayList<CpuInfoVo>();
       
        try {
            Process process = runtime.exec(command);
            reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;
            String[] columns = null;
            long total = 0;
            long idle = 0;
            int x = 0;
           
           
           
            while ( (line = reader.readLine()) != null ) {
                // System.out.println(line);
                line = line.replace("  ", " ");
                columns = line.split(" ");
   
                total = 0;
                idle = 0;
                for ( int i = 1 ; i < columns.length ; i++ ) {
                    total += Long.parseLong(columns[i]);
                }
                idle = Long.parseLong(columns[4]);
               
                CpuInfoVo vo = new CpuInfoVo();
                vo.setTotal(total);
                vo.setIdle(idle);
               
                prevInfoList.add(vo);
               
                x++;
            }

            // sleep 1sec
            //Thread.sleep(INTERVAL);
            process = runtime.exec(command);
            reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            x = 0;
            while ( (line = reader.readLine()) != null ) {
                line = line.replace("  ", " ");
                columns = line.split(" ");

                total = 0;
                idle = 0;
                for ( int i = 1 ; i < columns.length ; i++ ) {
                    total += Long.parseLong(columns[i]);
                }
                idle = Long.parseLong(columns[4]);

                long diffTotal = total - prevInfoList.get(x).getTotal();
                long diffIdle = idle - prevInfoList.get(x).getIdle();
                long cpuRate = 0;
                if (diffTotal != 0)
                    cpuRate = 100 * ( diffTotal - diffIdle ) / diffTotal;
               
                CpuInfoVo vo = new CpuInfoVo();
                vo.setTotal(diffTotal);
                vo.setIdle(diffIdle);
                vo.setRate(cpuRate);
                diffInfoList.add(vo);
                x++;
            }
            result = new String[diffInfoList.size()];
            for (int i=0; i<diffInfoList.size(); i++) {
                CpuInfoVo cpuInfoVo = (CpuInfoVo)diffInfoList.get(i);
                result[i] = Long.toString(cpuInfoVo.getRate());
            }
        }
        catch ( Exception e ) {
            e.printStackTrace();
        }

        return result;
    }

    public static void main(String[] args) throws Exception {
        String[] cpuRates = getCpuUsageByCore();
       
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String ymd = sdf.format(Calendar.getInstance().getTime().getTime());
       
        StringBuilder message = new StringBuilder();
        message.append(ymd);
        int total = 0;
        for ( int i = 0 ; i < cpuRates.length ; i++ ) {
            message.append(" ").append(cpuRates[i]);
            total += Integer.parseInt(cpuRates[i]);
        }
        int cpuRate = total / cpuRates.length;
        message.append(" (avg)").append(cpuRate);
        System.out.println(message);
    }

}

2012년 4월 29일 일요일

apache BeanUtils.populate에서 user_name 형식의 속성을 userName 멤버변수에 입력하도록 하기


public static void populate(Object bean, Map properties) throws IllegalAccessException, InvocationTargetException {
// Do nothing unless both arguments have been specified
if ((bean == null) || (properties == null)) {
return;
}

// Loop through the property name/value pairs to be set
Iterator entries = properties.entrySet().iterator();
while (entries.hasNext()) {

// Identify the property name and value(s) to be assigned
Map.Entry entry = (Map.Entry) entries.next();
String name = (String) entry.getKey();
if (name == null) {
continue;
}
char[] del = {'_'};
name = StringUtils.replace(WordUtils.capitalize(name, del), "_", "");
if (name.length() > 1) {
name = name.substring(0,1).toLowerCase() + name.substring(1);
}

// Perform the assignment for this property
BeanUtils.setProperty(bean, name, entry.getValue());
}
}

2011년 10월 28일 금요일

우분투 11.10에 Sun JDK 설치하기


Synaptic Package Manager 실행  (설치 않되어 있다면 설치)

우분투 소프트웨어 센터 실행
설정 > 저장소 (Settings > Repositories)
기타 소프트웨어 탭
추가 클릭하고 ppa:ferramroberto/java 입력하고 소스추가 클릭
닫기
새로고침

OpenJDK 삭제
Sun-Java 로 검색해서 패키지 설치

2011년 10월 11일 화요일

JOIN문을 이용한 UPDATE 쿼리


UPDATE T1
SET T1.P_CODE_VALUE1 = T2.P_CODE1
,T1.P_CODE_VALUE2 = T2.P_CODE2
FROM TMAST02TT T1
INNER JOIN TCODE02TT T2 ON T1.YEAR = T2.YEAR AND T1.P_CODE = T2.T_CODE
WHERE 1=1
AND T1.GUBUN = :gubun AND T1.YEAR = :year AND T1.SEASON = :season AND T1.SCHOOL = :school 
AND T1.BOKJONG = :bokjong AND T1.PUMOK = :pumok AND T1.SAYANG = :sayang AND T1.P_CODE = :pCode
AND T2.SEQ = :seq

2011년 9월 4일 일요일

ubuntu nabi 설치

1. nabi를 설치
$sudo apt-get install nabi

2. im-swich 설치
$sudo im-switch

3. nabi를 기본으로 설정
$sudo im-switch -c

4. reboot 또는 alt+SysRq+k

2011년 9월 1일 목요일

tomcat session timeout 변경

[tomcat]이 설치된 디렉토리/conf/web.xml 에서 아래 부분을 편집
단위는 분, 기본은 30분으로 설정되어 있음


<session-config>
        <session-timeout>360</session-timeout>
</session-config>

** 세션 타임아웃 적용 우선순위

1. 프로그램에 코딩된 session.setMaxInactiveInterval(int)
2. 각 웹 어플리케이션의 WEB-INF/web.xml
3. [tomcat설치디렉토리]/conf/web.xml