Escolar Documentos
Profissional Documentos
Cultura Documentos
Look
ANDROID JAVA JVM LANGUAGES SOFTWARE DEVELOPMENT AGILE CAREER COMMUNICATIONS DEVOPS META JCG
HomeJavaDesktopJavaIntroductiontoXugglerforVideoManipulation
Iliasisasoftwaredeveloperturnedonlineentrepreneur.HeiscofounderandExecutiveEditoratJavaCodeGeeks.
Note:ThisispartofourXugglerDevelopmentTutorialsseries.
Withtheexplosionofvideointheinternet,developersfrequentlyneedtomanipulate
videocontentintheirapplications.XugglerisafreeopensourcelibraryforJava
developerswhichcanbeusedtouncompress,manipulate,andcompressrecordedor
livevideoinrealtime.XugglerusestheverypowerfulFFmpegmediahandlinglibraries
underthehood,essentiallyplayingtheroleofajavawrapperaroundthem.Itisthe
easywaytouncompress,modify,andrecompressanymediafile(orstream)from
Try it free
Java.
Google Cloud provides a scalable
range of computing options tailored
FFmpegisacomplete,crossplatformsolutiontorecord,convertandstreamaudioand
to match your needs.
video,supportingnumerousformats.Itisprobablethatyouarealreadyusingiton
yourcomputer,evenwithoutknowingit.However,Xugglersuseisnotlimitedtojust
providinganeasyaccesstothecomplexFFmpegnativelibraries.TheXugglerdev NEWSLETTER
teamalsoconstantlyaddsimprovementstoFFmpeg.YoucanfindthelatestnewsontheXuggleblog,whereanumberoftutorialsisalso
published.DontmisstheOverlySimplisticGuidetoInternetVideofromthoseguys.
LetscontinuebygettingFFmpeg.NotethatXugglercomeswithitsown(improved)FFmpegversiontoavoidmisconfigurationproblems,so 179,260insidersarealreadyenjoy
youdoNOThavetomanuallyobtainFFmpeg.Alongtheway,wearegoingtotestsomethingsdirectlyusingFFmpegbeforepassingcontrolto weeklyupdatesandcomplimentary
whitepapers!
Xuggler,soyoumightprefertohavetheoriginalversionasaseparateexecutable.
Jointhemnowtogain
GotoFFmpegdownloadspageandgetthelatestdistribution,versionbeing0.6.1atthetime.ForLinux,youdownloadthesourcecodefrom accesstothelatestnewsintheJava
thetarballandproceedwiththecompilation.InWindowsthough,youshouldprobablygetaprecompiledbinary.Iusedtheoneprovidedby aswellasinsightsaboutAndroid,Scala
Mplayerwin32andcanbeobtainedfromhere.Youwillfindaffmpeg.exeexecutablethere.Copythatinaspecificfolder,Ichose Groovyandotherrelatedtechnologies.
C:\programs\ffmpegandoptionallyaddtheffmpeg.exeinyoursystemspathifyoudontwanttowritethewholepatheverytime.
Emailaddress:
Totestthattheexecutableworkscorrectlyopenaterminalandjustrunitwithnoarguments.Youshouldseeanoutputsimilartothis:
Youremailaddress
FFmpegversionSVNr21231Sherpya,Copyright(c)20002010FabriceBellard,etal.
builtonJan16201005:42:31withgcc4.2.520080919(prerelease)[Sherpya]libavutil50.7.0/50.7.0
libavcodec52.47.0/52.47.0 Signup
libavformat52.47.0/52.47.0
libavdevice52.2.0/52.2.0
libavfilter1.15.0/1.15.0
libswscale0.8.0/0.8.0 RECENT JOBS
libpostproc51.2.0/51.2.0
HyperfastAudioandVideoencoder
usage:ffmpeg[options][[infileoptions]iinfile]{[outfileoptions]outfile} SoftwareDeveloperinBracknell(UK)
Bracknell,UnitedKingdom
Usehtogetfullhelpor,evenbetter,runmanffmpeg
SoftwareEngineerServiceProvider
Youcanalsousethehswitch,assuggestedbytheoutput,toreceivearidiculouslylonglistofargumentsandoptions.Bettercheckoutthe Bracknell,UnitedKingdom
onlineFFmpegdocumentation.
VIEWALL
Thenextstepwouldbetotranscodeyourfirstvideo,probablyfromaprerecordedfile.MyinputfileisaMP4video,4min20seclong,witha
sizeof18.1MBcalledmyvideo.mp4.IwouldliketoconvertthattoaFlashVideo,considerablyloweringitsquality.Thisisaccomplishedwith
FFmpegveryeasilybyissuingthefollowingcommand(notetheuseofforwardslashesforthepaths):
JOIN US
ffmpeg.exeiC:/myvideo.mp4C:/myvideo.flv With 1,240,600 monthlyuniquevisitors
Hereiswhattheconsoleoutputlookslike: 500 authorsweareplacedamongtheto
relatedsitesaround.Constantlybeingont
FFmpegversionSVNr21231Sherpya,Copyright(c)20002010FabriceBellard,etal.
lookoutforpartnersweencourageyouto
builtonJan16201005:42:31withgcc4.2.520080919(prerelease)[Sherpya]libavutil50.7.0/50.7.0 SoIfyouhaveablogwithuniqueandinte
libavcodec52.47.0/52.47.0 contentthenyoushouldcheckoutour
libavformat52.47.0/52.47.0 program.Youcan
libavdevice52.2.0/52.2.0 guestwriter
libavfilter1.15.0/1.15.0 CodeGeeksandh
writingskills!
libswscale0.8.0/0.8.0
libpostproc51.2.0/51.2.0
Seemsstream1codecframeratediffersfromcontainerframerate:59.92(14981/250)>29.96(14981/500)
Input#0,mov,mp4,m4a,3gp,3g2,mj2,fromC:/myvideo.mp4:
Metadata:
major_brand:mp42
minor_version:0
compatible_brands:isomavc1mp42
Duration:00:04:20.96,start:0.000000,bitrate:582kb/s
Stream#0.0(und):Audio:aac,44100Hz,stereo,s16,115kb/s
Stream#0.1(und):Video:h264,yuv420p,480270[PAR1:1DAR16:9],464kb/s,29.96fps,29.96tbr,29962tbn,59.92tbc
Output#0,flv,toC:/myvideo.flv:
Stream#0.0(und):Video:flv,yuv420p,480270[PAR1:1DAR16:9],q=231,200kb/s,1ktbn,29.96tbc
Stream#0.1(und):Audio:libmp3lame,44100Hz,stereo,s16,64kb/s
Streammapping:
Stream#0.1>#0.0
Stream#0.0>#0.1
Press[q]tostopencoding
[libmp3lame@0038f3a0]lame:outputbuffertoosmall(bufferindex:9404,freebytes:388)
Audioencodingfailed
IgnoretheAudioencodingfailedmessage,thereisnoerror.Theoutcomeisanice,playableFLVfilenamedmyvideo.flvwithasizeof
10.1MB.
Cool,letsproceedwithinstallingXuggler.FirstwegetthelatestversionfromtheXugglerdownloadspage.Asstatedthere:
TheXuggleriscomposedoftwomaincomponentsasetofJavajarfiles,andasetofnativesharedlibraries(.dllfilesonWindows,.sofiles
onLinux,or.dylibfilesonMac).Touseyouneedtofirstinstallthenativelibraries,andthenyoucanwriteprogramsthatusetheXuggler.
MakesureyoudownloadthecorrectfilematchingyourOSsarchitectureandyourJavaversion.ForexampleIdownloadedthe32Bit(no64
bitforWindows),Java1.5orlaterversionforWindows,whichisbasicallyaninstaller.
Youcanfindinstructionsonhowtoinstallthenativelibrariesinthedownloadspage.ForWindows,youuninstallanypreviousversions,runthe
installerandofcourseyourebootyourcomputer.ThereisalsoavideodescribinghowtoinstallXuggleronMicrosoftWindows.Afterthe
reboot,letstestiftheinstallationwassuccessful.FirstwecheckiftheXugglepathvariablehasbeenset:
C:\>echo%XUGGLE_HOME%
C:\ProgramFiles(x86)\Xuggle
Thepathhasbeencorrectlyset.NotethattheXugglerFFmpegexecutableresidesinthe%XUGGLE_HOME%/binfolder.
Letsplayourfirstvideobyissuingthefollowingcommand(replacethec:/myvideo.mp4withafileofyours):
javacp%XUGGLE_HOME%\share\java\jars\xugglexuggler.jarcom.xuggle.xuggler.demos.DecodeAndPlayVideoc:/myvideo.mp4
TimetowriteourfirstcodewithXuggler.Wearegoingtoinspectavideofile,findoutitsmediacontainer,andprintoutasummaryofthe
contents.Meanwhile,bookmarktheXuggleAPIJavadocsforfuturereference.
FireupyourfavoriteIDE,createanewprojectandimportalltheJARfilesfoundinthe%XUGGLE_HOME%/share/java/jarsfolder.The
exampleissimilartotheoneprovidedintheHowToWriteYourFirstXugglerApplicationInEclipsepost.
01 packagecom.javacodegeeks.xuggler.intro;
02
03 importcom.xuggle.xuggler.ICodec;
04 importcom.xuggle.xuggler.IContainer;
05 importcom.xuggle.xuggler.IStream;
06 importcom.xuggle.xuggler.IStreamCoder;
07
08 publicclassVideoInfo{
09
10 privatestaticfinalStringfilename="c:/myvideo.mp4";
11
12 publicstaticvoidmain(String[]args){
13
14 //firstwecreateaXugglercontainerobject
15 IContainercontainer=IContainer.make();
16
17 //weattempttoopenupthecontainer
18 intresult=container.open(filename,IContainer.Type.READ,null);
19
20 //checkiftheoperationwassuccessful
21 if(result<0)
22 thrownewRuntimeException("Failedtoopenmediafile");
23
24 //queryhowmanystreamsthecalltoopenfound
25 intnumStreams=container.getNumStreams();
26
27 //queryforthetotalduration
28 longduration=container.getDuration();
29
30 //queryforthefilesize
31 longfileSize=container.getFileSize();
32
33 //queryforthebitrate
34 longbitRate=container.getBitRate();
35
36 System.out.println("Numberofstreams:"+numStreams);
37 System.out.println("Duration(ms):"+duration);
38 System.out.println("FileSize(bytes):"+fileSize);
39 System.out.println("BitRate:"+bitRate);
40
41 //iteratethroughthestreamstoprinttheirmetadata
41 //iteratethroughthestreamstoprinttheirmetadata
42 for(inti=0;i<numStreams;i++){
43
44 //findthestreamobject
45 IStreamstream=container.getStream(i);
46
47 //getthepreconfigureddecoderthatcandecodethisstream;
48 IStreamCodercoder=stream.getStreamCoder();
49
50 System.out.println("***StartofStreamInfo***");
51
52 System.out.printf("stream%d:",i);
53 System.out.printf("type:%s;",coder.getCodecType());
54 System.out.printf("codec:%s;",coder.getCodecID());
55 System.out.printf("duration:%s;",stream.getDuration());
56 System.out.printf("starttime:%s;",container.getStartTime());
57 System.out.printf("timebase:%d/%d;",
58 stream.getTimeBase().getNumerator(),
59 stream.getTimeBase().getDenominator());
60 System.out.printf("codertb:%d/%d;",
61 coder.getTimeBase().getNumerator(),
62 coder.getTimeBase().getDenominator());
63 System.out.println();
64
65 if(coder.getCodecType()==ICodec.Type.CODEC_TYPE_AUDIO){
66 System.out.printf("samplerate:%d;",coder.getSampleRate());
67 System.out.printf("channels:%d;",coder.getChannels());
68 System.out.printf("format:%s",coder.getSampleFormat());
69 }
70 elseif(coder.getCodecType()==ICodec.Type.CODEC_TYPE_VIDEO){
71 System.out.printf("width:%d;",coder.getWidth());
72 System.out.printf("height:%d;",coder.getHeight());
73 System.out.printf("format:%s;",coder.getPixelType());
74 System.out.printf("framerate:%5.2f;",coder.getFrameRate().getDouble());
75 }
76
77 System.out.println();
78 System.out.println("***EndofStreamInfo***");
79
80 }
81
82 }
83
84 }
WestartbyobtaininganIContainerinstance,whichisadatasourcethatcontainsoneormorestreamsofaudioandvideodata.Wethen
attempttoopenthemediafileandmakeitreadyforreading.Iftheoperationissuccessful,wecaneasilyretrieveinformationsuchasthe
numberofstreamscontained,thetotalduration,thefilesizeandthebitrate.
Notethatthisinformationrespondstothecontaineritself.However,wecanobtainmetadataregardingtheindividualstreamsthatthe
containerconsistsof.WeusethegetStreammethodtotakereferenceofthecorrespondingstreamandthenanIstreamCoderwhichisthe
decoderthatcandecodetheparticularstream.Fromthatobject,wecanfindthestreamscodectype,codecIDandabunchofother
information.
Finally,weareabletodistinguishamongaudioandvideostreams.Foraudiostreams,wecanfindthesamplerateused,thenumberof
channelsandtheaudiosampleformat.Likewise,forvideostreams,wecangetdimensions(widthandheight),thepixelformatandtheframe
rate.
Hereiswhatasampleoutputwilllooklike:
Numberofstreams:2
Duration(ms):260963888
FileSize(bytes):19007074
BitRate:582672
***StartofStreamInfo***
stream0:type:CODEC_TYPE_AUDIOcodec:CODEC_ID_AACduration:11507712starttime:0timebase:1/44100codertb:1/44100
samplerate:44100channels:2format:FMT_S16
***EndofStreamInfo***
***StartofStreamInfo***
stream1:type:CODEC_TYPE_VIDEOcodec:CODEC_ID_H264duration:7819000starttime:0timebase:1/29962codertb:250/14981
width:480height:270format:YUV420Pframerate:29.96
***EndofStreamInfo***
Thatsallguys.AsoftintroductiontoXugglerforvideomanipulation.Asalways,youcandownloadtheEclipseprojectcreatedforthistutorial.
InthenexttutorialsIwillshowyousomecoolerstuffthatcanbedonewithXugglerandFFmpeg,likevideoconversionandmodification.So,
staytunedhereatJavaCodeGeeks!Anddontforgettoshare!
RelatedArticles:
RTMPToRTSPrestreamusingwowzaandxuggler
XugglerTutorial:TranscodingandMediaModification
XugglerTutorial:FramesCaptureandVideoCreation
InstallAndroidOSonyourPCwithVirtualBox
DoyouwanttoknowhowtodevelopyourskillsettobecomeaJava
Rockstar?
SubscribetoournewslettertostartRockingrightnow!
TogetyoustartedwegiveyouourbestsellingeBooksforFREE!
1.JPAMiniBook
2.JVMTroubleshootingGuide
3.JUnitTutorialforUnitTesting
4.JavaAnnotationsTutorial
5.JavaInterviewQuestions
6.SpringInterviewQuestions
7.AndroidUIDesign
andmanymore....
Emailaddress:
Youremailaddress
Signup
Try it free
Google Cloud provides a scalable
range of computing options tailored
to match your needs.
8 COMMENTS
humanonomics
November23rd,2012at4:04pm
IfIwanttoextractDateandTimeofcreationofthevideoinformation,howdoIdothatusingXuggler?
Reply
DheerajSingh
June21st,2013at9:28am
Hi,isMplayerwin32.exeavailableforwin64bitmachine?
Reply
Akash
October7th,2014at9:18am
Howtoenableloggerinxuggler?toseethegeneratinglogs.
Reply
amal
December1st,2014at1:45pm
itriedtoexecutethiscodeinnetbeans
andifoundsomeerrors
thoseare,
SLF4J:Failedtoloadclassorg.slf4j.impl.StaticLoggerBinder.
SLF4J:Defaultingtonooperation(NOP)loggerimplementation
SLF4J:Seehttp://www.slf4j.org/codes.html#StaticLoggerBinderforfurtherdetails.
Exceptioninthreadmainjava.lang.ArrayIndexOutOfBoundsException:0
atblesson.DecodeAndCaptureFrames.main(DecodeAndCaptureFrames.java:85)
JavaResult:1
whattodo?
Reply
Devraijada
March11th,2015at8:37am
Youshoulddownloadslf4japi,,,.StaticLoggerBinderclassismissingwhichcomesinslf4japi
Reply
ahmed
August28th,2015at4:50pm
ifoundsomeerrors
Exceptioninthreadmainjava.lang.NoClassDefFoundError:org/slf4j/LoggerFactory
atcom.xuggle.ferry.JNILibrary.(JNILibrary.java:42)
atcom.xuggle.ferry.FerryJNI.(FerryJNI.java:14)
atcom.xuggle.ferry.Ferry.(Ferry.java:25)
atcom.xuggle.xuggler.XugglerJNI.(XugglerJNI.java:19)
atcom.xuggle.xuggler.IContainer.(IContainer.java:1622)
atxuggle.VideoInfo.main(VideoInfo.java:22)
Causedby:java.lang.ClassNotFoundException:org.slf4j.LoggerFactory
atjava.net.URLClassLoader.findClass(URLClassLoader.java:381)
atjava.lang.ClassLoader.loadClass(ClassLoader.java:424)
atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
atjava.lang.ClassLoader.loadClass(ClassLoader.java:357)
6more
JavaResult:1
Reply
saifullahminhas
September8th,2015at7:31pm
Itappearsthatsl4jjarismissingordamagedcauseofwhichclassisnotfound,pleasedownloaditsjarandaddit.Usethis
linkfordownload
http://www.slf4j.org/download.html
Reply
murali
October7th,2016at3:22pm
17:50:34.053[main]ERRORcom.xuggle.ferry.JNILibraryLoaderCouldnotloadlibrary:xuggleversion:5Visit
http://www.xuggle.com/xuggler/faq/tofindcommonsolutionstothisproblem
Exceptioninthreadmainjava.lang.UnsatisfiedLinkError:noxuggleinjava.library.path
atjava.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
atjava.lang.Runtime.loadLibrary0(Runtime.java:870)
atjava.lang.System.loadLibrary(System.java:1122)
atcom.xuggle.ferry.JNILibraryLoader.loadLibrary0(JNILibraryLoader.java:268)
atcom.xuggle.ferry.JNILibraryLoader.loadLibrary(JNILibraryLoader.java:171)
atcom.xuggle.ferry.JNILibrary.load(JNILibrary.java:161)
atcom.xuggle.ferry.FerryJNI.(FerryJNI.java:16)
atcom.xuggle.ferry.Ferry.(Ferry.java:25)
atcom.xuggle.xuggler.XugglerJNI.(XugglerJNI.java:19)
atcom.xuggle.xuggler.IContainer.(IContainer.java:1622)
atcom.med.info.VideoInfo.main(VideoInfo.java:15)
Reply
LEAVE A REPLY
Youremailaddresswillnotbepublished.Requiredfieldsaremarked*
Name*
Email*
Website
Signmeupforthenewsletter!
ReceiveEmailNotifications?
no,donotsubscribe instantly
Or,youcansubscribewithoutcommenting.
PostComment
JCGs(JavaCodeGeeks)isanindependentonlinecommunityfocusedoncreating
Courses AndroidFullApplicationTutorialseries
ultimateJavatoJavadevelopersresourcecentertargetedatthetechnicalarchite
technicalteamlead(seniordeveloper),projectmanagerandjuniordevelopersal
Examples 11OnlineLearningwebsitesthatyou
JCGsservetheJava,SOA,AgileandTelecomcommunitieswithdailynewswritte
shouldcheckout
domainexperts,articles,tutorials,reviews,announcements,codesnippetsandop
domainexperts,articles,tutorials,reviews,announcements,codesnippetsandop
Resources AdvantagesandDisadvantagesofCloud
sourceprojects.
ComputingCloudcomputingprosand
Tutorials cons
DISCLAIMER
Whitepapers AndroidGoogleMapsTutorial
AlltrademarksandregisteredtrademarksappearingonJavaCodeGeeksarethe
AndroidJSONParsingwithGsonTutorial
propertyoftheirrespectiveowners.Javaisatrademarkorregisteredtrademark
PARTNERS OracleCorporationintheUnitedStatesandothercountries.ExamplesJavaCode
AndroidLocationBasedServices
isnotconnectedtoOracleCorporationandisnotsponsoredbyOracleCorporatio
ApplicationGPSlocation
Mkyong
AndroidQuickPreferencesTutorial
.NETCodeGeeks GWT2Spring3JPA2Hibernate3.5
Tutorial
JavaCodeGeeks
JavaBestPracticesVectorvsArrayListvs
SystemCodeGeeks HashSet
WebCodeGeeks
JavaCodeGeeksandallcontentcopyright20102017,ExelixisMediaP.C.|TermsofUse|PrivacyPolicy|Contact