gpt4 book ai didi

Android MediaRecorder制作旋转视频

转载 作者:太空狗 更新时间:2023-10-29 14:26:17 26 4
gpt4 key购买 nike

我一直在尝试让 MediaRecorder 按照官方示例工作,虽然我能够制作一个顺时针旋转 90 度的文件...

现在我在纵向模式下尝试这个并且确实将预览表面旋转了 90 度并将其锁定为纵向模式...

我不知道如何解决这个问题并获得纵向视频,并且尝试了与该主题相关的无数解决方案都无济于事...

代码:

public class CameraRecorder {

private Camera cam;
private MediaRecorder mMediaRecorder;
private CameraPreview mPreview;
private static Context mContext;

public CameraRecorder(CameraPreview preview, Context context){

mPreview = preview;
cam = mPreview.getCamera();
//cam.getParameters().setRotation(0);
mContext = context;

}

public boolean prep(){


mMediaRecorder = new MediaRecorder();
//mMediaRecorder.setOrientationHint(90);

// Step 1: Unlock and set camera to MediaRecorder
cam.unlock();
mMediaRecorder.setCamera(cam);

// Step 2: Set sources
//mMediaRecorder.setAudioSource(mContext.openFileInput());
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);


// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
//mMediaRecorder.setVideoSize(mPreview.getMeasuredWidth(), mPreview.getMeasuredHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);

//mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));

// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile().toString());

// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

// Step 6: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d("Exception", "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d("Exception", "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (Exception e) {
Log.d("Exception", "Exception preparing MediaRecorder: " + e.getMessage());
return false;
}
return true;

}

public static File getOutputMediaFile(){

File mediaFile;

mediaFile = new File(mContext.getCacheDir() + File.separator + "vid.mp4");

return mediaFile;


}

public void releaseMediaRecorder(){

if (mMediaRecorder != null) {
mMediaRecorder.reset(); // clear recorder configuration
mMediaRecorder.release(); // release the recorder object
mMediaRecorder = null;
cam.lock(); // lock camera for later use
}

}

public void startRecording(){

mMediaRecorder.start();

}

public void stopRecording(){

try {
mMediaRecorder.stop(); // stop the recording
releaseMediaRecorder(); // release the MediaRecorder object
cam.lock();
} catch (Exception e) {
Log.d("Exception","Exiting with exception: " + e.getMessage());
}



}



}

我已经尝试了评论方法的各种组合,但没有结果(设置特定的视频大小会导致“尝试删除损坏的文件”错误,所以我把它留了下来)......顺便说一句,我故意忽略了音频源,因为我只需要视频(我需要稍后拼接音频,而且确实也不知道从哪里开始)

非常感谢任何提示、想法或指示!

最佳答案

您不能旋转视频。只是预览表面或静止图像。但不是视频流。

关于Android MediaRecorder制作旋转视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12252927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com