这是我使用JavaCV和ffmpeg在android中调整视频大小的代码 -
FFmpegFrameGrabber grabber = new FmpegFrameGrabber("/sdcard/DCIM/100MEDIA/VIDEO0066.mp4");
grabber.start();
int w = (int)grabber.getImageWidth()/2;
int h = (int)grabber.getImageHeight()/2;
if (w%2 != 0) w=w-1;
if (h%2 != 0) h=h-1;
FrameRecorder recorder = new FFmpegFrameRecorder("/sdcard/DCIM/output.mov", w, h ,grabber.getAudioChannels());
recorder.setVideoCodec(avcodec.CODEC_ID_MPEG4);
recorder.setPixelFormat(avutil.PIX_FMT_YUV420P);
recorder.setAudioCodec(avcodec.CODEC_ID_PCM_S16LE);
recorder.start();
Frame frame = null;
while ((frame = grabber.grabFrame()) != null)
{
IplImage source = frame.image;
if (source!=null)
{
IplImage destination = cvCreateImage(cvSize(w , h), source.depth(), source.nChannels() );
cvResize(source, destination);
frame.image = destination;
recorder.record(frame);
}
}
如果我使用的原始宽度和高度比视频有声,但是当我使用w / 2和h / 2时,输出文件没有声音。 请指教。