/**
* Convert uploaded video to 3gp SD format
*
* @param resourceId
* @return
*/
public static map<string, object> to3gp (String resourceId) {
String SourcePath = "E:";
String Sourcefilepath = SourcePath + "/" + resourceId;
Logger.info ("--------------------sourcefilepath:" + Sourcefilepath);
String Targetsourceid = (resourceid.substring (0,resourceid.lastindexof ("."))) + ". 3gp";
String Targetfilepath = SourcePath + "/" + Targetsourceid;
Logger.info ("--------------------targetfilepath:" + Targetfilepath);
map<string, object> returnmap = new hashmap<string, object> ();
File Source = new file (Sourcefilepath);
File target = new file (Targetfilepath);
Encoder Encoder = new Encoder ();
Multimediainfo Info=null;
if (!source.exists ()) {
Logger.info ("Source not exists");
}
try {
info = encoder.getinfo (source);
} catch (Exception e) {
Logger.error (e);
}
Get video information about a source file
Videoinfo videoinfo = Info.getvideo ();
int vodeobitrate=videoinfo.getbitrate (); Total bit Rate
int videoframerate= (int) videoinfo.getframerate ();//Frame rate
String Videodecoder=videoinfo.getdecoder ();
Videosize videosize = Videoinfo.getsize ();
Get audio information for a source file
Audioinfo audioinfo = Info.getaudio ();
int audiobitrate=audioinfo.getbitrate ();//Bit rate
String Audiodecoder=audioinfo.getdecoder ();
int audiochannel = Audioinfo.getchannels ();//Channel
int audiosimplingrate = Audioinfo.getsamplingrate ();//Audio sampling frequency
Audioattributes audio = new Audioattributes ();
Audio.setcodec ("LIBFAAC");
Audio.setbitrate (New Integer (8));
Audio.setsamplingrate (New Integer (AUDIOSIMPLINGRATE/2));
Audio.setchannels (New Integer (Audiochannel));
Videoattributes video = new Videoattributes ();
Video.setcodec ("MPEG4");
Video.setbitrate (New Integer (100000));
Video.setframerate (New Integer (16));
Video.setsize (New videosize ((int) (Videosize.getwidth ()/4), (int) (Videosize.getheight ()/4));
Encodingattributes attrs = new Encodingattributes ();
Attrs.setformat ("3gp");
Attrs.setaudioattributes (audio);
Attrs.setvideoattributes (video);
try {
Encoder.encode (source, target, attrs);
} catch (Exception e) {
Logger.error (e);
Targetsourceid= "";
}
Logger.info ("--------------------sourcesize:" + source.length ());
Logger.info ("--------------------targetsize:" + target.length ());
Returnmap.put ("ResourceID", Targetsourceid);
Integer resourcesize= (int) target.length ();
Returnmap.put ("Resourcesize", resourcesize);
return returnmap;
}
Java uses Jave to convert video format to 3GP