Search in sources :

Example 31 with MediaInfo

use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_common by LanSoSdk.

the class DemoFunctions method demoVideoCropOverlay.

/**
 * 演示 先剪切, 再画面裁剪,再图片叠加.
 */
public static int demoVideoCropOverlay(Context ctx, VideoEditor editor, String srcVideo, String dstVideo) {
    MediaInfo info = new MediaInfo(srcVideo);
    if (info.prepare()) {
        String imagePath = CopyDefaultVideoAsyncTask.copyFile(ctx, "ic_launcher.png");
        int cropW = 240;
        int cropH = 240;
        int max = Math.max(info.vWidth, info.vHeight);
        int cropMax = Math.max(cropW, cropH);
        float dstBr = (float) info.vBitRate;
        float ratio = (float) cropMax / (float) max;
        // 得到恒定码率的等比例值.
        dstBr *= ratio;
        dstBr *= 1.5f;
        return editor.executeCropOverlay(srcVideo, info.vCodecName, imagePath, 20, 20, cropW, cropH, 0, 0, dstVideo, (int) dstBr);
    } else {
        return -1;
    }
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo)

Example 32 with MediaInfo

use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_common by LanSoSdk.

the class ScaleExecuteDemoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_scale_layout);
    tvProgressHint = (TextView) findViewById(R.id.id_video_scale_progress_hint);
    tvSelectFile = (TextView) findViewById(R.id.id_video_scale_selectfilehint);
    videoPath = getIntent().getStringExtra("videopath");
    findViewById(R.id.id_video_scale_startbtn).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (videoPath != null) {
                mInfo = new MediaInfo(videoPath, false);
                if (mInfo.prepare()) {
                    if (mInfo.vDuration >= 60 * 1000) {
                        // 大于60秒
                        showHintDialog();
                    } else {
                        testScaleEdit();
                    }
                }
            }
        }
    });
    findViewById(R.id.id_video_scale_play).setEnabled(false);
    findViewById(R.id.id_video_scale_play).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (SDKFileUtils.fileExist(dstPath)) {
                Intent intent = new Intent(ScaleExecuteDemoActivity.this, VideoPlayerActivity.class);
                intent.putExtra("videopath", dstPath);
                startActivity(intent);
            } else {
                Toast.makeText(ScaleExecuteDemoActivity.this, "目标文件不存在", Toast.LENGTH_SHORT).show();
            }
        }
    });
    // 在手机的默认路径下创建一个文件名,用来保存生成的视频文件,(在onDestroy中删除)
    editTmpPath = SDKFileUtils.newMp4PathInBox();
    dstPath = SDKFileUtils.newMp4PathInBox();
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View)

Example 33 with MediaInfo

use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_common by LanSoSdk.

the class VideoPlayerActivity method play.

private void play(Surface surface) {
    if (videoPath == null)
        return;
    MediaInfo info = new MediaInfo(videoPath);
    if (info.prepare() == false) {
        return;
    }
    Log.i(TAG, "info:" + info.toString());
    mediaPlayer = new MediaPlayer();
    mediaPlayer.reset();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            // TODO Auto-generated method stub
            Toast.makeText(VideoPlayerActivity.this, "视频播放完毕!", Toast.LENGTH_SHORT).show();
        }
    });
    try {
        mediaPlayer.setDataSource(videoPath);
        mediaPlayer.setSurface(surface);
        mediaPlayer.prepare();
        // 因为是竖屏.宽度小于高度.
        if (screenWidth > mInfo.vWidth) {
            tvSizeHint.setText(R.string.origal_width);
            textureView.setDispalyRatio(TextureRenderView.AR_ASPECT_WRAP_CONTENT);
        } else {
            // 大于屏幕的宽度
            tvSizeHint.setText(R.string.fix_width);
            textureView.setDispalyRatio(TextureRenderView.AR_ASPECT_FIT_PARENT);
        }
        textureView.setVideoSize(mediaPlayer.getVideoWidth(), mediaPlayer.getVideoHeight());
        textureView.requestLayout();
        mediaPlayer.start();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo) OnCompletionListener(android.media.MediaPlayer.OnCompletionListener) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Example 34 with MediaInfo

use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_advance by LanSoSdk.

the class DemoFunctions method demoAVMerge.

/**
 * 演示音频和视频合成, 也可以认为是音频替换.
 * <p>
 * 音视频合成:\n把一个纯音频文件和纯视频文件合并成一个mp4格式的多媒体文件, 如果源视频之前有音频,会首先删除音频部分. \n\n
 */
public static int demoAVMerge(Context ctx, VideoEditor editor, String srcVideo, String dstPath) {
    int ret = -1;
    MediaInfo info = new MediaInfo(srcVideo, false);
    if (info.prepare()) {
        String video2 = srcVideo;
        String video3 = null;
        // 如果源视频中有音频,则先删除音频
        if (info.isHaveAudio()) {
            video3 = SDKFileUtils.createFileInBox(info.fileSuffix);
            editor.executeDeleteAudio(video2, video3);
            video2 = video3;
        }
        String audio = CopyDefaultVideoAsyncTask.copyFile(ctx, "aac20s.aac");
        ret = editor.executeVideoMergeAudio(video2, audio, dstPath);
        SDKFileUtils.deleteFile(video3);
    }
    return ret;
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo)

Example 35 with MediaInfo

use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_advance by LanSoSdk.

the class DemoFunctions method demoAudioCut.

/**
 * 演示音频截取
 * <p>
 * 音频剪切:\n剪切音频的长度,可以指定开始位置,指定结束位置.\n这里演示截取音频的前20秒或时长的一半,形成新的音频文件.
 */
public static int demoAudioCut(Context ctx, VideoEditor editor, String dstAudio) {
    String srcAudio = CopyDefaultVideoAsyncTask.copyFile(ctx, "honor30s2.m4a");
    MediaInfo info = new MediaInfo(srcAudio);
    if (info.prepare() && info.aCodecName != null) {
        if (info.aDuration > 15)
            return editor.executeAudioCutOut(srcAudio, dstAudio, 0, 15);
        else
            return editor.executeAudioCutOut(srcAudio, dstAudio, 0, info.aDuration / 2);
    } else {
        return -1;
    }
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo)

Aggregations

MediaInfo (com.lansosdk.videoeditor.MediaInfo)59 Handler (android.os.Handler)12 com.lansosdk.box.onDrawPadSizeChangedListener (com.lansosdk.box.onDrawPadSizeChangedListener)9 Paint (android.graphics.Paint)8 TextView (android.widget.TextView)6 Intent (android.content.Intent)5 View (android.view.View)5 OnClickListener (android.view.View.OnClickListener)5 CanvasRunnable (com.lansosdk.box.CanvasRunnable)5 DrawPad (com.lansosdk.box.DrawPad)5 Bitmap (android.graphics.Bitmap)4 DrawPadView (com.lansosdk.videoeditor.DrawPadView)4 File (java.io.File)3 SurfaceTexture (android.graphics.SurfaceTexture)2 MediaPlayer (android.media.MediaPlayer)2 DisplayMetrics (android.util.DisplayMetrics)2 Surface (android.view.Surface)2 SurfaceTextureListener (android.view.TextureView.SurfaceTextureListener)2 VideoPlayerActivity (com.example.advanceDemo.VideoPlayerActivity)2 DrawPadVideoRunnable (com.lansosdk.box.DrawPadVideoRunnable)2