Create a program to read and display video files, and use the slider bar to control the playback of video files. A slider is used to control the video playback position, jumping in 10 steps. Another slider to control stop/play

Source: Internet
Author: User

Create a program to read and display video files, and use the slider bar to control the playback of video files. A slider is used to control the video playback position, jumping in 10 steps. Another slider to control stop/play

/*Create a program to read and display video files, and use the slider bar to control the playback of video files. A slider is used to control the video playback position, jumping in 10 steps. Another slider to control stop/play*/#include<cv.h>#includeintG_slider_position =0; Cvcapture* G_capture =NULL;intindex =0;BOOLFlag =true;intG_slider_position1 =0;voidOntrackbarslider (intPOS)     {Cvsetcaptureproperty (g_capture, Cv_cap_prop_pos_frames, POS); //gets the properties of the video as a number of framesindex =Pos;}voidPlay_pause (intPOS) {    if(pos = =0) {flag=true; }    Else{flag=false; }}intMain () {Cvnamedwindow ("Main", cv_window_autosize); G_capture= Cvcreatefilecapture ("1.avi"); intFrames = (int) Cvgetcaptureproperty (g_capture, Cv_cap_prop_frame_count); //get the total number of frames in a video total number of frames in a video file    if(frames!=0) {Cvcreatetrackbar ("position","Main", &g_slider_position, frames, ontrackbarslider); //sets the position of the slider and is named position the slider bar's sliding position in the window main shows the maximum value of the slider each time the slider changes the callback functionCvcreatetrackbar ("Position1","Main", &g_slider_position1,1, Play_pause); }    Else{printf ("Read Video failed\n"); } iplimage*frame; Cvsettrackbarpos ("position","Main",1); //set the value of the slider barCvsettrackbarpos ("Position1","Main",0);  while(1) {Frame=Cvqueryframe (g_capture); //read the contents of a video file individually by frame        Charc = Cvwaitkey (Ten); if(c = = -) Break; Cvshowimage ("Main", frame); Cvsettrackbarpos ("position","Main", index); //sets the position of the current slider bar        if(flag) {Index= index +Ten;            Cvsetcaptureproperty (G_capture, Cv_cap_prop_pos_frames, index); //get the properties of a video        }        Else{cvsetcaptureproperty (g_capture, Cv_cap_prop_pos_frames, index); //Gets the video is the attribute}} cvreleasecapture (&g_capture); Cvdestroywindow ("Main"); return 0;}

Create a program to read and display video files, and use the slider bar to control the playback of video files. A slider is used to control the video playback position, jumping in 10 steps. Another slider to control stop/play

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.