这是我用来使用 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 时,输出文件没有声音。请指教。