Search in sources :

Example 26 with MediaInfo

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

the class DemoFunctions method demoVideoConcat.

/**
 * 视频拼接 ,
 *
 * 为了方便演示,需要您的视频大于20秒(或用默认视频).先把原视频从(0到1/3处)和(2/3到结束)截取成两段,这样就有了两个独立的视频, 然后把这两段拼接在一起,来演示视频的拼接,
 * 您实际可任意的组合,注意尽量视频的宽高比等参数一致,不然合成是可以,但有些播放器无法播放.
 */
public static int demoVideoConcat(VideoEditor editor, String srcVideo, String dstVideo) {
    MediaInfo info = new MediaInfo(srcVideo);
    int ret = -1;
    if (info.prepare() && info.vDuration > 20) {
        // 第一步:先创建三个视频文件,并剪切好视频.
        String seg1 = SDKFileUtils.createFileInBox(info.fileSuffix);
        String seg2 = SDKFileUtils.createFileInBox(info.fileSuffix);
        String segTs1 = SDKFileUtils.createFileInBox("ts");
        String segTs2 = SDKFileUtils.createFileInBox("ts");
        ret = editor.executeVideoCutOut(srcVideo, seg1, 0, info.vDuration / 3);
        ret = editor.executeVideoCutOut(srcVideo, seg2, info.vDuration * 2 / 3, info.vDuration);
        // 第二步: 把他们转换为ts格式.
        ret = editor.executeConvertMp4toTs(seg1, segTs1);
        ret = editor.executeConvertMp4toTs(seg2, segTs2);
        // 第三步: 把ts文件拼接成mp4
        ret = editor.executeConvertTsToMp4(new String[] { segTs1, segTs2 }, dstVideo);
        // 第四步: 删除之前的临时文件.
        SDKFileUtils.deleteFile(segTs2);
        SDKFileUtils.deleteFile(segTs1);
        SDKFileUtils.deleteFile(seg2);
        SDKFileUtils.deleteFile(seg1);
    }
    return ret;
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo)

Example 27 with MediaInfo

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

the class DemoFunctions method demoGetOneFrame.

/**
 * 获取一张图片
 */
public static int demoGetOneFrame(VideoEditor editor, String srcVideo, String dstVideo) {
    MediaInfo info = new MediaInfo(srcVideo);
    if (info.prepare()) {
        // 这里是保存的路径
        String picPath = SDKFileUtils.createFileInBox("png");
        Log.i("lansosdk", "picture save at " + picPath);
        return editor.executeGetOneFrame(srcVideo, info.vCodecName, info.vDuration / 2, picPath);
    } else {
        return -1;
    }
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo)

Example 28 with MediaInfo

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

the class DemoFunctions method demoVideoScale.

/**
 * 视频画面缩放[软件缩放],
 *
 * 视频缩放:缩小视频的宽度和高度\n 这里演示把宽度和高度都缩小一半.\n 注意:这里是采用软缩放的形式来做,流程是:硬解码-->软件缩放-->硬编码
 */
public static int demoVideoScale(VideoEditor editor, String srcVideo, String dstVideo) {
    MediaInfo info = new MediaInfo(srcVideo);
    if (info.prepare()) {
        float f = (float) info.vBitRate;
        f *= 0.7f;
        return editor.executeVideoFrameScale(srcVideo, info.vWidth / 2, info.vHeight / 2, dstVideo, (int) f);
    } else {
        return -1;
    }
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo)

Example 29 with MediaInfo

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

the class DemoFunctions method demoPaddingVideo.

/**
 * 视频增加边框
 */
public static int demoPaddingVideo(VideoEditor editor, String srcVideo, String dstVideo) {
    MediaInfo info = new MediaInfo(srcVideo);
    if (info.prepare()) {
        int bitrate = (int) (info.vBitRate * 1.5f);
        if (bitrate > 2000 * 1000)
            // 2M
            bitrate = 2000 * 1000;
        // 向外padding32个像素
        int width = info.vCodecWidth + 32;
        int height = info.vCodecHeight + 32;
        return editor.executePadingVideo(srcVideo, info.vCodecName, width, height, 0, 0, dstVideo, (int) (info.vBitRate * 1.5f));
    } else {
        return -1;
    }
}
Also used : MediaInfo(com.lansosdk.videoeditor.MediaInfo)

Example 30 with MediaInfo

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

the class DemoFunctions method demoFrameCrop.

/**
 * 演示视频画面裁剪
 *
 * 视频画面裁剪:裁剪视频的宽度和高度\n 这里演示从左上角裁剪视频高度和宽度为原来的一半保存为新的视频.\n
 */
public static int demoFrameCrop(VideoEditor editor, String srcVideo, String dstVideo) {
    MediaInfo info = new MediaInfo(srcVideo);
    if (info.prepare()) {
        float dstBr = (float) info.vBitRate;
        dstBr *= 0.4f;
        int dstBr2 = (int) dstBr;
        // 检查宽高
        int width = info.vCodecWidth;
        int height = info.vCodecHeight;
        if (info.vRotateAngle == 90 || info.vRotateAngle == 270) {
            width = info.vCodecHeight;
            height = info.vCodecWidth;
        }
        return editor.executeVideoFrameCrop(srcVideo, width / 2, height / 2, 0, 0, dstVideo, info.vCodecName, dstBr2);
    // return editor.executeVideoFrameCrop(srcVideo, width, height, 0, 0, dstVideo, info.vCodecName,dstBr2);  //测试.
    } 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