Video thumbnail image for android - Titanium - android

I have a video and I need a thumbnail image for that video for android.This is what I created for iOS.
player.requestThumbnailImagesAtTimes([1],Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(response) {
if(response.success) {
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, videoName + ".png");
f.write(response.image);
So? What about android? How can it be done? This is what I done video capture for android. How can I create a thumbnail image for this?
var intent = Titanium.Android.createIntent({
action : 'android.media.action.VIDEO_CAPTURE' //android.provider.MediaStore.ACTION_VIDEO_CAPTURE
});
intent.putExtra("android.intent.extra.durationLimit", 15);

You can get the thumbnail bitmap of video file by using code given below :
Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);

Related

How to record a live streaming video, capture a photo from SurfaceView and save it phone Internal storage

I have an app that displays live video streaming from a camera device on the Surface view. As I am not an expert on Android, it took me weeks to display live streaming content on the Surface view. The format is raw H.264. I used Mediacodec to decode. What I need is to record that live streaming video and capture a screenshot of the same on a button click.
Code for taking a screenshot:
private void takeScreenshot() {
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or DOM
e.printStackTrace();
}
}
private void openScreenshot(File imageFile) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(imageFile);
intent.setDataAndType(uri, "image/*");
startActivity(intent);
}
Using the above code I am able to take a screenshot but the image color is black and also contains other buttons that I am using. All the other buttons are placed on top of the Surface view.
Is it possible to record and capture only the contents(excluding the buttons on top of the Surface view) that are displayed on the Surface view?
I am just thinking, please correct me if I am wrong. Instead of displaying it on SurfaceView, Is there any way to record and capture the decoded frames directly? Please find the below code:
This is how I display streaming content on SurfaceView;
LinearLayout surface2 = (LinearLayout)findViewById(R.id.surface);
SurfaceView sv = new SurfaceView(this);
sv.getHolder().addCallback(this);
surface2.addView(sv);

How to get frame of stream video link with Glide

in my android TV application, at start i want to show a frame of my each stream links. my current solution is using LoaderManager and the problem of this technique is to it's too slow(application crashed).
FFmpegMediaMetadataRetriever to load and set video stream link.
this.retriever = new FFmpegMediaMetadataRetriever();
Bitmap bitmap = null;
retriever.setDataSource(this.mSelectedStream.getStreamUrl());
bitmap = retriever.getFrameAtTime();
drawable = new BitmapDrawable(bitmap);
retriever.release();
i found this thread that explain that glide can used to load image from video links.
BitmapPool bitmapPool = Glide.get(getApplicationContext()).getBitmapPool();
int microSecond = 6000000;// 6th second as an example
VideoBitmapDecoder videoBitmapDecoder = new VideoBitmapDecoder(microSecond);
FileDescriptorBitmapDecoder fileDescriptorBitmapDecoder = new FileDescriptorBitmapDecoder(videoBitmapDecoder, bitmapPool, DecodeFormat.PREFER_ARGB_8888);
Glide.with(getApplicationContext())
.load(yourUri)
.asBitmap()
.override(50,50)// Example
.videoDecoder(fileDescriptorBitmapDecoder)
.into(yourImageView);
but when i used above code i get "cannot access from outside of package" error for VideoBitmapDecoder.
exmaple link = "http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"
any idea?
thanks
I've used this snippet to get thumb nail out of video frames. Try it
Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(media_url,
MediaStore.Images.Thumbnails.MINI_KIND);
BitmapDrawable BD = new BitmapDrawable(thumbnail);
videoView.setBackgroundDrawable(BD);

Displaying image from gallery in Oncreate method without opening gallery intent

I know how to open gallery intent and to display in the imageview.
But I am facing problem in selecting image automatically in oncreate method and display in the imageview.
I have an image in gallery folder with name "myfile.jpg"
Can anyone guide me how to do it without openting gallery intent.
Thank you in advance
Here is solution :
ImageView image = (ImageView)findViewById(R.id.myImage);
File root = Environment.getExternalStorageDirectory();
String path = root.getAbsolutePath();
path = path + File.separator + "myfile.jpg"; //where you image file located
Bitmap myBitmap = BitmapFactory.decodeFile(path);
image.setImageBitmap(myBitmap);

How to send video thumbnail to online server

Hi am working on a video app in android i want to generate video thumbnail and send to the server or simple how can i get video thumbnail and store in server so that when i retrieve the video i can also get the video thumbnail to use in a recycle view thanks
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(filePath,
MediaStore.Images.Thumbnails.MINI_KIND);
BitmapDrawable bitmapDrawable = new BitmapDrawable(thumb);
vidPreview.setBackgroundDrawable(bitmapDrawable);
I assume you are sending the video to the server also? If so then it may be better to generate the thumbnail on the server as you usually have more processing power there and less worry about consuming battery. It also saves you having to send the generated thumbnail to the server.
If you do want to create the thumbnail on the Android device then the following code will work (before this chunk the app has loaded all the videos in Media Store using the loader pattern and they are accessible via the 'cursor' variable below) - see the 'getThumbnail' method call:
while (videoCursor.moveToNext()) {
//Create the Thumbnail for this video
Log.d("ItemListFragment", "onLoadFinished: Creating Thumbnail");
String videoTitle = videoCursor.getString(titleColumn_index);
String videoPath = videoCursor.getString(pathColumn_index);
long videoID = videoCursor.getLong(idColumn_index);
Bitmap thisVideoThumbnail = MediaStore.Video.Thumbnails.getThumbnail(this.getActivity().getContentResolver(), videoID, MediaStore.Images.Thumbnails.MINI_KIND, null);
if (thisVideoThumbnail == null) {
Log.d("VideoContent refresh ","VideoThumbnail is null!!!");
}
VideoItem newVideoItem = new VideoItem(videoID, videoTitle, videoPath, thisVideoThumbnail);
//Add the new video item to the list
videosArray.addItem(newVideoItem);
}

GPUImage library for Android - Load and save pic with full size

I connected GPUImage library for android, everything works pretty nice, but when i try to load image it crops and size is very small, how can i load and save pic in full size?
This is my code for save photo wit full resolution using GPUImage :
private void startSavePhoto(String originalPhotoFilePath) {
final String TEMP_FOLDER = AppConst.PATH_FILE_SAVE_PHOTO + AppConst.PATH_FILE_SAVE_TEMP;
ExtraUtils.createFolder(TEMP_FOLDER);
final String TEMP_FILE_NAME = ".ImageEffect.png";
// Save Photo based on original file
Bitmap source = BitmapFactory.decodeFile(originalPhotoFilePath);
String pathFile = TEMP_FOLDER + File.separator + TEMP_FILE_NAME;
Bitmap bitmap = gpuImage.getGPUImage().getBitmapWithFilterApplied(source);
// Bitmap to File
if (ExtraUtils.saveBitmapToPNG(bitmap, pathFile)) {
showSaveWithAdsDialog(pathFile);
} else {
T.show(R.string.error_save_image);
}
}

Categories

Resources