Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libvlc: how to snap a frame at any time

Tags:

c

libvlc

Now my method is:

libvlc_video_set_callbacks //set the lock,unlock,display callback functions
libvlc_media_player_set_position //goto the snap time
libvlc_media_player_play  //start playing

then in unlock callback function invoke 'libvlc_media_player_stop' to stop the play, and save the data which provider by display callback function.

This method had succeeded some times, but more times it will take my whole program crash. I know it looks a bit stupid, but I cannot found any frame by frame control function in the libvlc include files.

like image 307
coollofty Avatar asked Apr 26 '13 06:04

coollofty


1 Answers

Actually, the libvlc has a really poor handling of frame by frame since it is not the way it handles streams. Therefore, frame by frame - when there is some - is quite hacky and can be rather ugly. Going forward or backward one frame is often achieved by computing the length between two frames, and jumping to the corresponding datetime.

The only frame-related function in the library is libvlc_media_player_next_frame which seems to be conditionally supported and it also seems that some development is being done to later support libvlc_media_player_previous_frame.

Therefore, your method is probably as fine as any other would be. An alternative would be to replace libvlc_media_player_set_position by libvlc_media_player_set_time if you want to be able to set your time to the wanted millisecond. Yet another one would be to slow the playback down before snapping. None of these methods is really efficient though, but there does not seem to be any cleaner way to do so.

like image 83
Morwenn Avatar answered Oct 29 '22 15:10

Morwenn