Is there a way to insert a piece of different video in the middle of http dynamic stream (live or vod)? In case of Apple's HLS it is trivial - just put #EXT-X-DISCONTINUITY tags in m3u8 file before and after segments of inserted video, but I don't see anything similar in HDS.
I do not know if it is possible to do what you are asking by editing the f4m manifest file. I suspect not.
The usual way to insert ads is using an ad aware player. An ad enabled player gives you much more control over your pre-roll, mid-roll, post-roll, companion, rollover ads etc.
For the OSMF player there is lots of documentaion on www.osmf.org, and all of the ad networks have their own documentation which will help also.