FFmpegMediaMetadataRetriever icon indicating copy to clipboard operation
FFmpegMediaMetadataRetriever copied to clipboard

Front Camera orientation problem.

Open Wolf00Bomber opened this issue 8 years ago • 4 comments

When operating the Lib on Video taken from Front Camera, the orientation is wrong. That is we are seeing a 90 degree rotation of the images. This was working fine in MediaMetadataRetriever class. Please help.

Wolf00Bomber avatar Oct 04 '16 12:10 Wolf00Bomber

Can you post a sample video I can test with?

wseemann avatar Dec 01 '16 06:12 wseemann

Here is video : https://drive.google.com/file/d/0B-T15ODuON57S2U0LTRZTGNJTk0/view?usp=drivesdk

I am getting landscape bitmaps. video is recorded from app as portrait and following is my code :

FFmpegMediaMetadataRetriever fpeg = new FFmpegMediaMetadataRetriever();
            fpeg.setDataSource(AppUtils.videoPath);  // its sdcard video path
 String duration = fpeg
                    .extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);

seesaw_bitmaps[0] = fpeg.getFrameAtTime(1, FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC);

hardikJoshi123 avatar Jul 28 '17 15:07 hardikJoshi123

@hardikJoshi123 Maybe this snippet of code will help get you in the right direction:

public void fixImageRotation(){
	imageview.buildDrawingCache();
	Bitmap original = imageview.getDrawingCache();
	//fileUri is the uri of the selected image
	imageview.setImageBitmap(imageOreintationValidator(original, fileUri.getPath()));
}

private Bitmap imageOreintationValidator(Bitmap bitmap, String path) {

	ExifInterface ei;
	try {
		ei = new ExifInterface(path);
		int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
				ExifInterface.ORIENTATION_NORMAL);
		switch (orientation) {
			case ExifInterface.ORIENTATION_ROTATE_90:
				bitmap = rotateImage(bitmap, 90);
				break;
			case ExifInterface.ORIENTATION_ROTATE_180:
				bitmap = rotateImage(bitmap, 180);
				break;
			case ExifInterface.ORIENTATION_ROTATE_270:
				bitmap = rotateImage(bitmap, 270);
				break;
		}
	} catch (IOException e) {
		e.printStackTrace();
	}

	return bitmap;
}

private Bitmap rotateImage(Bitmap source, float angle) {

	Bitmap bitmap = null;
	Matrix matrix = new Matrix();
	matrix.postRotate(angle);
	try {
		bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
				matrix, true);
	} catch (OutOfMemoryError err) {
		err.printStackTrace();
	}
	return bitmap;
}

power7714 avatar Aug 03 '17 20:08 power7714

Look at my issue #190, Using ExifInterface will not fix the issue on some Samsung devices, I can confirm this on my Samsung J7 Pro. I found a workaround.

HBiSoft avatar Sep 09 '18 12:09 HBiSoft