Search in sources :

Example 1 with FileParameter

use of com.lansosdk.box.FileParameter in project LanSoEditor_advance by LanSoSdk.

the class VideoOneDo method startDrawPad.

private boolean startDrawPad() {
    // 先判断有无裁剪画面
    if (cropHeight > 0 && cropWidth > 0) {
        fileParamter = new FileParameter();
        fileParamter.setDataSoure(videoPath);
        /**
         * 设置当前需要显示的区域 ,以左上角为0,0坐标.
         *
         * @param startX  开始的X坐标, 即从宽度的什么位置开始
         * @param startY  开始的Y坐标, 即从高度的什么位置开始
         * @param cropW   需要显示的宽度
         * @param cropH   需要显示的高度.
         */
        fileParamter.setShowRect(startX, startY, cropWidth, cropHeight);
        fileParamter.setStartTimeUs(startTimeUs);
        int padWidth = cropWidth;
        int padHeight = cropHeight;
        if (scaleHeight > 0 && scaleWidth > 0) {
            padWidth = scaleWidth;
            padHeight = scaleHeight;
        }
        float f = (float) (padHeight * padWidth) / (float) (fileParamter.info.vWidth * fileParamter.info.vHeight);
        float bitrate = f * fileParamter.info.vBitRate * compressFactor * 2.0f;
        drawPad = new DrawPadVideoExecute(context, fileParamter, padWidth, padHeight, (int) bitrate, videoFilter, dstPath);
    } else {
        // 没有裁剪
        int padWidth = srcInfo.getWidth();
        int padHeight = srcInfo.getHeight();
        float bitrate = (float) srcInfo.vBitRate * compressFactor * 1.5f;
        if (scaleHeight > 0 && scaleWidth > 0) {
            padWidth = scaleWidth;
            padHeight = scaleHeight;
            float f = (float) (padHeight * padWidth) / (float) (srcInfo.vWidth * srcInfo.vHeight);
            bitrate *= f;
        }
        drawPad = new DrawPadVideoExecute(context, videoPath, startTimeUs, padWidth, padHeight, (int) bitrate, videoFilter, dstPath);
    }
    drawPad.setUseMainVideoPts(true);
    drawPad.setDrawPadErrorListener(new onDrawPadErrorListener() {

        @Override
        public void onError(DrawPad d, int what) {
            if (monVideoOneDoErrorListener != null) {
                monVideoOneDoErrorListener.oError(VideoOneDo.this, VIDEOONEDO_ERROR_DRAWPAD);
            }
        }
    });
    /**
     * 设置DrawPad处理的进度监听, 回传的currentTimeUs单位是微秒.
     */
    drawPad.setDrawPadProgressListener(new onDrawPadProgressListener() {

        @Override
        public void onProgress(DrawPad v, long currentTimeUs) {
            progressCallback(v, currentTimeUs);
            if (monVideoOneDoProgressListener != null) {
                float time = (float) currentTimeUs / 1000000f;
                float percent = time / (float) tmpvDuration;
                // 保留两位小数.
                float b = (float) (Math.round(percent * 100)) / 100;
                if (b < 1.0f && monVideoOneDoProgressListener != null && isExecuting) {
                    monVideoOneDoProgressListener.onProgress(VideoOneDo.this, b);
                }
            }
            if (cutDurationUs > 0 && currentTimeUs > cutDurationUs) {
                // 设置了结束时间, 如果当前时间戳大于结束时间,则停止容器.
                drawPad.stopDrawPad();
            }
        }
    });
    // 容器内部的进度回调.
    drawPad.setDrawPadThreadProgressListener(new onDrawPadThreadProgressListener() {

        @Override
        public void onThreadProgress(DrawPad v, long currentTimeUs) {
            progressThreadCallback(v, currentTimeUs);
        }
    });
    /**
     * 设置DrawPad处理完成后的监听.
     */
    drawPad.setDrawPadCompletedListener(new onDrawPadCompletedListener() {

        @Override
        public void onCompleted(DrawPad v) {
            completeDrawPad();
        }
    });
    /**
     * 增加音频参数.
     */
    addAudioParamter();
    /**
     * 增加时间拉伸.
     */
    if (timeStretchArray != null) {
        drawPad.addTimeStretch(timeStretchArray);
    }
    if (timeRepeatArray != null) {
        drawPad.addTimeRepeat(timeRepeatArray);
    }
    if (timeFreezeArray != null) {
        drawPad.addTimeFreeze(timeFreezeArray);
    }
    drawPad.pauseRecord();
    if (drawPad.startDrawPad()) {
        videoLayer = drawPad.getMainVideoLayer();
        videoLayer.setScaledValue(videoLayer.getPadWidth(), videoLayer.getPadHeight());
        // 增加图片图层
        addBitmapLayer();
        // 增加文字图层.
        addCanvasLayer();
        // 开始恢复处理.
        drawPad.resumeRecord();
        return true;
    } else {
        return false;
    }
}
Also used : DrawPad(com.lansosdk.box.DrawPad) com.lansosdk.box.onDrawPadErrorListener(com.lansosdk.box.onDrawPadErrorListener) com.lansosdk.box.onDrawPadProgressListener(com.lansosdk.box.onDrawPadProgressListener) FileParameter(com.lansosdk.box.FileParameter) com.lansosdk.box.onDrawPadThreadProgressListener(com.lansosdk.box.onDrawPadThreadProgressListener) com.lansosdk.box.onDrawPadCompletedListener(com.lansosdk.box.onDrawPadCompletedListener) Paint(android.graphics.Paint)

Example 2 with FileParameter

use of com.lansosdk.box.FileParameter in project LanSoEditor_advance by LanSoSdk.

the class VideoOneDo method setCropRect.

/**
 * 设置裁剪画面的一部分用来处理,
 * 依靠视频呈现出怎样的区域来裁剪.
 * 比如视频显示720x1280,则您可以认为视频画面的宽度就是720,高度就是1280;不做其他角度的判断.
 * <p>
 * 裁剪后, 如果设置了缩放,则会把cropW和cropH缩放到指定的缩放宽度.
 *
 * @param startX 画面的开始横向坐标,
 * @param startY 画面的结束纵向坐标
 * @param cropW  裁剪多少宽度
 * @param cropH  裁剪多少高度
 */
public void setCropRect(int startX, int startY, int cropW, int cropH) {
    fileParamter = new FileParameter();
    this.startX = startX;
    this.startY = startY;
    cropWidth = cropW;
    cropHeight = cropH;
}
Also used : FileParameter(com.lansosdk.box.FileParameter)

Aggregations

FileParameter (com.lansosdk.box.FileParameter)2 Paint (android.graphics.Paint)1 DrawPad (com.lansosdk.box.DrawPad)1 com.lansosdk.box.onDrawPadCompletedListener (com.lansosdk.box.onDrawPadCompletedListener)1 com.lansosdk.box.onDrawPadErrorListener (com.lansosdk.box.onDrawPadErrorListener)1 com.lansosdk.box.onDrawPadProgressListener (com.lansosdk.box.onDrawPadProgressListener)1 com.lansosdk.box.onDrawPadThreadProgressListener (com.lansosdk.box.onDrawPadThreadProgressListener)1