ubuntu ffmpeg 썸네일 이미지 저장

300x250

 

<?
// 비디오 입력 및 저장이미지 경로 설정
$video_file = "/var/www/master/mobile/modyeye/videos/day.mp4";
$thum_file =  "/var/www/master/mobile/modyeye/videos/thum/day.png";

// 1. ffmpeg 명령어로 비디오 가로 세로 크기 가져오기
$command = 'ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 ' . escapeshellarg($video_file);
$size= shell_exec($command);	
$size = str_replace("\n", "", $size);


// 2. ffmpeg 명령어로 설정된 크기와 시간으로 이미지를 저장하기
$time = "00:00:00.000";
$cmd = "ffmpeg -i $video_file -ss $time -s $size $thum_file";
shell_exec($cmd);  
?>
300x250

댓글()

PHP - 현재 날짜 가지고 오기 등 날짜 시간 관련

300x250

현재 날짜 가지고 오기

$today = date("Y-m-d",time());

 

 

1달전 날짜 가지고오기

$day = date('Y-m-d', strtotime('-1 month'));


그외 날짜

date("Y-m-d", time());						//오늘
date("Y-m-d", strtotime("-1 week", time()));	//최근 일주일
date("Y-m-d", strtotime("-1 month", time()));	//최근 1개월
date("Y-m-d", strtotime("-6 month", time()));	//최근 6개월
date("Y-m-d", strtotime("-1 year", time()));	//최근 1년

 

응용 ( 6개월전 을 구한다음 하루 뺴기)

	$limit_dt = date(  'Y-m-d', strtotime('-1 days', strtotime('-6 month', time()))  );
300x250

댓글()

php - ubuntu 동영상 썸네일

300x250

먼저 우분투에서 동영상 썸네일 추출을 위해서는

ffmpeg 라는 프로그램을 설치해야 합니다.

 

당연히 설치전에는 root로 로그인 해야 겠죠.

아래 sudo -s를 사용해서 root 로그인 합시다.

sudo -s

 

아래 쉘커맨드를 입력하면 ffmpeg를 설치 합니다.

경고가 뜨면 Y 눌러주면 됩니다.

apt update
apt install ffmpeg

 

비디오 파일 경로와, 만들어질 썸네일 이미지 경로 + 파일명을 넣어줍니다.

size는 썸네일 이미지 크기

time는 동영상에서 뽑아낼 시간

$video_file = "/var/www/master/upload/comment/test.mp4"
$thum_file = "/var/www/master/upload/comment/thum.png"

if(true) // 동영상 이라면
{
	$size = "960x512";
    $time = "00:00:00.000";
    $cmd = "ffmpeg -i $video_file -ss $time -s $size $thum_file";
    shell_exec($cmd);  
}

shell_exec를 사용하여 ffmpeg 프로그램을 사용하여 썸네일 이미지를 추출합니다.

 

기타로는 이미지 크기변경도 가능합니다.

ffmpeg -i input.jpg -vf scale=320:240 output_320x240.png
300x250

댓글()

Javascript <-> PHP 인코드 디코드

300x250

PHP나 javascript 에서 JSON 처리시 한글처리가 안되서 오류가 자주 발생한다.

따라서 json으로 변환시 한글이 들어간 값을 처리해줘야 한다.

 

 

1. PHP (한글 인코딩) -> JAVASCRIPT (디코딩) 예제

(PHP에서 한글 인코딩)

$string_data = "한글값";
$value = rawurlencode( iconv( "CP949", "UTF-8", $string_data));

 

(JAVASCRIPT 에서 한글 디코딩)

 var value = decodeURIComponent(string_value);

 

PHP에서 JSON으로 변환시  jsonencode 처리전에 값을 변환 해야한다. (아래 예제와 같이)

$my_array = array ('idx' => '1',
'msg' => rawurlencode( iconv( "CP949", "UTF-8", '한글')));

echo  json_encode($my_array);

 

 

 

2. JAVASCRIPT (한글 인코딩) ->PHP  (디코딩) 예제

(JAVASCRIPT 에서 한글 인코딩)

var string_data = "한글값";
var value = encodeURIComponent(string_data);

(PHP에서 한글 디코딩)

$value = iconv("UTF-8", "CP949", rawurldecode($string_value));
300x250

댓글()