I have a 1997 Ford F-150 v8 with a 4.6L engine 4x4?

I was driving and was stoping at a red light then was still moving and went to press on the gas and nothing truck was still running but would not drive so pulled over and no gears worked then about 30 minutes later I put it in 4 wheel drive and in to drive started to work so I Took it out of four-wheel-drive and tryed to drive it and it would go but Real bad whining sound coming from the transmission it sounded like so was trying to get it home it and put it in neutral going down a hill to try and take some pressure off the transmission then stopped at a red light so I put it back in drive but nothing so I put it back in four-wheel-drive again and got it going
It felt like the whole time driving it home like it was in 4 low and in low gear

Sounds like a transmission interlock problem. Take it to a shop or disconnect the tranny yourself and fix it.