Question: I am trying to implement a video retrieval system and I need to first extract key frames from a video, ideally I want to have a library for automatically detecting those key frames, one key frame from each shot. Bonus if I can configure which key frame to extract(first, middle, or last of the continuous frames in a shot).
Is there an open source implementation for this?

Answer: 
The ffmpeg lib (included in openCV) can seek to a keyframe with av\_seek\_frame()

see [FFMPEG reading keyframes](https://stackoverflow.com/questions/6316407/ffmpeg-reading-keyframes)
If you have as an input an uncompressed video, you can download the ffmpeg from [www.ffmpeg.org] and use this executable to decompress your video stream into its frames.

Subsequently, in order to detect your shot boundaries you have to extract some features from the video keyframes. An efficient technique for shot boundary detection is proposed in [MediaMixer Deliverable, D1.1.2](http://www.mediamixer.eu/wordpress/wp-content/uploads/2012/11/D1.1.2-final_Update1.pdf). In addition, in MediaMixer Webinars you can find the lecture [“Fragmenting your Media Assets meaningfully – media analysis for fragment detection and extraction”](http://videolectures.net/mediamixer_mezaris_media_assets/) where this shot-boundary detection implementation is presented, while you can also visit the MediaMixer demonstrator [http://www.mediamixer.eu/automatic-fragmentation-and-annotation-for-improved-access-to-lecture-videos/] where the results of video shot segmentation and concept detection are visualized.