Permission denied for openFileDescriptor to pass a file from SDCARD to FFmpeg

Permission denied for openFileDescriptor to pass a file from SDCARD to FFmpeg

I am trying to work with a file from Sdcard which is to be passed to FFmpeg fro this I am using

 Uri contentUri = ContentUris.withAppendedId(
            MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            cursor.getLong(Integer.parseInt(BaseColumns._ID)));
    String fileOpenMode = "r";
    ParcelFileDescriptor parcelFd =
            resolver.openFileDescriptor(contentUri, fileOpenMode);
    if (parcelFd != null) {
        int fd = parcelFd.detachFd();
        // Pass the integer value "fd" into your native code. Remember to call
        // close(2) on the file descriptor when you're done using it.
    }

int pid = android.os.Process.myPid();
            String mediaFile = "/proc/" + pid + "/fd/" + fd;

            Toast.makeText(videoexample.this, "mediafile" + mediaFile, Toast.LENGTH_SHORT).show();

            //File directoryToStore = videoexample.this.getExternalFilesDir("tempDirectory");
            File directoryToStore = videoexample.this.getExternalFilesDir("tempDirectory");
            if(directoryToStore != null) {
                if (!directoryToStore.exists()) {
                    if (directoryToStore.mkdir()) ; //directory is created;
                }
            }


            // Output path passed to FFmpeg
            String outputPath = directoryToStore+"/testFile.mp4";

            int rc = FFmpeg.execute("-y -i "+mediaFile+" -filter:v scale=1280:720 -c:a copy "+outputPath);

If this file is present in the SDCard , It gives me an error

E/mobile-ffmpeg: /proc/20124/fd/169: Permission denied in the logcat

however if the file is from Internal (phone's ) storage it works fine

all the permissions are given , I am trying it on a Moto C android 7.0

any help would be useeful