modified version for hevc. Note: this version shutdown safe