A kind of control method of video stream frame rate
Technical field
The invention belongs to audio video synchronization technical field, especially a kind of control method of video stream frame rate.
Background technology
Supervisory control system is towards the future development of digitlization, intellectuality, automation, networking.Networking is the trend of the times of supervisory control system, and it has been simplified widely the mode of information transmission and has improved the speed that information is transmitted.Progressively ripe along with the development of network technology and computer technology and market applied environment, the network video monitor and control system based on video exchange technology has become supervisory control system developing direction.
Common camera that web camera is integrated and network commutator function, image can be converted to the packet based on TCP/IP network standard, the picture that video camera is taken the photograph is directly sent on network by RJ-45 Ethernet interface, can obtains far-end monitoring image by network.When have report to the police trigger time or manually this live video stream is recorded on PC or far-end storage facilities (as memory devices such as SD card, hard disks).Monitor staff can transfer video recording play, play time may need to carry out frame per second control, for example put soon, put slowly, play location and frame by frame play etc. so that institute's recorded video is analyzed.There is the problems such as control method complexity, speed be slow in the frame rate control method of existing video flowing.
Summary of the invention
The object of the invention is to overcome the deficiencies in the prior art, provide a kind of reasonable in design, control method is simple and the control method of fireballing video stream frame rate.
The present invention solves existing technical problem and takes following technical scheme to realize:
A control method for video stream frame rate, comprises the following steps:
(1) create the buffer queue that frame is play;
(2) video file is resolved and analysis result is stored in buffer queue;
(3) video is shown and carries out initialization and process video decode;
(4) reading video data information the video data getting is carried out to frame per second control from buffer queue;
(5) finish to play and discharge related resource.
And described buffer queue adopts fifo queue.
And described buffer queue comprises presentation of video frames queue and audio frame broadcasting queue; Described buffer queue comprises following information: whether this frame video position, the timestamp of this frame video, this frame video is hereof the data length of I frame and this frame video.
And (2) described step comprises following treatment step:
Step 201: open video file to be played, initialization video frame number flag bit;
Step 202: detect end-of-file mark and thread and exit flag bit, if condition is set up, exit document analysis, otherwise execution step 203;
Step 203: read video requency frame data and carry out frame head verification;
Step 204: resolve resolution, and log resolution;
Step 205, file are reorientated, and judge whether these frame data are video datas, if it is perform step 206, otherwise execution step 207;
Step 206: video requency frame data information is left in presentation of video frames queue, return to step 202;
Step 207: leave audio frame data message in audio frame and play in queue, return to step 202.
And described step (3) initialization video adopts third party's video decode storehouse in conjunction with Directshow display video mode.
And (4) described step is carried out frame per second control to video data and is comprised the following steps:
Step 401: detect thread or file and exit mark, if set exit, otherwise execution step 402;
Step 402: detect whether need to upgrade playback rate, if it is upgrade playback rate;
Step 403: whether inquiry needs frame-skipping to play, plays step if need to carry out frame-skipping;
Step 404: file reading is also carried out suitable operation;
Step 405: video frame rate control;
Step 406: displaying video;
Step 407: buffer queue pointer adds one, points to next frame video data information, returns to step 401.
And described step 402 comprises the following steps:
Step 40201: judge that speed changes flag bit, if set performs step 40202, otherwise execution step 403;
Step 40202: overall playback rate is set, and empties this flag bit, local zone time and video datum mark time reset simultaneously.
And described step 403 comprises the following steps:
Step 40301: the whether set of inquiry slider bar flag bit, if set performs step 40302, otherwise execution step 40303;
Step 40302: search forward nearest I frame according to the mark arranging, change buffer queue pointer, empty this mark, reset local zone time and video datum mark time;
Step 40303: whether inquiry next frame flag bit is true, very performs step 40304 if, otherwise execution step 40305;
Step 40304: paper suspension mark is set, empties next frame flag bit;
Step 40305: whether inquiry file pause flag position is true, very performs step 40306 if, otherwise execution step 404;
Step 40306: empty paper suspension flag bit, dormancy 100ms, refreshing video shows, reset local zone time and video datum mark time, returns to execution step 401.
And described step 404 comprises the following steps:
Step 40401: according to the information file reading in current buffer queue to specify buffering area in;
Step 40402: judge whether paper suspension flag bit is true, very performs step 406 if, otherwise execution step 405.
And described step 405 comprises the following steps:
Step 40501: whether the inquiry datum mark time resets, if resetted, performs step 40502, otherwise execution step 40504;
Step 40502: again obtain timestamp in the video information in current buffer queue pointer as the video datum mark time;
Step 40503: obtain local zone time, as the datum mark time of local zone time;
Step 40504: obtain the timestamp in the video information in current buffer queue pointer, and video datum mark subtracts each other the time difference obtaining between current video frame and datum mark, and according to current playback rate compression or elongate this time difference;
Step 40505: obtain current local zone time, subtract each other the program current location obtaining with poor with its local zone time with local time reference point;
Step 40506: inquiry local zone time is poor, and whether to be greater than video frame time poor, if be greater than, performs step 40507, otherwise execution step 406;
Step 40507: calculate that local zone time is poor deducts the poor difference of video frame time, and make this differential time of thread dormancy.
Advantage of the present invention and good effect are:
The present invention resolves each frame data and analysis result is deposited in the buffer queue of displaying video frame video file, by the mode that reads buffer queue, video requency frame data is carried out to frame per second control, adopt third party's video decode storehouse and in conjunction with Directshow display video mode simultaneously, processing speed and the result of broadcast of video frame rate are effectively improved, its method is easy and be easy to realization, can be widely used in video stream frame rate control field.
Brief description of the drawings
Fig. 1 is overall flow figure of the present invention;
Fig. 2 is step 2 is carried out dissection process flow chart to video file;
Fig. 3 is step 4 is carried out frame per second control flow chart to video data;
Fig. 4 is the process chart of step 402;
Fig. 5 is the process chart of step 403;
Fig. 6 is the process chart of step 404;
Fig. 7 is the process chart of step 405.
Embodiment
Below in conjunction with accompanying drawing, the embodiment of the present invention is further described.
A kind of control method of video stream frame rate, describe to be embodied as example in following video system: the front end of this system adopt the HISI3516 chip of Hai Si extend out FLASH, RAM taking LINUX as kernel, BUSYBOX is the video acquisition device of file system, be used for gathering audio, video data, the audio, video data gathering passes through network special delivery to PC, and on PC, completes video preview.Front end video acquisition device and PC can both be realized recording function, each frame video of their institute's recorded video files or audio frequency have the privately owned head of oneself, indicate these frame data some information (as timestamp, whether be I frame, this frame data length, be audio frequency or video data etc.).
A control method for video stream frame rate, as shown in Figure 1, comprises the following steps:
Step 1: create the buffer queue that frame is play.
This method employing is put into buffer queue by video data and is play, therefore, first need to set up the buffer queue that frame is play, buffer queue comprises presentation of video frames queue and audio frame broadcasting queue, this buffer queue can adopt FIFO(first in first out First Input First Output) queue, also can adopt other buffer queue structures.Describe as buffer queue as example taking fifo queue (video fifo queue and audio frequency fifo queue) below, this fifo queue is mainly stored following information: whether this frame video position, the timestamp of this frame video, this frame video is hereof data length of I frame (for H264 data), this frame video etc.
Step 2: video file is resolved and analysis result is stored in corresponding buffer queue.The concrete processing procedure that video file is resolved is as follows:
Step 201, open video file to be played, the flag bits such as initialization video frame number;
Step 202, detection end-of-file mark and thread exit flag bit, if condition is set up, exit document analysis, otherwise execution step 203;
Step 203, read video requency frame data and carry out frame head verification, if mistake is carried out corresponding wrong processing;
Step 204, parsing resolution, and log resolution, for future use;
Step 205, file are reorientated, and judge whether these frame data are video datas, if it is perform step 206, otherwise execution step 207;
Step 206, video requency frame data information is left in video fifo queue, return to step 202;
Step 207, audio frame data message is left in audio frequency fifo queue, return to step 202;
Step 3: video is shown and carries out initialization and process video decode.
The present embodiment adopts third party's video decode storehouse in conjunction with Directshow display video mode, in this step necessary initialization process that storehouse and video show of first decoding.
Step 4: obtain video data information from buffer queue, the video data getting is carried out to frame per second control.Concrete processing procedure is as follows:
Step 401, detection thread or file exit mark, if set performs step 5, otherwise execution step 402;
Whether step 402, detection need to upgrade playback rate, if need to, upgrade playback rate (this speed passes to this thread by interface from host computer);
Step 40201, judge speed change flag bit, if set performs step 40202, otherwise execution step 403;
Step 40202, overall playback rate is set, and empties this flag bit, local zone time and video datum mark time (object is for re-synchronization) reset simultaneously;
Whether step 403, inquiry need frame-skipping to play, and play step (need to reinitialize lock in time) if need to carry out frame-skipping;
The whether set of step 40301, inquiry slider bar flag bit, if set performs step 40302, otherwise execution step 40303;
Step 40302, search forward nearest I frame according to the mark arranging, change FIFO pointer, empty this mark, reset local zone time and video datum mark time (object is for re-synchronization);
Whether step 40303, inquiry next frame flag bit are true, very perform step 40304 if, otherwise execution step 40305;
Step 40304, paper suspension mark is set, empties next frame flag bit;
Whether step 40305, inquiry file pause flag position are true, very perform step 40306 if, otherwise execution step 404;
Step 40306, empty paper suspension flag bit, dormancy 100ms(thread switches), refreshing video shows, reset local zone time and video datum mark time (object is for re-synchronization), returns to execution step 401;
Step 404, file reading are also carried out suitable operation;
Step 40401, according to the information file reading in current FIFO to specify Buffer in;
Step 40402, judge that whether paper suspension flag bit is true, very perform step 406 if, otherwise execution step 405;
Step 405, video frame rate control;
Whether step 40501, inquiry datum mark time reset, if resetted, perform step 40502, otherwise execution step 40504;
Step 40502, again obtain timestamp in the video information in current FIFO pointer as the video datum mark time;
Step 40503, obtain local zone time, as the datum mark of local zone time;
Step 40504, obtain the timestamp in the video information in current FIFO pointer, and video datum mark subtracts each other the time difference obtaining between current video frame and datum mark.And compress or elongate this time difference according to current playback rate;
Step 40505, obtain current local zone time, subtract each other the program current location obtaining with poor with its local zone time with local time reference point;
Step 40506, inquiry local zone time are poor, and whether to be greater than video frame time poor, if be greater than, performs step 40507, otherwise execution step 406;
Step 40507, calculate that local zone time is poor deducts the poor difference of video frame time, and make this differential time of thread dormancy (completing synchronous key);
Step 406, displaying video;
Step 407, FIFO pointer add one, point to next frame video data information, return to step 401;
Step 5: discharge video and be correlated with and related resource.
It is emphasized that; embodiment of the present invention is illustrative; instead of determinate; therefore the present invention includes and be not limited to the embodiment described in embodiment; every other execution modes that drawn by those skilled in the art's technical scheme according to the present invention, belong to the scope of protection of the invention equally.