Go to the Settings > Power Save Settings > Set Time Until PS4 Turns Off. Select the General (Games) option and select after how much idle time your console will go off: After 1 Hour, After 2 Hours, After 3 Hours, After 4 Hours, or After 5 Hours.
If you would like to prevent your PlayStation 4 from shutting down while you are watching a movie, head back to Set Time Until PS4 Turns Off > Media Playback:
The auto shutdown settings for media playback can be adjusted separately.
N.B. You should not worry about losing unsaved app data or game progression. If the console detects an active game or app, it will automatically suspend your apps and switch to the Rest mode.
Photo by Nikita Kachanovsky on Unsplash