Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize_path - invalid input: "lib/", the input path should be absolute #1127

Closed
YLPeng opened this issue Jan 22, 2019 · 23 comments
Closed
Labels

Comments

@YLPeng
Copy link

YLPeng commented Jan 22, 2019

val fffr = FFmpegFrameRecorder(Environment.getExternalStorageDirectory().absolutePath + File.separator + "test.mp4",256,256)
        try {
            fffr.videoCodec = avcodec.AV_CODEC_ID_MPEG4
            fffr.format = "mp4"
            fffr.frameRate = 30.0
            fffr.pixelFormat = avutil.AV_PIX_FMT_YUV420P
            fffr.videoBitrate = 1200
            fffr.start()

            for (i in 0..4) {
                activity_record_layout.isDrawingCacheEnabled = true
                val b = Bitmap.createBitmap(activity_record_layout.drawingCache)
                //val frame =viewToFrame(activity_record_layout)
                val frame = AndroidFrameConverter().convert(b)
                recorder.record(frame)
            }

            fffr.stop()
        }
        catch (e: Exception){
            e.printStackTrace()
        }

I have above simple function to record view using FFmpegRecorder. However I have following issue when I'm running the code:

E/linker: normalize_path - invalid input: "lib/", the input path should be absolute
W/linker: Warning: unable to normalize "lib/"
W/System.err: org.bytedeco.javacv.FrameRecorder$Exception: avio_open2 error() error -13: Could not open 'null'

I have searched issues with error -13 but didn't find any useful information. Please help thanks!

here's my grade dependencies for java cv:

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation group: 'org.bytedeco', name: 'javacv', version: '1.4.4'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-arm'
    implementation 'org.bytedeco.javacpp-presets:opencv:4.0.1-1.4.4:android-x86'
    implementation 'org.bytedeco.javacpp-presets:ffmpeg:4.1-1.4.4:android-arm'
    implementation 'org.bytedeco.javacpp-presets:ffmpeg:4.1-1.4.4:android-x86'
@saudet
Copy link
Member

saudet commented Jan 22, 2019

Since this isn't a problem, let's mark this as "enhancement". Please consider making a contribution :)

@saudet
Copy link
Member

saudet commented Jan 22, 2019

If you're wondering why Environment.getExternalStorageDirectory() returns null, that's not an issue with JavaCV, it's probably a problem with the permissions of your application.

@YLPeng
Copy link
Author

YLPeng commented Jan 23, 2019

Thank you @saudet. You are right, the issue was caused by the permissions issue. If anyone has the same issue, please double check you have the code to request correct permissions. I believe starting from Android 6.0 (API level 23), you need to have both manifest and request code in order to get permission granted.

https://developer.android.com/training/permissions/requesting

@Maja755
Copy link

Maja755 commented Sep 25, 2019

Which Android permissions exactly do I need to set for this error "normalize_path - invalid input: "lib/", the input path should be absolute" not to be present?

@saudet
Copy link
Member

saudet commented Sep 25, 2019

@Maja755 That's probably just a warning that we can ignore.

@saudet
Copy link
Member

saudet commented Oct 3, 2019

The only thing that I can see that could do that is the rpath given in these properties:
https://github.com/bytedeco/javacpp/tree/master/src/main/resources/org/bytedeco/javacpp/properties
I believe it used to be required a long long time ago, but I think we can remove it now...
@Maja755 Please give it a try! Thanks

@Maja755
Copy link

Maja755 commented Oct 3, 2019

@saudet Thank you for your previous answer about ignoring the warning. Though I don't understand your last reply...
But in this context, when ignoring the above mentioned warning, I get the following errors, which I am not sure have anything to do with the warning:

2019-10-03 18:24:14.658 1400-1668/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-10-03 18:24:14.997 1400-1434/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
2019-10-03 18:24:15.609 1603-1620/? E/BluetoothAdapter: Bluetooth binder is null
2019-10-03 18:24:15.623 1603-1620/? E/KernelUidCpuFreqTimeReader: Failed to read /proc/uid_time_in_state: java.io.FileNotFoundException: /proc/uid_time_in_state (No such file or directory)
2019-10-03 18:24:15.623 1603-1620/? E/KernelCpuSpeedReader: Failed to read cpu-freq: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state (No such file or directory)
2019-10-03 18:24:15.702 1603-1620/? E/BatteryExternalStatsWorker: modem info is invalid: ModemActivityInfo{ mTimestamp=0 mSleepTimeMs=0 mIdleTimeMs=0 mTxTimeMs[]=[0, 0, 0, 0, 0] mRxTimeMs=0 mEnergyUsed=0}

What would you say about these errors?

@saudet
Copy link
Member

saudet commented Oct 4, 2019

@Maja755 Those don't look related, no.

@qq12cvhj
Copy link

qq12cvhj commented Apr 24, 2020

So what is the exactly permission?My device is on Android O or later.I just write this:
String str = Loader.load(ffmpeg.class);
Now the str is null.
and then I got this :
E/linker: normalize_path - invalid input: "lib/", the input path should be absolute W/linker: Warning: unable to normalize "lib/" (ignoring)
I've already require the WRITE & READ EXTERNAL STORAGE permissions.But this problem occurs.

@saudet
Copy link
Member

saudet commented Apr 24, 2020

@qq12cvhj That's just a warning, not an error. The error is some other message in the log.

@nlgtuankiet
Copy link

I tried 'org.bytedeco:ffmpeg-platform:4.2.2-1.5.3' few day ago
For some reason Loader.load(ffmpeg.class); return null (same with @qq12cvhj )
avcodec other binding in org.bytedeco.ffmpeg.global.** still work
and the apk looking good though
image

I'm using this library on Android
Could you please check @saudet
Thanks!

@saudet
Copy link
Member

saudet commented Jun 12, 2020

@nlgtuankiet That's been fixed in 1.5.4-SNAPSHOT, see issue #1410.
Please give it a try with the snapshots: http://bytedeco.org/builds/

@nlgtuankiet
Copy link

thank @saudet
I tried 1.5.4-SNAPSHOT
Good new is Loader.load(ffmpeg::class.java) working well, but I got permission denied when trying to execute the command ffmpeg (both alone with no params and with params) using the ProcessBuilder (from the doc)
Any idea?

2020-06-13 15:56:08.748 1568-3248/com.nlgtuankiet.ffmpeg1 E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
    Process: com.nlgtuankiet.ffmpeg1, PID: 1568
    java.lang.Error: java.io.IOException: Cannot run program "/data/data/com.nlgtuankiet.ffmpeg1/cache/.javacpp-root/cache/base.apk/lib/arm64-v8a/ffmpeg": error=13, Permission denied
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1173)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:929)
     Caused by: java.io.IOException: Cannot run program "/data/data/com.nlgtuankiet.ffmpeg1/cache/.javacpp-root/cache/base.apk/lib/arm64-v8a/ffmpeg": error=13, Permission denied
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1050)
        at com.nlgtuankiet.ffmpeg1.MainActivity.exeCommand(MainActivity.kt:65)
        at com.nlgtuankiet.ffmpeg1.MainActivity.access$exeCommand(MainActivity.kt:24)
        at com.nlgtuankiet.ffmpeg1.MainActivity$execute$1.run(MainActivity.kt:48)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:929) 
     Caused by: java.io.IOException: error=13, Permission denied
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
        at java.lang.ProcessImpl.start(ProcessImpl.java:141)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        at com.nlgtuankiet.ffmpeg1.MainActivity.exeCommand(MainActivity.kt:65) 
        at com.nlgtuankiet.ffmpeg1.MainActivity.access$exeCommand(MainActivity.kt:24) 
        at com.nlgtuankiet.ffmpeg1.MainActivity$execute$1.run(MainActivity.kt:48) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:929) 

@saudet
Copy link
Member

saudet commented Jun 13, 2020 via email

@nlgtuankiet
Copy link

@saudet thank man, it work!

For those who are using this library on android, try this:

val ffmpeg = Loader.load(ffmpeg::class.java)
require(File(ffmpeg).setExecutable(true))
repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
implementation 'org.bytedeco:ffmpeg-platform:4.2.3-1.5.4-SNAPSHOT'

@saudet
Copy link
Member

saudet commented Jun 14, 2020

File.setExecutable(true) already gets called before returning it, so something else is causing problems here: https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/Loader.java#L1262

BTW, it appears that Android API 29+ doesn't support executing files like that anymore, so we might have to use API 28 or lower until they figure out another way to let us do that again.

@nlgtuankiet
Copy link

nlgtuankiet commented Jun 14, 2020

yup, my compileSdkVersion is 29 but I set targetSdkVersion to 28. As @saudet mention targetSdkVersion 29 will not work and you will get an exception:

     Caused by: java.io.IOException: error=13, Permission denied
        at java.lang.UNIXProcess.forkAndExec(Native Method)
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
        at java.lang.ProcessImpl.start(ProcessImpl.java:141)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
        at org.zeroturnaround.exec.ProcessExecutor.invokeStart(ProcessExecutor.java:997) 
        at org.zeroturnaround.exec.ProcessExecutor.startInternal(ProcessExecutor.java:970) 
        at org.zeroturnaround.exec.ProcessExecutor.execute(ProcessExecutor.java:906) 

I have since an open that put ffmpeg executable file in the assets folder, at run time they copy it into the app folder ann execute the file from there. I haven't tried it yet but targetSdkVersion 28 seems just fine for me now

Edit: nope you still got permission denied

@saudet
Copy link
Member

saudet commented Sep 10, 2020

@nlgtuankiet Try an even older version of the SDK. It works fine for me when targeting Android 7.0, see issue #1410.

@kshitijgarg2609
Copy link

@saudet

I am trying bytedeco opencv 1.5.6 along with it's dependencies ffmpeg openblas javacpp etc. I have given the permissions as you have said, I have extracted the jar files which contains .so file and stored in jniLibs folder, I was able to call the Loader function and able to instantiate VideoCapture but I really can't open the camera. I am sharing the screenshot of the error and the androidmanifest too, My code is just a test code and I am unable to open the camera I am getting the message in the run terminal which is mentioned in this topic, Please do tell me about the permissions missing and where my code is wrong.

image
manifest
image

Main code

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

//import org.bytedeco.opencv.opencv_videoio.VideoCapture;
import org.opencv.videoio.VideoCapture;

import org.opencv.videoio.Videoio;

import java.io.File;

import static android.content.ContentValues.TAG;

public class MainActivity extends AppCompatActivity
{
public Thread loop = new Thread()
{
public void run()
{
try
{
File test_root[] = File.listRoots();
Log.v(TAG,"check\n"+System.getProperty("user.dir")+"\n");
for(File f : test_root)
{
Log.v(TAG,"check : "+f.getAbsolutePath()+"\n");
for(File f1 : f.listFiles())
{
Log.v(TAG,"check : "+f1.getAbsolutePath()+"\n");
}
}
}
catch(Exception e)
{
Log.v(TAG,"exception file\n");
}
org.bytedeco.javacpp.Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);
org.bytedeco.javacpp.Loader.load(org.bytedeco.opencv.opencv_java.class);
try {
VideoCapture
vcb = new VideoCapture();
if(vcb.open(0))
{
Log.v(TAG,"opened success");
}
else
{
Log.v(TAG,"opened not success");
}
}
catch(Exception e)
{
Log.v(TAG,"EXCEPTION ###");
}
}
}
;
ImageView imgView;
private static final String[] REQUIRED_PERMISSIONS = new String[] { Manifest.permission.CAMERA,
Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.MANAGE_EXTERNAL_STORAGE};
private static final int REQUEST_CODE_PERMISSIONS = 100;
@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button)findViewById(R.id.button);
b.setOnClickListener(
new View.OnClickListener() {
@OverRide
public void onClick(View v) {
loop.start();
}
}
);
imgView=(ImageView)findViewById(R.id.imageView);
if (!allPermissionsGranted()) {
ActivityCompat.requestPermissions(
this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS);
}
}
private boolean allPermissionsGranted() {
for(String permission: REQUIRED_PERMISSIONS) {
Boolean granted = ContextCompat.checkSelfPermission(
getBaseContext(), permission) == PackageManager.PERMISSION_GRANTED;
if (!granted) {
return false;
}
}
return true;
}
}

@saudet
Copy link
Member

saudet commented Nov 23, 2021

Permissions are something that users need to grant to your applications, it's not something that we can set from the application. You'll need to figure out how your device allows users to grant permissions to applications.

@saudet
Copy link
Member

saudet commented Nov 23, 2021

Also, I don't believe VideoCapture from OpenCV supports Android. Please use the Android API.

@kshitijgarg2609
Copy link

Thank you @saudet for your suggestion. If not OpenCV VideoCapture then I have tried different types of FrameGrabber too, will it work? Android Camera 2 API is too much comples to fetch camera data, I would like to have some more suggestions aabout opening the camera if there is some other classes available.

@saudet
Copy link
Member

saudet commented Nov 25, 2021

It looks like FFmpeg supports the Android Camera API now, so you may want to give that a try:
https://www.ffmpeg.org/ffmpeg-devices.html#android_005fcamera
Let's continue this discussion at issue #1692.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants