I have a mp4 file(already recorded) and want to change the rotation(including meta data) of the video. There is a way to do this using Hex Editor where in you find the track header(tkhdr) and replace the rotation matrix with the required rotation.
I know this can be done using ffmpeg library but I do not want to use the library instead I want to do this in Android using JAVA. Let me know if anyone has done this before.
Thanks
Ravi
Reference link
This library may help you: https://github.com/MasayukiSuda/Mp4Composer-android
This library generates an Mp4 movie using Android MediaCodec API and can rotate Mp4.
StackOverflow reference: https://stackoverflow.com/a/19392712/8572503
It's API is fluent and easy :
new Mp4Composer(sourceFile, destinationFile)
.rotation(Rotation.ROTATION_90)
.size(1280,720) //720P
.fillMode(FillMode.PRESERVE_ASPECT_FIT)
.listener(new Mp4Composer.Listener() {
#Override
public void onProgress(double progress) {
Log.d(TAG, "onProgress = " + progress);
//or show in notification
}
#Override
public void onCompleted() {
Log.v(TAG, "onCompleted() : Destination → "+ destinationFile);
}
#Override
public void onCanceled() {
Log.d(TAG, "onCanceled");
}
#Override
public void onFailed(Exception exception) {
Log.wtf(TAG, "onFailed()", exception);
}
})
.start();
You can also see this transcoder has written in pure Java: https://github.com/ypresto/android-transcoder
[EDIT: From Comment]:
You can extract code from this: https://github.com/javadev/hexeditor to manually modify the hex.
Related
How to attach PDF file to post API with two parameter? I am using Fast android networking library.
I am able to call API but I when user touched button my API called in my API have three parameters like this:
message = "Test"
receiver_Email = "#gmail.com"
File = text.PDF;
Sy API allows only PDF form met with message and email. I am using Fast android networking library. I try to call API but I am not able to do it.
I also looked at some examples but it couldn't help me out.
just call this method from your onCreate this is the easy way to call API with file and parameter I hope it helps you
//method used to call API to send email
enter code here
#RequiresApi(API = Build.VERSION_CODES.LOLLIPOP_MR1)
public void call_Api()
{
final String key = "file";
final File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "/test.pdf");
AndroidNetworking.initialize(this);
AndroidNetworking.upload("your API")
.setPriority(Priority.HIGH)
.addMultipartParameter("message", "test")
.addMultipartParameter("receiverEmail","testrg0017#gmail.com")
.addMultipartFile(key, file)
.setPriority(Priority.HIGH)
.build()
.getAsJSONObject(new JSONObjectRequestListener()
{
#Override
public void onResponse(JSONObject response)
{
Log.d("res ",response.toString());
if(file.exists())
{
Toast.makeText(PdfGeneration.this, "API call successfully",
Toast.LENGTH_SHORT).show();
}
}
#Override
public void onError(ANError anError)
{
anError.printStackTrace();
Log.d("res12 ",anError.toString());
if(!file.exists())
{
Toast.makeText(PdfGeneration.this, "file not available",
Toast.LENGTH_SHORT).show();
}
}
});
}
I am trying to setup an ImageAnalyzer with my Android app so I can run object classification using Google's ML Kit API. The issue I am currently facing, as the title suggests, is constantly seeing the error "Failed to initialize detector".
I've reread this tutorial about three times now and followed this post about someone facing the same error (although for a different reason) to no avail. I've also made sure everything with the CameraX API (except the ImageAnalyzer code that I will show in a second) works as expected.
As mentioned in the ML Kit documentation, here is the code I have regarding setting up a LocalModel, a CustomObjectDetectorOptions, and an ObjectDetector:
LocalModel localModel = new LocalModel.Builder()
.setAssetFilePath("mobilenet_v1_1.0_224_quantized_1_metadata_1.tflite")
.build();
CustomObjectDetectorOptions customObjectDetectorOptions =
new CustomObjectDetectorOptions.Builder(localModel)
.setDetectorMode(CustomObjectDetectorOptions.STREAM_MODE)
.enableClassification()
.setClassificationConfidenceThreshold(0.5f)
.setMaxPerObjectLabelCount(3)
.build();
ObjectDetector objectDetector = ObjectDetection.getClient(customObjectDetectorOptions);
Here is the ImageAnalyzer code I have, which basically makes a call to the ML Kit API by way of the processImage helper method:
// Creates an ImageAnalysis for analyzing the camera preview feed
ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
.setTargetResolution(new Size(224, 224))
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build();
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(this),
new ImageAnalysis.Analyzer() {
#Override
public void analyze(#NonNull ImageProxy imageProxy) {
#SuppressLint("UnsafeExperimentalUsageError") Image mediaImage =
imageProxy.getImage();
if (mediaImage != null) {
Log.i(TAG, "Obtained ImageProxy object");
processImage(mediaImage, imageProxy)
.addOnCompleteListener(new OnCompleteListener<List<DetectedObject>>() {
#Override
public void onComplete(#NonNull Task<List<DetectedObject>> task) {
imageProxy.close();
}
});
}
}
});
Here is the processImage helper method, where I actually call objectDetector.process(...), the line of code that actually runs the tflite model.
private Task<List<DetectedObject>> processImage(Image mediaImage, ImageProxy imageProxy) {
InputImage image =
InputImage.fromMediaImage(mediaImage,
imageProxy.getImageInfo().getRotationDegrees());
return objectDetector.process(image)
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
String error = "Failed to process. Error: " + e.getMessage();
Log.i(TAG, error);
}
})
.addOnSuccessListener(new OnSuccessListener<List<DetectedObject>>() {
#Override
public void onSuccess(List<DetectedObject> results) {
String success = "Object(s) detected successfully!";
Log.i(TAG, success);
for (DetectedObject detectedObject : results) {
Rect boundingBox = detectedObject.getBoundingBox();
Integer trackingId = detectedObject.getTrackingId();
for (DetectedObject.Label label : detectedObject.getLabels()) {
String text = label.getText();
int index = label.getIndex();
float confidence = label.getConfidence();
Log.i(TAG, "Object detected: " + text + "; "
+ "Confidence: " + confidence);
}
}
}
});
}
Essentially, once I run the app, logcat just keeps logging these two lines on repeat. I know it means the ImageAnalyzer is continuously trying to analyze the image input, but for some reason the LocalModel just cannot process the input
2021-01-21 22:02:24.020 9328-9328/com.example.camerax I/MainActivity: Obtained ImageProxy object
2021-01-21 22:02:24.036 9328-9328/com.example.camerax I/MainActivity: Failed to process. Error: Failed to initialize detector.
I have only just started to work with Android, especially ML in Android, so any sort of help would be appreciated!
I managed to fix my issue before anyone answered, but in case anyone who just started to learn Android like me I'll leave my solution here.
Basically, remember to create an asset folder in the /src/main directory rather than the /src/androidTest directory :P
Once I did that, the model loaded correctly and now I just have to figure out how to display the results in my application.
// Do NOT compress tflite model files (need to call out to developers!)
aaptOptions {
noCompress "tflite"
}
add this line in build gradle for app under android tag
I have a method that creates targets for Picasso like this:
private void createTargets() {
Target target;
for (Id id : itemids) {
target = picassoImageTarget(getContext(), "imageDir", id.getId() + ".png");
imgTargets.add(new ImgTarget(id.getId(), target));
}
}
and then I download images to disk this way:
private void download() {
for (ImgTarget imgTarget : imgTargets) {
Picasso.with(getContext()).load("https://www.sestavsisvujsvet.cz/files/magnetky/" + imgTarget.getId() + ".png").into(imgTarget.getTarget());
}
}
it does what I want it to do, however I am unable to get a callback, because the constructor with callback exists only when using ImageView:
Can someone help me find a solution to this? I don't understand callbacks and things like that too much, so it's hard for me to figure it out.
I just need to know when the whole downloading process has finished so I can notify the user.
Thanks :)
A picasso Target is essentially a callback, if you look at the Target object, it has the following structure:
Target target = new Target() {
#Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// Notify the user
}
#Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
// Notify the user
}
#Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
In your function picassoImageTarget(...) you would be building that target, and inside the onBitmapLoaded and onBitmapFailed you can put your code in to notify the user depending on your implementation.
Also, I noticed you are using Picasso.with(context), this has been updated to Picasso.get() in the latest library, might be worthwhile updating your picasso library to the latest too.
Hi I tried to open some files from Google Drive in andoid app using Google Drive Api with:
ResourceClient.openFile(selectedFile.asDriveFile() , DriveFile.MODE_READ_WRITE)
My code worked just fine for Word format (docx), but for all ohters format i tried it threw
com.google.android.gms.common.api.ApiException: 10: This file is not openable.
exception. This exception is nowhere to be found and i really couldn't get rid of it. If anybody can help I would be really grateful.
EDIT: Btw. I claimed metadata for all files successfully.
EDIT 2: Even while using Google samples i could open just Word documents.
Code that I used just in case you would need it:
Signing in to google:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Drive.SCOPE_FILE)
.build();
signInClient = GoogleSignIn.getClient(getApplicationContext(), gso);
startActivityForResult(signInClient.getSignInIntent(), SING_IN_REQEST_CODE);
Geting metadata and files:
contentsTask = resourceClient.getMetadata(selectedFile.asDriveResource())
.continueWithTask(new Continuation<Metadata, Task<DriveContents>>(){
#Override
public Task<DriveContents> then(#NonNull Task<Metadata> task) throws Exception {
if(task.isComplete() && task.isSuccessful()) {
Log.d(TAG, "Metadata claimed sucessfully");
if(task.getResult().isEditable())
Log.d(TAG, "File is edittable");
return resourceClient.openFile(selectedFile.asDriveFile() , DriveFile.MODE_READ_WRITE);
}
else {
Log.i(TAG, "Metadata wasn't claimed sucessfully" + task.isComplete());
return null;
}
}
} ).addOnSuccessListener(new OnSuccessListener<DriveContents>() {
#Override
public void onSuccess(DriveContents driveContents) {
Log.i(TAG, "successfully get driveContents");
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.i(TAG, "didn't successfully get driveContents", e);
}
});
EDIT: Issue has been replicated by: https://github.com/googledrive/android-demos/issues/70
So, I left and come back this topic 2 times, but for others: Despide the fact that i didn't find ANY DOCUMENTATION that would say that, Android Drive API (and my friend told me exactly same expirience with Java API) can only download files:
PDF
Pictures
and can not download:
office formats
If anybody would have anything to add (like I overlooked huge documentaion on topic wich formats can you acces with Drive APIs please let me know.-
For my semester project I am trying to identify speaker on Android. For this purpose, I have been trying to integrate vText java library to Android Studio. You can find the page through this link. However, I got the .jar files which are mentioned in the web page and tried to do sample things for discovering the library and I got java.lang.VerifyError. Of course I searched for it but did not get anything handy.I tried to change JDK version but I could not make it,too. If anyone can help me for using this library in Android Studio properly.
Here is my code part relevant to this problem.
btnVoice.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CountDownTimer countDownTimer=new CountDownTimer(5000,1000) {
#Override
public void onTick(long millisUntilFinished) {
btnVoice.setText(millisUntilFinished/1000 + " seconds.");
}
#Override
public void onFinish() {
stopRecording();
try {
vTText=new vTextClass();
vTText.dataAcq(1, filename);
System.out.println("Recording completed");
} catch (MWException e) {
e.printStackTrace();
}
}
}.start();
This library uses matlab component runtime, which is not available on android. See How to run Matlab code on an Android device?
You can use other framework instead like Recognito