¿Es posible generar una miniatura de una url de vídeo en Android
Estoy trabajando en una aplicación de vídeo. Estoy transmitiendo un video desde el enlace del servidor, ¿es posible que genere una miniatura de video desde la URL sin descargar el video?
7 answers
Sin descargar video puede generar miniaturas desde el siguiente código:
public static Bitmap retriveVideoFrameFromVideo(String videoPath) throws Throwable
{
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try
{
mediaMetadataRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mediaMetadataRetriever.setDataSource(videoPath, new HashMap<String, String>());
else
mediaMetadataRetriever.setDataSource(videoPath);
// mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime();
} catch (Exception e) {
e.printStackTrace();
throw new Throwable("Exception in retriveVideoFrameFromVideo(String videoPath)" + e.getMessage());
} finally {
if (mediaMetadataRetriever != null) {
mediaMetadataRetriever.release();
}
}
return bitmap;
}
NOTA: El video se almacena como Intra y no Intra (Marcos de fotos) getFrameAtTime devolverá el marco no intra más cercano como mapa de bits. Así que básicamente no descargará el video completo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-28 08:10:47
No es posible crear miniaturas desde el enlace steaming, debe mostrarlas desde el servidor. Es mejor subir una miniatura a lo largo del video. Utilice el siguiente código para generar thumbnail
Bitmap ThumbnailUtils.createVideoThumbnail("picturePath", MediaStore.Video.Thumbnails.MINI_KIND);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-28 08:06:32
Aquí está su enlace:
- Android: ¿Es posible mostrar miniaturas de vídeo?
- http://developer.android.com/reference/android/media/ThumbnailUtils.html
En mi opinión, el lado del servidor debe crear miniaturas a partir de un video y transferir imágenes de video en miniatura a través de su servicio.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:03:02
Probé esto con glide y funcionó , versión Glide 4.3.1
GlideApp.with(context)
.asBitmap()
.load(FILE_URL)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.into(iv_picture);
Editar: Glide estaba trabajando lento para mí
La respuesta principal no estaba dando resultado para algunos videos, así es como lo hice
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
//give YourVideoUrl below
retriever.setDataSource("YourVideoUrl", new HashMap<String, String>());
// this gets frame at 2nd second
Bitmap image = retriever.getFrameAtTime(2000000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
//use this bitmap image
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-15 14:26:51
Intenta usar este
Bitmap bitmap=ThumbnailUtils.createVideoThumbnail("VIDEO FILE
ADDRESS",MediaStore.Video.Thumbnails.MINI_KIND);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-29 11:51:35
Este método le dará miniaturas de todos los archivos de vídeo en su teléfono... siéntase libre de hacer preguntas
public static Bitmap[] getThumbnail(Context context){
Uri uri=MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection=new String[] { MediaStore.Video.Thumbnails._ID };
Cursor ca = context.getContentResolver().query(uri, projection, null, null, null);
Bitmap[] b=new Bitmap[ca.getCount()];
int i=0;
ca.moveToFirst();
while(i<ca.getCount()) {
int id = ca.getInt(ca.getColumnIndex(MediaStore.Video.Thumbnails._ID));
b[i++]=MediaStore.Video.Thumbnails.getThumbnail(context.getContentResolver(),id, MediaStore.Images.Thumbnails.MINI_KIND, null );
ca.moveToNext();
}
ca.close();
return b;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-04 03:23:07
Obtenemos todo el video en el teléfono Android. http://sunilkmrnishad.blogspot.in/2017/03/read-files-apps-photos-media-from.html
public class ThumbnailExtract extends AsyncTask<String, long[], Bitmap> {
private final String videoUrl;
private final ImageView mThumbnail;
private final boolean mIsVideo;
private MediaMetadataRetriever mmr;
public ThumbnailExtract(String videoLocalUrl, ImageView thumbnail, boolean isVideo) {
this.videoUrl = videoLocalUrl;
mThumbnail = thumbnail;
mIsVideo = isVideo;
if (!isVideo) {
mmr = new MediaMetadataRetriever();
}
}
@Override
protected Bitmap doInBackground(String... params) {
if (!mIsVideo) {
return getBitmap(videoUrl);
} else {
return ThumbnailUtils.createVideoThumbnail(videoUrl,
MediaStore.Images.Thumbnails.MINI_KIND);
}
}
@Override
protected void onPostExecute(Bitmap thumb) {
if (thumb != null) {
mThumbnail.setImageBitmap(thumb);
}
}
private Bitmap getBitmap(String fileUrl) {
mmr.setDataSource(fileUrl);
byte[] data = mmr.getEmbeddedPicture();
Bitmap bitmap = null;
// convert the byte array to a bitmap
if (data != null) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
}
return bitmap != null ? ScalingUtilities.createScaledBitmap(bitmap, 40, 40, ScalingUtilities.ScalingLogic.FIT) : bitmap;
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-20 07:03:38