官网地址:http://www.sauronsoftware.it/projects/jave/manual.php
In order to use JAVE in your Java application, you have to add the file jave-1.0.jar in your application CLASSPATH.
JAVE runs on a Java Runtime Environment J2SE v.1.4 or later.
JAVE includes and uses a ffmpeg executable built for Windows and Linux operating systems on i386/32 bit hardware platforms. In order to run JAVE on other platforms you have to replace the built-in ffmpeg executable with another one suitable for your needs. This is very simple, once you have built your own ffmpeg binaries. The operation is described in the "Using an alternative ffmpeg executable" section.
The most important JAVE class is it.sauronsoftware.jave.Encoder. Encoder objects expose many methods for multimedia transcoding. In order to use JAVE, you always have to create an Encoder istance:
Encoder encoder = new Encoder();
Once the instance has been created, you can start transcoding calling the encode() method:
public void encode(java.io.File source,
java.io.File target,
it.sauronsoftware.jave.EncodingAttributes attributes)
throws java.lang.IllegalArgumentException,
it.sauronsoftware.jave.InputFormatException,
it.sauronsoftware.jave.EncoderException
The first parameter, source, represents the source file to decode.
The second parameter, target, is the target file that will be created and encoded.
The attributes parameter, whose type is it.sauronsoftware.jave.EncodingAttributes, is a data structure containing any information needed by the encoder.
Please note that a call to encode() is a blocking one: the method will return only once the transcoding operation has been completed (or failed). If you are interested in monitoring the transcoding operation take a look to the "Monitoring the transcoding operation" section.
To specify your preferences about the transcoding operation you have to supply an it.sauronsoftware.jave.EncodingAttributes instance to the encode() call. You can create your own EncodingAttributes instance, and you can populate it with the following methods:
public void **setAudioAttributes**(it.sauronsoftware.jave.AudioAttributes audioAttributes)
public void **setVideoAttributes**(it.sauronsoftware.jave.AudioAttributes videoAttributes)
public void **setFormat**(java.lang.String format)
public void **setOffset**(java.lang.Float offset)
public void **setDuration**(java.lang.Float duration)
Audio encoding attributes are represented by the instances of the it.sauronsoftware.jave.AudioAttributes class. The available methods on this kind of objects are:
public void **setCodec**(java.lang.String codec)
public void **setBitRate**(java.lang.Integer bitRate)
public void **setSamplingRate**(java.lang.Integer bitRate)
public void **setChannels**(java.lang.Integer channels)
public void **setVolume**(java.lang.Integer volume)
Video encoding attributes are represented by the instances of the it.sauronsoftware.jave.VideoAttributes class. The available methods on this kind of objects are:
public void **setCodec**(java.lang.String codec)
public void **setTag**(java.lang.String tag)
public void **setBitRate**(java.lang.Integer bitRate)
public void **setFrameRate**(java.lang.Integer bitRate)
public void **setSize**(it.sauronsoftware.jave.VideoSize size)
You can monitor a transcoding operation with a listener. JAVE defines the it.sauronsoftware.jave.EncoderProgressListener interface. This interface could be implemented by your application, and concrete EncoderProgressListener instances can be passed to the encoder. The encoder will call your listener methods every time a significant event occurs. To pass an EncoderProgressListener to the encoder you should use this definition of the encode() method:
public void encode(java.io.File source,
java.io.File target,
it.sauronsoftware.jave.EncodingAttributes attributes,
it.sauronsoftware.jave.EncoderProgressListener listener)
throws java.lang.IllegalArgumentException,
it.sauronsoftware.jave.InputFormatException,
it.sauronsoftware.jave.EncoderException
To implemen the EncoderProgressListener interface you have to define all of the following methods:
public void **sourceInfo**(it.sauronsoftware.jave.MultimediaInfo info)
public void **progress**(int permil)
public void **message**(java.lang.String message)
Of course, a transcoding operation could fail. Then the encode() method will propagate an exception. Depending on what is happened, the exception will be one of the following:
You can get informations about an existing multimedia file before transcoding it, calling the encoder getInfo() method. The getInfo() method gives you informations about the container used by the file and about its wrapped audio and video streams:
public it.sauronsoftware.jave.MultimediaInfo getInfo(java.io.File source)
throws it.sauronsoftware.jave.InputFormatException,
it.sauronsoftware.jave.EncoderException
An it.sauronsoftware.jave.MultimediaInfo object encapsulates information on the whole multimedia content and its streams, using instances of it.sauronsoftware.jave.AudioInfo and it.sauronsoftware.jave.VideoInfo to describe the wrapped audio and video. These objects are similar to the EncodingAttributes, AudioAttributes and VideoAttributes ones, but they works in a read-only mode. Check the JAVE API javadoc documentation, bundled with the JAVE distribution, to gain more details about them.
JAVE is not pure Java: it acts as a wrapper around an ffmpeg (http://ffmpeg.mplayerhq.hu/) executable. ffmpeg is an open source and free software project entirely written in C, so its executables cannot be easily ported from a machine to another. You need a pre-compiled version of ffmpeg in order to run JAVE on your target machine. The JAVE distribution includes two pre-compiled executables of ffmpeg: a Windows one and a Linux one, both compiled for i386/32 bit hardware achitectures. This should be enough in most cases. If it is not enough for your specific situation, you can still run JAVE, but you need to obtain a platform specific ffmpeg executable. Check the Internet for it. You can even build it by yourself getting the code (and the documentation to build it) on the official ffmpeg site. Once you have obtained a ffmpeg executable suitable for your needs, you have to hook it in the JAVE library. That's a plain operation. JAVE gives you an abstract class called it.sauronsoftware.jave.FFMPEGLocator. Extend it. All you have to do is to define the following method:
public java.lang.String getFFMPEGExecutablePath()
This method should return a file system based path to your custom ffmpeg executable.
Once your class is ready, suppose you have called it MyFFMPEGExecutableLocator, you have to create an alternate encoder that uses it instead of the default locator:
Encoder encoder = new Encoder(new MyFFMPEGExecutableLocator())
You can use the same procedure also to switch to other versions of ffmpeg, even if you are on a platform covered by the executables bundled in the JAVE distribution.
Anyway be careful and test ever your application: JAVE it's not guaranteed to work properly with custom ffmpeg executables different from the bundled ones.
The JAVE built-in ffmpeg executable gives support for the following multimedia container formats:
Formato
Descrizione
4xm
4X Technologies format
MTV
MTV format
RoQ
Id RoQ format
aac
ADTS AAC
ac3
raw ac3
aiff
Audio IFF
alaw
pcm A law format
amr
3gpp amr file format
apc
CRYO APC format
ape
Monkey's Audio
asf
asf format
au
SUN AU Format
avi
avi format
avs
AVISynth
bethsoftvid
Bethesda Softworks 'Daggerfall' VID format
c93
Interplay C93
daud
D-Cinema audio format
dsicin
Delphine Software International CIN format
dts
raw dts
dv
DV video format
dxa
dxa
ea
Electronic Arts Multimedia Format
ea_cdata
Electronic Arts cdata
ffm
ffm format
film_cpk
Sega FILM/CPK format
flac
raw flac
flic
FLI/FLC/FLX animation format
flv
flv format
gif
GIF Animation
gxf
GXF format
h261
raw h261
h263
raw h263
h264
raw H264 video format
idcin
Id CIN format
image2
image2 sequence
image2pipe
piped image2 sequence
ingenient
Ingenient MJPEG
ipmovie
Interplay MVE format
libnut
nut format
m4v
raw MPEG4 video format
matroska
Matroska File Format
mjpeg
MJPEG video
mm
American Laser Games MM format
mmf
mmf format
mov,mp4,m4a,3gp,3g2,mj2
QuickTime/MPEG4/Motion JPEG 2000 format
mp3
MPEG audio layer 3
mpc
musepack
mpc8
musepack8
mpeg
MPEG1 System format
mpegts
MPEG2 transport stream format
mpegtsraw
MPEG2 raw transport stream format
mpegvideo
MPEG video
mulaw
pcm mu law format
mxf
MXF format
nsv
NullSoft Video format
nut
nut format
nuv
NuppelVideo format
ogg
Ogg format
psxstr
Sony Playstation STR format
rawvideo
raw video format
redir
Redirector format
rm
rm format
rtsp
RTSP input format
s16be
pcm signed 16 bit big endian format
s16le
pcm signed 16 bit little endian format
s8
pcm signed 8 bit format
sdp
SDP
shn
raw shorten
siff
Beam Software SIFF
smk
Smacker Video
sol
Sierra SOL Format
swf
Flash format
thp
THP
tiertexseq
Tiertex Limited SEQ format
tta
true-audio
txd
txd format
u16be
pcm unsigned 16 bit big endian format
u16le
pcm unsigned 16 bit little endian format
u8
pcm unsigned 8 bit format
vc1
raw vc1
vmd
Sierra VMD format
voc
Creative Voice File format
wav
wav format
wc3movie
Wing Commander III movie format
wsaud
Westwood Studios audio format
wsvqa
Westwood Studios VQA format
wv
WavPack
yuv4mpegpipe
YUV4MPEG pipe format
Formato
Descrizione
3g2
3gp2 format
3gp
3gp format
RoQ
Id RoQ format
ac3
raw ac3
adts
ADTS AAC
aiff
Audio IFF
alaw
pcm A law format
amr
3gpp amr file format
asf
asf format
asf_stream
asf format
au
SUN AU Format
avi
avi format
crc
crc testing format
dv
DV video format
dvd
MPEG2 PS format (DVD VOB)
ffm
ffm format
flac
raw flac
flv
flv format
framecrc
framecrc testing format
gif
GIF Animation
gxf
GXF format
h261
raw h261
h263
raw h263
h264
raw H264 video format
image2
image2 sequence
image2pipe
piped image2 sequence
libnut
nut format
m4v
raw MPEG4 video format
matroska
Matroska File Format
mjpeg
MJPEG video
mmf
mmf format
mov
mov format
mp2
MPEG audio layer 2
mp3
MPEG audio layer 3
mp4
mp4 format
mpeg
MPEG1 System format
mpeg1video
MPEG video
mpeg2video
MPEG2 video
mpegts
MPEG2 transport stream format
mpjpeg
Mime multipart JPEG format
mulaw
pcm mu law format
null
null video format
nut
nut format
ogg
Ogg format
psp
psp mp4 format
rawvideo
raw video format
rm
rm format
rtp
RTP output format
s16be
pcm signed 16 bit big endian format
s16le
pcm signed 16 bit little endian format
s8
pcm signed 8 bit format
svcd
MPEG2 PS format (VOB)
swf
Flash format
u16be
pcm unsigned 16 bit big endian format
u16le
pcm unsigned 16 bit little endian format
u8
pcm unsigned 8 bit format
vcd
MPEG1 System format (VCD)
vob
MPEG2 PS format (VOB)
voc
Creative Voice File format
wav
wav format
yuv4mpegpipe
YUV4MPEG pipe format
The JAVE built-in ffmpeg executable contains the following decoders and encoders:
adpcm_4xm
adpcm_adx
adpcm_ct
adpcm_ea
adpcm_ea_r1
adpcm_ea_r2
adpcm_ea_r3
adpcm_ea_xas
adpcm_ima_amv
adpcm_ima_dk3
adpcm_ima_dk4
adpcm_ima_ea_eacs
adpcm_ima_ea_sead
adpcm_ima_qt
adpcm_ima_smjpeg
adpcm_ima_wav
adpcm_ima_ws
adpcm_ms
adpcm_sbpro_2
adpcm_sbpro_3
adpcm_sbpro_4
adpcm_swf
adpcm_thp
adpcm_xa
adpcm_yamaha
alac
ape
atrac 3
cook
dca
dsicinaudio
flac
g726
imc
interplay_dpcm
liba52
libamr_nb
libamr_wb
libfaad
libgsm
libgsm_ms
mace3
mace6
mp2
mp3
mp3adu
mp3on4
mpc sv7
mpc sv8
mpeg4aac
nellymoser
pcm_alaw
pcm_mulaw
pcm_s16be
pcm_s16le
pcm_s16le_planar
pcm_s24be
pcm_s24daud
pcm_s24le
pcm_s32be
pcm_s32le
pcm_s8
pcm_u16be
pcm_u16le
pcm_u24be
pcm_u24le
pcm_u32be
pcm_u32le
pcm_u8
pcm_zork
qdm2
real_144
real_288
roq_dpcm
shorten
smackaud
sol_dpcm
sonic
truespeech
tta
vmdaudio
vorbis
wavpack
wmav1
wmav2
ws_snd1
xan_dpcm
ac3
adpcm_adx
adpcm_ima_wav
adpcm_ms
adpcm_swf
adpcm_yamaha
flac
g726
libamr_nb
libamr_wb
libfaac
libgsm
libgsm_ms
libmp3lame
libvorbis
mp2
pcm_alaw
pcm_mulaw
pcm_s16be
pcm_s16le
pcm_s24be
pcm_s24daud
pcm_s24le
pcm_s32be
pcm_s32le
pcm_s8
pcm_u16be
pcm_u16le
pcm_u24be
pcm_u24le
pcm_u32be
pcm_u32le
pcm_u8
pcm_zork
roq_dpcm
sonic
sonicls
vorbis
wmav1
wmav2
4xm
8bps
VMware video
aasc
amv
asv1
asv2
avs
bethsoftvid
bmp
c93
camstudio
camtasia
cavs
cinepak
cljr
cyuv
dnxhd
dsicinvideo
dvvideo
dxa
ffv1
ffvhuff
flashsv
flic
flv
fraps
gif
h261
h263
h263i
h264
huffyuv
idcinvideo
indeo2
indeo3
interplayvideo
jpegls
kmvc
loco
mdec
mjpeg
mjpegb
mmvideo
mpeg1video
mpeg2video
mpeg4
mpegvideo
msmpeg4
msmpeg4v1
msmpeg4v2
msrle
msvideo1
mszh
nuv
pam
pbm
pgm
pgmyuv
png
ppm
ptx
qdraw
qpeg
qtrle
rawvideo
roqvideo
rpza
rv10
rv20
sgi
smackvid
smc
snow
sp5x
svq1
svq3
targa
theora
thp
tiertexseqvideo
tiff
truemotion1
truemotion2
txd
ultimotion
vb
vc1
vcr1
vmdvideo
vp3
vp5
vp6
vp6a
vp6f
vqavideo
wmv1
wmv2
wmv3
wnv1
xan_wc3
xl
zlib
zmbv
asv1
asv2
bmp
dnxhd
dvvideo
ffv1
ffvhuff
flashsv
flv
gif
h261
h263
h263p
huffyuv
jpegls
libtheora
libx264
libxvid
ljpeg
mjpeg
mpeg1video
mpeg2video
mpeg4
msmpeg4
msmpeg4v1
msmpeg4v2
pam
pbm
pgm
pgmyuv
png
ppm
qtrle
rawvideo
roqvideo
rv10
rv20
sgi
snow
svq1
targa
tiff
wmv1
wmv2
zlib
zmbv
From a generic AVI to a youtube-like FLV movie, with an embedded MP3 audio stream:
File source = new File("source.avi");
File target = new File("target.flv");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(64000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(22050));
VideoAttributes video = new VideoAttributes();
video.setCodec("flv");
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setSize(new VideoSize(400, 300));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("flv");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
Next lines extracts audio informations from an AVI and store them in a plain WAV file:
File source = new File("source.avi");
File target = new File("target.wav");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("pcm_s16le");
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("wav");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
Next example takes an audio WAV file and generates a 128 kbit/s, stereo, 44100 Hz MP3 file:
File source = new File("source.wav");
File target = new File("target.mp3");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(128000));
audio.setChannels(new Integer(2));
audio.setSamplingRate(new Integer(44100));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
Next one decodes a generic AVI file and creates another one with the same video stream of the source and a re-encoded low quality MP3 audio stream:
File source = new File("source.avi");
File target = new File("target.avi");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(56000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(22050));
VideoAttributes video = new VideoAttributes();
video.setCodec(VideoAttributes.DIRECT_STREAM_COPY);
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("avi");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
Next one generates an AVI with MPEG 4/DivX video and OGG Vorbis audio:
File source = new File("source.avi");
File target = new File("target.avi");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libvorbis");
VideoAttributes video = new VideoAttributes();
video.setCodec("mpeg4");
video.setTag("DIVX");
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(30));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mpegvideo");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
A smartphone suitable video:
File source = new File("source.avi");
File target = new File("target.3gp");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libfaac");
audio.setBitRate(new Integer(128000));
audio.setSamplingRate(new Integer(44100));
audio.setChannels(new Integer(2));
VideoAttributes video = new VideoAttributes();
video.setCodec("mpeg4");
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setSize(new VideoSize(176, 144));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("3gp");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
手机扫一扫
移动阅读更方便
你可能感兴趣的文章