use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_advance by LanSoSdk.
the class ExtractVideoFrameDemoActivity method testExtractVideoFrame.
/**
* 从这里开始演示.
*/
private void testExtractVideoFrame() {
if (isExecuting)
return;
isExecuting = true;
mInfo = new MediaInfo(videoPath);
if (mInfo.prepare() == false || mInfo.isHaveVideo() == false) {
return;
}
/**
* 初始化.
*/
mExtractFrame = new ExtractVideoFrame(ExtractVideoFrameDemoActivity.this, videoPath);
/**
* 设置在获取图片的时候, 可以指定图片的宽高, 指定后, 视频帧画面会被缩放到指定的宽高.
*
* 不调用则内部认为, 如果视频大于等于1280x720则自动缩小一倍.不然使用原来大小.
* 大部分的使用场景是:作为预览横条用, 建议缩放, 这样可减少app内存
* @param width 缩放宽度
* @param height 缩放高度
*/
if (mInfo.vWidth * mInfo.vHeight > 960 * 540) {
mExtractFrame.setBitmapWH(mInfo.vWidth / 2, mInfo.vHeight / 2);
}
//
/**
* 设置提取间隔.
* 取bitmap的间隔, 即解码好后, 每隔几个返回一个bitmap, 用在需要列出视频一部分,但不需要全部的场合,比如预览缩略图.
*
* 如果设置时间,则从开始时间后, 查当前解码好几个图片,然后做间隔返回bitmap
*
* 比如设置间隔是3, 则bitmap在第 0个返回, 第4 8,12,16个返回.
*
* 可以用MediaInfo或FrameInfo得到当前视频中总共有多少帧,用FrameInfo可以得到每一帧的时间戳.
*
* @param frames
*/
// mExtractFrame.setExtractInterval(5);
/**
* 设置处理完成监听.
*/
mExtractFrame.setOnExtractCompletedListener(new onExtractVideoFrameCompletedListener() {
@Override
public void onCompleted(ExtractVideoFrame v) {
// TODO Auto-generated method stub
// 单位毫秒.
long timeOut = System.currentTimeMillis() - startTime;
float leftF = ((float) timeOut / 1000);
// 保留一位小数.
float b = (float) (Math.round(leftF * 10)) / 10;
String str = "解码结束:\n" + "解码的视频总帧数:" + frameCount + "\n" + "解码耗时:" + b + "(秒)" + "\n" + "\n" + "\n" + "视频宽高:" + mInfo.vWidth + " x " + mInfo.vHeight + "\n" + "解码后图片缩放宽高:" + mExtractFrame.getBitmapWidth() + " x " + mExtractFrame.getBitmapHeight() + "\n";
Log.i("TIME", "解码结束::" + str);
tvProgressHint.setText("Completed" + str);
isExecuting = false;
frameCount = 0;
}
});
/**
* 设置处理进度监听.
*/
mExtractFrame.setOnExtractProgressListener(new onExtractVideoFrameProgressListener() {
/**
* 当前帧的画面回调,, ptsUS:当前帧的时间戳,单位微秒.
* 拿到图片后,建议放到ArrayList中, 不要直接在这里处理.
*/
@Override
public void onExtractBitmap(Bitmap bmp, long ptsUS) {
// TODO Auto-generated method stub
frameCount++;
String hint = " 当前是第" + frameCount + "帧" + "\n" + "当前帧的时间戳是:" + String.valueOf(ptsUS) + "微秒";
tvProgressHint.setText(hint);
Log.i(TAG, "bitmap ptsUs is:" + ptsUS);
// savePng(bmp); //测试使用.
// if(bmp!=null && bmp.isRecycled()){
// bmp.recycle();
// bmp=null;
// }
// if(ptsUS>15*1000*1000){ // 你可以在指定的时间段停止.
// mExtractFrame.stop(); //这里演示在15秒的时候停止.
// }
}
});
frameCount = 0;
/**
* 开始执行. 或者你可以从指定地方开始解码.
* mExtractFrame.start(10*1000*1000);则从视频的10秒处开始提取.
*/
mExtractFrame.start();
/**
* 您可以一帧一帧的读取, seekPause是指:seek到指定帧后, 调用回调就暂停.
* 单位是us, 微秒.
* 单独读取的话, 把这里打开
* 如果您频繁的读取, 建议直接一次性读取完毕,放到sd卡里,然后用的时候, 从sd卡中读取.
*/
// mExtractFrame.seekPause(seekCount*1000*1000);
startTime = System.currentTimeMillis();
}
use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_advance by LanSoSdk.
the class BitmapLayerMarkActivity method initDrawPad.
/**
* Step1: 初始化 DrawPad 容器
*/
private void initDrawPad() {
MediaInfo info = new MediaInfo(mVideoPath);
if (info.prepare()) {
// mMarkView.setUseMainVideoPts(true);
markView.setRealEncodeEnable(480, 480, 1000000, (int) info.vFrameRate, editTmpPath);
markView.setDrawPadSize(480, 480, new onDrawPadSizeChangedListener() {
@Override
public void onSizeChanged(int viewWidth, int viewHeight) {
// TODO Auto-generated method stub
startDrawPad();
}
});
}
}
use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_advance by LanSoSdk.
the class ExecuteAllDrawpadActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.execute_edit_demo_layout);
mContext = getApplicationContext();
videoPath = getIntent().getStringExtra("videopath");
mInfo = new MediaInfo(videoPath, false);
initView();
// 在手机的默认路径下创建一个文件名,用来保存生成的视频文件,(在onDestroy中删除)
dstPath = SDKFileUtils.newMp4PathInBox();
new Thread(new Runnable() {
@Override
public void run() {
videoPath2 = CopyFileFromAssets.copyAssets(getApplicationContext(), "ping25s.mp4");
}
}).start();
if (// 为了很快演示, 这里只要前3秒.
mInfo.prepare() && mInfo.vDuration > 3.0f) {
VideoEditor editor = new VideoEditor();
video3S = SDKFileUtils.createFileInBox(mInfo.fileSuffix);
editor.executeVideoCutOut(videoPath, video3S, 0, 3.0f);
} else {
video3S = videoPath;
}
}
use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_advance by LanSoSdk.
the class MoreLayHeadSeekActivity method setupDrawPad.
/**
* Step1: 设置DrawPad 容器的尺寸.并设置是否实时录制容器上的内容.
*/
private void setupDrawPad() {
videoWidth = firstInfo.vWidth;
videoHeight = firstInfo.vHeight;
if (firstInfo.vRotateAngle == 90 || firstInfo.vRotateAngle == 270) {
videoWidth = firstInfo.vHeight;
videoHeight = firstInfo.vWidth;
}
joinCopySecondVideo();
secondInfo = new MediaInfo(videoPath2, false);
secondInfo.prepare();
bmpLayerStartTime = (long) (firstInfo.vDuration * 1000 * 1000);
// 设置最大值.
totalTimeUs = (long) (firstInfo.vDuration * 1000 * 1000) + BITMAP_DURATION + (long) (secondInfo.vDuration * 1000 * 1000);
skbTime.setMax((int) totalTimeUs);
drawPadView.setRealEncodeEnable(videoWidth, videoHeight, 1500000, (int) 25, dstPath);
// 25是帧率.
drawPadView.setUpdateMode(DrawPadUpdateMode.AUTO_FLUSH, 25);
drawPadView.setDrawPadSize(videoWidth, videoHeight, new onDrawPadSizeChangedListener() {
@Override
public void onSizeChanged(int viewWidth, int viewHeight) {
drawPadView.pauseDrawPad();
startDrawPad();
}
});
drawPadView.setOnDrawPadRunTimeListener(new onDrawPadRunTimeListener() {
@Override
public void onRunTime(DrawPad v, long curerntTimeUs) {
playVideo1(curerntTimeUs);
playVideo2(curerntTimeUs);
playPicture(curerntTimeUs);
}
});
drawPadView.setOnDrawPadProgressListener(new onDrawPadProgressListener() {
@Override
public void onProgress(DrawPad v, long currentTimeUs) {
}
});
}
use of com.lansosdk.videoeditor.MediaInfo in project LanSoEditor_advance by LanSoSdk.
the class OutBodyDemoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.outbody_demo_layout);
srcVideoPath = getIntent().getStringExtra("videopath");
mInfo = new MediaInfo(srcVideoPath, false);
if (mInfo.prepare() == false) {
Toast.makeText(this, "传递过来的视频文件错误", Toast.LENGTH_SHORT).show();
this.finish();
}
mDrawPadView = (DrawPadView) findViewById(R.id.id_outbody_drawpadview);
btnTest = (Button) findViewById(R.id.id_outbody_testbutton);
btnTest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mainVideoLayer != null) {
mainVideoLayer.setSubImageEnable(false);
}
}
});
playVideo = (LinearLayout) findViewById(R.id.id_outbody_saveplay);
playVideo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (SDKFileUtils.fileExist(dstPath)) {
Intent intent = new Intent(OutBodyDemoActivity.this, VideoPlayerActivity.class);
intent.putExtra("videopath", dstPath);
startActivity(intent);
} else {
Toast.makeText(OutBodyDemoActivity.this, "目标文件不存在", Toast.LENGTH_SHORT).show();
}
}
});
playVideo.setVisibility(View.GONE);
editTmpPath = SDKFileUtils.newMp4PathInBox();
dstPath = SDKFileUtils.newMp4PathInBox();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// showHintDialog();
startPlayVideo();
}
}, 300);
}
Aggregations