我只想合并同一帧和分辨率的多个视频。 我在下面找到了代码 -
String filenamevideo = "f:/testvidfol/video.mp4"; //video file on your disk
String filenameaudio = "f:/testvidfol/audio.wav"; //audio file on your disk
IMediaWriter mWriter = null;
try{
String mpath = path+"videowriter.flv";
mWriter = ToolFactory.makeWriter(mpath); //output file
}
catch(Exception e){
e.printStackTrace();
}
IContainer containerVideo = IContainer.make();
IContainer containerAudio = IContainer.make();
if (containerVideo.open(filenamevideo, IContainer.Type.READ, null) < 0)
throw new IllegalArgumentException("Cant find " + filenamevideo);
if (containerAudio.open(filenameaudio, IContainer.Type.READ, null) < 0)
throw new IllegalArgumentException("Cant find " + filenameaudio);
int numStreamVideo = containerVideo.getNumStreams();
int numStreamAudio = containerAudio.getNumStreams();
System.out.println("Number of video streams: "+numStreamVideo + "\n" + "Number of audio streams: "+numStreamAudio );
int videostreamt = -1; //this is the video stream id
int audiostreamt = -1;
IStreamCoder videocoder = null;
for(int i=0; i<numStreamVideo; i++){
IStream stream = containerVideo.getStream(i);
IStreamCoder code = stream.getStreamCoder();
if(code.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO)
{
videostreamt = i;
videocoder = code;
break;
}
}
for(int i=0; i<numStreamAudio; i++){
IStream stream = containerAudio.getStream(i);
IStreamCoder code = stream.getStreamCoder();
if(code.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO)
{
audiostreamt = i;
break;
}
}
if (videostreamt == -1) throw new RuntimeException("No video steam found");
if (audiostreamt == -1) throw new RuntimeException("No audio steam found");
if(videocoder.open()<0 ) throw new RuntimeException("Cant open video coder");
IPacket packetvideo = IPacket.make();
IStreamCoder audioCoder = containerAudio.getStream(audiostreamt).getStreamCoder();
if(audioCoder.open()<0 ) throw new RuntimeException("Cant open audio coder");
mWriter.addAudioStream(0, 0, audioCoder.getChannels(), audioCoder.getSampleRate());
mWriter.addVideoStream(1, 1, videocoder.getWidth(), videocoder.getHeight());
IPacket packetaudio = IPacket.make();
while(containerVideo.readNextPacket(packetvideo) >= 0 ||
containerAudio.readNextPacket(packetaudio) >= 0){
if(packetvideo.getStreamIndex() == videostreamt){
//video packet
IVideoPicture picture = IVideoPicture.make(videocoder.getPixelType(),
videocoder.getWidth(),
videocoder.getHeight());
int offset = 0;
while (offset < packetvideo.getSize()){
int bytesDecoded = videocoder.decodeVideo(picture,
packetvideo,
offset);
if(bytesDecoded < 0) throw new RuntimeException("bytesDecoded not working");
offset += bytesDecoded;
if(picture.isComplete()){
System.out.println(picture.getPixelType());
mWriter.encodeVideo(1, picture);
}
}
}
if(packetaudio.getStreamIndex() == audiostreamt){
//audio packet
IAudioSamples samples = IAudioSamples.make(512,
audioCoder.getChannels());
int offset = 0;
while(offset<packetaudio.getSize())
{
int bytesDecodedaudio = audioCoder.decodeAudio(samples,
packetaudio,
offset);
if (bytesDecodedaudio < 0)
throw new RuntimeException("could not detect audio");
offset += bytesDecodedaudio;
if (samples.isComplete()){
mWriter.encodeAudio(0, samples);
}
}
}
}
我在构建路径中添加了jar -
1.log4j-1.2.16.jar
2.slf4j-simple-1.7.7.jar
3.slf4j-api-1.7.7.jar
4.xuggle-xuggler-3.0.660.jar
以下是我的日志cat错误,当我运行我的代码 -
java.lang.UnsatisfiedLinkError: Native method not found: com.xuggle.ferry.FerryJNI.IBuffer_make__SWIG_0:(JLcom/xuggle/ferry/RefCounted;I)J
at com.xuggle.ferry.FerryJNI.IBuffer_make__SWIG_0(Native Method)
at com.xuggle.ferry.IBuffer.make(IBuffer.java:1088)
at com.xuggle.ferry.FerryJNI.<clinit>(FerryJNI.java:21)
at com.xuggle.ferry.JNIMemoryManager.setMemoryModel(JNIMemoryManager.java:1190)
at com.xuggle.mediatool.MediaWriter.<clinit>(MediaWriter.java:119)
at com.xuggle.mediatool.ToolFactory.makeWriter(ToolFactory.java:149)
at com.yps.demo.CameraRecordingActivity.mergeFiles(CameraRecordingActivity.java:84)
at com.yps.demo.CameraRecordingActivity.onCreate(CameraRecordingActivity.java:69)
at android.app.Activity.performCreate(Activity.java:5141)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1150)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2315)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$600(ActivityThread.java:165)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5387)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
请帮我解决这个问题。 提前致谢