https://gist.github.com/pierrenoizat/6880a12a599fa03a2099e3b38e8664e0
In a nutshell, if your witness script is like (for instance):
# script multisignature "2-of-2":
witness_script = BTC::Script.new << BTC::Script::OP_2 << @user_key.compressed_public_key << @escrow_key.compressed_public_key << BTC::Script::OP_2
witness_script << BTC::Script::OP_CHECKMULTISIG
then your witness program (script_pub_key) is:
script_pub_key = BTC::Script.new << BTC::Script::OP_0
script_pub_key<< BTC.sha256(witness_script.data) # witness program
This is a ruby example but you get the idea in any other programming language you are using. Hope this helps.