Convert javacv framework to bitmap using Android frameconverter
•
Android
I'm trying to convert the size to 1280 using javacv androidframeconverter × 720 frames are converted to bitmaps, and the conversion takes a long time. This is the example code of conversion
FrameGrabber grabber = new FFmpegFrameGrabber(videoUrl);
frame = grabber.grab();
AndroidFrameConverter converter = new AndroidFrameConverter();
Bitmap originalBitmap = converter.convert(frame);
Is there any other faster solution than this?
resolvent:
You can use this code and change the filter as needed
public class FilterAsync extends AsyncTask {
private FFmpegFrameGrabber VIDEO_GRABBER;
private FFmpegFrameRecorder videoRecorder;
private File file = new File(Environment.getExternalStorageDirectory() + "/Download/Abc.mp4");
private Context mContext;
private FFmpegFrameFilter filter;
private boolean isTrue = false;
private ArrayList<String> videoPaths;
private File myDirectory;
public FilterAsync(Context context) {
mContext = context;
VIDEO_GRABBER = new FFmpegFrameGrabber(file);
myDirectory = new File(Environment.getExternalStorageDirectory() + "/Folder/");
if (!myDirectory.exists()) {
myDirectory.mkdirs();
}
videoPaths = new ArrayList<>();
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Object doInBackground(Object[] params) {
Frame tempVideoFrame;
try {
VIDEO_GRABBER.start();
initVideoRecorder(myDirectory + "/video" + System.currentTimeMillis() + ".mp4");
filter.start();
while (VIDEO_GRABBER.grab() != null) {
tempVideoFrame = VIDEO_GRABBER.grabImage();
if (tempVideoFrame != null) {
filter.push(tempVideoFrame);
tempVideoFrame = filter.pull();
videoRecorder.record(tempVideoFrame);
}
}
videoRecorder.stop();
filter.stop();
videoRecorder.release();
VIDEO_GRABBER.stop();
VIDEO_GRABBER.release();
} catch (FrameGrabber.Exception e) {
e.printStackTrace();
} catch (FrameRecorder.Exception e) {
e.printStackTrace();
} catch (FrameFilter.Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
}
private void initVideoRecorder(String path) {
try {
filter = new FFmpegFrameFilter("transpose=clock ,crop=w=640:h=480:x=0:y=0", VIDEO_GRABBER.getImageWidth(), VIDEO_GRABBER.getImageHeight());
videoRecorder = FFmpegFrameRecorder.createDefault(path, VIDEO_GRABBER.getImageWidth(), VIDEO_GRABBER.getImageHeight());
videoRecorder.setAudioChannels(VIDEO_GRABBER.getAudioChannels());
videoRecorder.start();
} catch (FrameRecorder.Exception e) {
e.printStackTrace();
}
}
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码