【问题标题】:Recording a fragment or a view, output video录制片段或视图,输出视频
【发布时间】:2016-02-17 04:47:13
【问题描述】:

场景

我在片段中有(一个图像视图和一个视频视图)或(自定义的东西,如表面视图和在左侧的照片和右侧的视频),我需要将片段布局输出为视频,以加入将照片和视频合并为一个视频。

问题

我真的不知道如何使这项工作,也许是录制屏幕但不专业。也许你能帮助我?一些教程、想法或任何东西都会很好。

谢谢。

【问题讨论】:

  • 嗯..你可以看到我不需要屏幕录像机。
  • 我必须想办法从照片和视频中制作视频。
  • 你可以为此使用 ffmpeg 库

标签: android android-fragments android-video-player android-videoview android-screen-support


【解决方案1】:

虽然this 不是片段,但它可以帮助你。您可以通过 5.0 API 使用 OpenGLES 纹理制作视频。

或制作屏幕录像机服务。像这样,

public boolean startRecord(MediaProjection mediaProjection, File file) {

    mRecorder = new MediaRecorder();
    mRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setAudioSource(MediaRecorder.AudioSource..DEFAULT);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    mRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mRecorder.setOutputFile(file.getPath());
    mRecorder.setMaxDuration(60000);
    mRecorder.setVideoSize(720,1280);

    try {
        mRecorder.prepare();
        mMediaProjection = mediaProjection;
        Surface targetSurface = mRecorder.getSurface();
        mDisplay = mMediaProjection.createVirtualDisplay("ScreenRecorder", 720, 1280, 240,
                DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, targetSurface, null, null);

        mRecorder.start();
        mRecording = true;
        showNotification();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

    return true;
}

在活动中获取 MediaProjection

{
        btnStartRecording.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = mMediaProjectionManager.createScreenCaptureIntent();
                startActivityForResult(intent, REQUEST_CODE_SCREEN_CAST);
            }
        });
}
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_CODE_SCREEN_CAST) {
            if (resultCode != RESULT_OK) {
                Toast.makeText(this, "Permission denied, close this app", Toast.LENGTH_SHORT).show();
                finish();
            }
            mMediaProjection = mMediaProjectionManager.getMediaProjection(resultCode, data);
            if (mMediaProjection == null) {
                return;
            }
            File moviesFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
            File movieFile = new File(moviesFolder, "test.mp4");
            if (mService != null) {
                mService.startRecord(mMediaProjection, movieFile);
            }
            else{
                mMediaProjection.stop();
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

您可以记录显示的所有内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 2016-12-08
    • 2014-07-01
    相关资源
    最近更新 更多