2009年9月19日 星期六

ffmpeg batch converter written in Java!!

(東抄西抄一堆Java IO samples來的,寫得很亂,但跑起來還不錯!想寫給Windows users用,但目前是在Unix環境測試,算是0.01版吧)

import java.io.*;
public class jffmpeg {

public static void main(String args[]) {
System.out.println("原始檔案請放到\"D:\\transcode\"資料夾");
System.out.println("MPEG2將轉檔於\"D:\\transcode\\output\"資料夾");
System.out.println("注意檔案名稱不要留空白!!");
try{
System.out.println("請按Enter繼續;Ctrl-C結束");
System.in.read();
} catch(IOException io)
{
System.out.println("ERROR" + io);
}

File outDir = new File("/work/java/output"); //指定要輸出的目錄
File myDir = new File("/work/java/mpg"); //指定要列出的目錄
if(!outDir.exists()){
System.out.println("\""+outDir+"\"不存在,請建立\""+outDir+"\"資料夾!!");
}else if (!myDir.exists()){
System.out.println("\""+myDir+"\"不存在,請建立\""+myDir+"\"資料夾!!");
}else{
/**
* 刪除目標資料夾下的所有檔案
*/
File[] dellist = outDir.listFiles();
for (int di = 0; di < dellist.length; di++) {
if (dellist[di].isFile()) {
dellist[di].delete();
}
}
try{
String[] list = myDir.list(); //取得目錄中的檔案列表
for(int i=0;i < list.length;i++){
try {
String line;
// String[] cmd = {"mencoder","test.mpg","-ovc","copy","-oac","copy","-o","output.mpg"};
// String[] cmd = {"ffmpeg"};
String[] cmd = {"ffmpeg","-i",myDir+"/"+list[i],"-target","ntsc-dvd",outDir+"/"+list[i]+".mpg"};
System.out.println("開始"+"\""+list[i]+"\""+"的MPEG2編碼...");
Process p = Runtime.getRuntime().exec(cmd);
/* Process p = Runtime.getRuntime().exec
(System.getenv("windir") +"\\system32\\"+"tree.com /A");*/
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
System.out.println("完成"+"\""+list[i]+"\""+"的MPEG2編碼!!");
}
catch (Exception err) {
err.printStackTrace();
}
}
}catch(Exception e){
System.err.println(e);
}
}
}
}

2009年9月10日 星期四

Compile ffmpeg with x264 manually

http://www.chineselinuxuniversity.net/courses/using/introductions/25004.shtml

DO NOT INSTALL ANY FFMPEG & X264 from REPOS!!

# apt-get install build-essential subversion git-core
(subversion is for fetching ffmpeg source; git is for x264 source)

# wget http://www.tortall.net/projects/yasm/releases/yasm-0.7.2.tar.gz
# tar xzvf yasm-0.7.2.tar.gz
# cd yasm-0.7.2
#./configure && make && make install
(yasm is for building x264)

# git clone git://git.videolan.org/x264.git
# cd x264
# ./configure --enable-shared
# make && make install
(fetch & compile x264 library)

# svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
# cd ffmpeg
# ./configure --enable-gpl --enable-libx264
# make && make install
(fetch & compile ffmpeg with libx264 support)

# mkdir ~/.ffmpeg
# cp ~/ffmpeg/ffpresets/* ~/.ffmpeg
(copy the ffmpeg presets)

# ffmpeg -i infile -vcodec libx264 -vpre hq -b 1M -bt 1M outfile.mp4
(DONE!! You can now encode x264 videos with the presets via -vpre!!)

2009年9月9日 星期三

mplayer、ffmpeg 指令備忘

http://cha.homeip.net/blog/archives/2008/03/mplayerffmpeg.html

環境: Fedora 8 with Livna repo

查看 DVD 結構

mplayer dvd:// -identify -endpos 0 | grep ID_DVD

ID_DVD_TITLES=2 (總共有兩個標題)
ID_DVD_TITLE_1_CHAPTERS=11 (第一個標題有十一個章節)
ID_DVD_TITLE_1_ANGLES=1 (第一個標題只有一種視角)
ID_DVD_TITLE_2_CHAPTERS=8 (第二個標題有八個章節)
ID_DVD_TITLE_2_ANGLES=1 (第二個標題只有一種視角)

dvd:// → DVD
vcd:// → VCD
cdda:// → Audio CD
cddb:// → Audio CD


擷錄 DVD 影片

#擷錄 TITLE 1, CHAPTER 8
mplayer dvd://1 -chapter 8-8 -dumpstream -dumpfile myfile.vob

-dumpstream: Video + Audio
-dumpvideo: Video only
-dumpaudio: Audio only (-dumpfile filename.ac3)


修剪影音檔案

#從第 11 秒的地方開始擷錄 (去除前面 10 秒內容)
ffmpeg -i input_file -ss 11 -acodec libmp3lame -ab 192k output.mp3

#從 -ss hh:mm:ss 開始擷錄, 且只錄製 -t hh:mm:ss 長度
ffmpeg -i input_file -ss hh:mm:ss -t hh:mm:ss -acodec copy -ab 192k output_file


下載影音串流檔案

#下載 mms:// 影音串流
mplayer mms://host/hot_mv.asf -dumpstream -dumpfile myfile.asf


Webcam 應用

#播放 Webcam 視訊
mplayer tv:// -fps 30

#錄製 Webcam 影像
ffmpeg -i /dev/video -f video4linux2 -s 320x240 -f m4v myvideo.m4v


附錄: 解決 Ubuntu 8.04 (Hardy) ffmpeg 無法 AC3 解碼的問題

sudo vi /etc/apt/sources.list

#加入
deb http://packages.medibuntu.org/ hardy free non-free

wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add -

sudo apt-get update

sudo apt-get upgrade (更新 ffmpeg 版本)

#擷錄 DVD 音訊內容
mplayer dvd://1 -chapter 1-1 -dumpaudio -dumpfile myfile.ac3

#處理 AC3 格式檔案
ffmpeg -f ac3 -i myfile.ac3 -ss 11 -acodec copy cutted_file.ac3

Ref: http://www.hwupgrade.it/forum/showthread.php?t=1106346&page=793

ffmpeg指定in-out點轉檔(-ss,-t)

ffmpeg -i unnamed-002-C001.avi -t 00:03:08 -target ntsc-dvd unnamed-002-C001.mpg
ffmpeg -i unnamed2-001.vob -ss 00:02:51 -t 00:02:20 -target ntsc-dvd unnamed2-001.mpg

2009年9月8日 星期二

Compile mplayer and x264 for ostube

http://www.ostube.de/node/1941#comment-2598
http://www.chineselinuxuniversity.net/courses/using/introductions/25004.shtml

=========================================================
Basic installation instructions for external Software
=========================================================

-> Create a folder where you store the software archives we want to build and change in there:

mkdir /root/self_build
cd /root/self_build
****************************

-> Now we install at first the jpeg headers and ruby from your repository:

Debian:
apt-get install libjpeg-dev ruby

RedHat/Fedora/CentOS:
Make sure yum is installed. Otherwise you have to use rpm manually.
yum install libjpeg-devel ruby

SuSE:
yast2 -i libjpeg-devel ruby
****************************

-> Get all the software needed using the downloading swissknife 'wget':

1. libmp3lame / libamrwb /libamrnb:
wget http://downloads.sourceforge.net/lame/lame-3.97.tar.gz?modtime=1159107882&big_mirror=0
wget http://ftp.penguin.cz/pub/users/utx/amr/amrnb-7.0.0.0.tar.bz2
wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-7.0.0.2.tar.bz2

2. Mplayer:
wget http://www.mplayerhq.hu/MPlayer/releases/MPlayer-1.0rc2.tar.bz2

3. Codecs for Mplayer - select the one for your environment (32bit / 64bit)
wget http://www2.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
wget http://www2.mplayerhq.hu/MPlayer/releases/codecs/essential-amd64-20071007.tar.bz2

4. Flvtool2:
wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
****************************

-> Now change directory to /usr/local/lib, decompress the codecs package there and rename the newly created folder to 'codecs':

cd /usr/local/lib
tar xvjf /root/self_build/essential-20071007.tar.bz2
mv essential-20071007 codecs
cd /root/self_build
****************************

-> The first compiling job: we build the lame and amr libraries

tar xzf lame-3.97.tar.gz
tar xvjf amrnb-7.0.0.0.tar.bz2
tar xvjf amrwb-7.0.0.2.tar.bz2
cd lame-3.97
./configure && make && make install
cd ../amrnb-7.0.0.0
./configure && make && make install
cd ../amrwb-7.0.0.2
./configure && make && make install
ldconfig

If there are error messages like 'no suitable compiler found', you have to install some development packages from your repository. You do that just like I described above (jpeg headers and ruby)

- g++ (gcc)
- make
- automake
- autoconf
- patch
- pkgconfig

**************** EDIT ******************
for HD support from version 2.6 on you need x264 libraries as well:
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20080731-2245.tar.bz2
tar xvjf x264-snapshot-20080731-2245.tar.bz2
cd x264-snapshot-20080731-2245
./configure --enable-shared
make && make install && ldconfig
cd ..
************** END EDIT ***************
* Newer yasm is needed instead of the old one in repo!! DO NOT USE APT!!
wget http://www.tortall.net/projects/yasm/releases/yasm-0.7.2.tar.gz
tar xzvf yasm-0.7.2.tar.gz
cd yasm-0.7.2
./configure && make && make install

-> Now Mplayer:

tar xvjf MPlayer-1.0rc2.tar.bz2
cd Mplayer-1.0rc2
./configure
At this point LOOK at the configure output! It will possibly prevent you from later frustrations! Make sure both jpeg output support and libmp3lame (for mencoder) are activated automatically here. If this is not the case, check again if you really installed the jpeg headers and the lame library. Then open the file /etc/ld.so.conf, add the line /usr/local/lib, save the file and execute ldconfig. Now clean up the previously made configuration for Mplayer by executing make distclean and run ./configure again. Now lame and jpeg headers should be found in the system. If so, go ahead with:
make && make install
cd ..
****************************

-> Finally we install Flvtool2:

tar xzf flvtool2-1.0.6.tgz
cd flvtool2-1.0.6
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install
cd ..

=========================================================
At this point all software packages urgently needed by osTube is installed
=========================================================

For the paying stuff you really should ask one of our sales manager (markovski@auvica.de or ucke@auvica.de). As far as I know PayPal isn't a problem at all.
But I think base currency for selling osTube is in fact EUR. Meaning you have to calculate the actual exchange rate. But before I tell you stuff that isn't fresh anymore, just ask the sales manager guys. Maybe in the meantime they have a constant price in USD... I don't know.

I hope that was informative.

Regards

-- osTube Entwicklerteam, Karsten

2009年9月6日 星期日

[FFmpeg-user] How to broadcast a video -- in depth ??

> Due to what I can imagine, there are 2 possible ways to broadcast a video
> file.
>
> 1) Read over the video file at the very beginning (something like a video
> loading) and obtain two full data streams, namely audio stream and video
> stream. And then simultaneously start broadcasting the audio stream as a
> MIDI and start broadcasting the video stream at a specific frequency (say,
> 30 frames per second). But there seems to be a synchronization problem here.
>
> 2) A video file is normally interleaved by one frame of audio stream and one
> frame of video stream, one after another.... For each frame ( no matter it's
> an audio stream or a video stream), there is a time stamp. It seems no
> matter what types of the video files are, the frames (both audio and video
> together) are interleaved sequentially according to the time stamp sequence.
> So, it might be possible to broadcast according to time sequence. However,
> this will bring me another problem: that is: if this frame is a video frame,
> during this short period of time (if 30 frames per second, 1 frame takes
> 1/30=0.033333 second ), there will be no sound to be broadcasted, which
> makes the audio broadcasting uncontinuous, right????

read both audio and video in a buffer, say 1 sec, then you are able to
process audio and video simultaneously, or that quick after another that
no one will be able to see or hear that there is a gap. If there is a
picture shown to you for 0.033333 second you won't be able to tell what
you've seen.

[FFmpeg-user] DV25 quicktime code

Date: 2009-09-04 22:39 +800
To: FFmpeg user questions and RTFMs
Subject: Re: [FFmpeg-user] DV25 quicktime code
Maksym Veremeyenko wrote:
> Kemal Seref написав(ла):
>> I want to create a quicktime movie, pal DV25, 720x576, 48 khz, 16bit
>> stereo
>> sound.
>>
>> I do not want to use the target pal-dv option to create a dv file. I
>> want a
>> quicktime movie with dv codec.
>>
>> when I use:
>>
>> -i (filename) -acoded pcm_s16le -ar 48000 -s 720x576 -vcodec dvvideo -b
>> 25000 -r 25 -y location & new filename

> I get a movie which doesn't seems to be right. Final Cut gives this message:
> media file is not optimezed for Final Cut Pro.


Ignore this message, FCP complains because audio chunks are not
containing ~= 48000 samples which is completely non efficient.

--
Baptiste COUDURIER GnuPG Key Id: 0x5C1ABAAA
Key fingerprint 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
FFmpeg maintainer http://www.ffmpeg.org

>
> sometime i had a problem if *vtag* is not defined...
>
> # dvcpro25
> -i (filename) -f mov -vcodec dvvideo -r 25 -acodec pcm_s16be -ac 2
> -pix_fmt yuv411p -vtag dvpp
>
> # dvcpro50
> -i (filename) -f mov -vcodec dvvideo -r 25 -acodec pcm_s16be -ac 2
> -pix_fmt yuv422p -vtag dv5p
>
> # dvcam
> -i (filename) -f mov -vcodec dvvideo -r 25 -acodec pcm_s16be -ac 2
> -pix_fmt yuv420p -vtag dvcp
>


I usually force the audio to avoid issue with odd sample rates, and add
an aspect tag:-

-i infile.fmt -vcodec dvvideo -s 720x576 -aspect 4:3 -pix_fmt yuv420p -r
25 -acodec pcm_s16le -ac 2 -ar 48000 out.mov

I have not had a problem with the 4cc.

--
Tim Nicholson

2009年9月4日 星期五

Understanding the MPEG format

(ffmpeg-user Digest, Vol 54, Issue 10)
" It was seen in Figure 2.7 that a sinusoidal function is a rotation
resolved in one axis. In order to obtain a purely sinusoidal motion, the
motion on the other axis must be eliminated. Conceptually this may be
achieved by having a contra-rotating system in which there is one
rotation at +w and another at -w. Figure 2.8(a) shows that the sine
components of these two rotations will be in the same phase and will
add, whereas the cosine components will be in anti-phase and will
cancel. Thus all real frequencies actually contain equal amounts of
positive and negative frequencies. These cannot be distinguished unless
a modulation process takes place. Figure 2.8(b) shows that when two
signals of frequency +/-w1 and +/-w2 are multiplied together, the result is
that the rotations of each must be added. The result is four frequencies,
+/-(w1 + w2) and +/-(w1 - w2), one of which is the sum of the input
frequencies and one of which is the difference between them. These
are called sidebands."

The fact is that there is no picture 2.7 in the book, yeeeeheeee !
First of all i don't get this sentence :
"Conceptually this may be
achieved by having a contra-rotating system in which there is one
rotation at +w and another at -w."

Can someone explain me please ?

=>Read up on Fourier analysis...
In yet other words, a real sinusoid has symmetric contributions from
positive and negative freqs:

cos(x) = (exp(ix)+exp(-ix))/2

tovid 的高畫質DVD(8M)轉檔指令

tovid -force -in 0904-sapling-TW.avi -vbitrate 8000 -ntsc -dvd -out 0904-sapling-TW