CN106998449A - Method, device and the terminal device of seamless video recording are realized in application layer - Google Patents

Method, device and the terminal device of seamless video recording are realized in application layer Download PDF

Info

Publication number
CN106998449A
CN106998449A CN201710228016.1A CN201710228016A CN106998449A CN 106998449 A CN106998449 A CN 106998449A CN 201710228016 A CN201710228016 A CN 201710228016A CN 106998449 A CN106998449 A CN 106998449A
Authority
CN
China
Prior art keywords
wrapper
encapsulation
video
data
audio
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201710228016.1A
Other languages
Chinese (zh)
Other versions
CN106998449B (en
Inventor
孙磊
王宏斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hisense Mobile Communications Technology Co Ltd
Original Assignee
Hisense Mobile Communications Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hisense Mobile Communications Technology Co Ltd filed Critical Hisense Mobile Communications Technology Co Ltd
Priority to CN201710228016.1A priority Critical patent/CN106998449B/en
Publication of CN106998449A publication Critical patent/CN106998449A/en
Application granted granted Critical
Publication of CN106998449B publication Critical patent/CN106998449B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N7/00Television systems
    • H04N7/18Closed-circuit television [CCTV] systems, i.e. systems in which the video signal is not broadcast
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N5/00Details of television systems
    • H04N5/76Television signal recording

Abstract

The embodiment of the present invention provides a kind of method, device and terminal device that seamless video recording is realized in application layer, it is first encoded using MediaCodec to preview video data and voice data, obtain audio/video coding data, then two wrappers are controlled alternately to be packaged to audio/video coding data using MediaMuxer, and before a wrapper stops an encapsulation process, another wrapper has pre-actuated and has started encapsulation operation, so that two neighboring video file has lap, leakage second phenomenon is eliminated.In the present embodiment, MediaCodec is run always after video recording starts, until seamless video recording terminates, the release for carrying out coder resource, reconstruction operation need not be circulated, two wrapper alternations that MediaMuxer is controlled, even if one of them needs to carry out resource release and reconstruction, also have another wrapper and be in encapsulation work state, really realize seamless video recording.

Description

Method, device and the terminal device of seamless video recording are realized in application layer
Technical field
The present embodiments relate to videoing skill field, more particularly to it is a kind of realized in android system application layer it is seamless Method, device and the terminal device of video recording.
Background technology
In production and living, many occasions are required for the monitoring record of the monitoring video, workshop on lasting video recording, such as street Driving recording on picture, automobile etc..Because video time is longer, the video file of recording is bigger, therefore continues in video process, no The video of recording may be all preserved in one file, it is necessary to according to time progress segmentation video recording, i.e., often record a period of time Just produce a video file.For example, the recording time for presetting each video file is 5 minutes, from 9:00:00 starts record System, then should obtain following video file successively in theory:9:00:00~9:05:First video file, 9 recorded in 00: 05:00~9:10:Second video file, 9 recorded in 00:10:00~9:15:The 3rd video file recorded in 00 Deng.
But the videotaping protocol that existing video recording equipment is used, from a video file (stopping video recording) is preserved to newly-built one Video file (restarts video recording), needs certain time interval;And during this period of time, video recording program at least needs Complete release decoder and wrapper, re-create the action such as wrapper and decoder, it is impossible to recorded a video, i.e., the so-called leakage second Phenomenon, leakage time second is generally in 1s or so.For example in example described above, for second video file, it starts video recording Time can be than 9:05:In 00 evening, be such as probably 9:05:01, accordingly, the actual video time of second video file is 9:05: 01~9:10:01.
It can be seen that, existing videotaping protocol can not really realize lasting video recording, within the period of leakage second, it is most likely that occur Critical event, can not but be recorded in video file.Therefore, needing badly a kind of can eliminate the seamless video recording side of Lou second phenomenon Case.
The content of the invention
Provided in the embodiment of the present invention it is a kind of android system application layer realize the method for seamless video recording, device and Terminal device, to solve the existing leakage for continuing generally existing in videotaping protocol second problem.
In a first aspect, the embodiments of the invention provide a kind of method for realizing seamless video recording in android system application layer, This method includes:
Preview video data and voice data are encoded by encoder interfaces MediaCodec, audio frequency and video volume is obtained Code data;It is used to carry out in advance on screen in the original video data that the preview video data collect for video acquisition device Look at the preview frame data of display;
First wrapper is started by wrapper interface MediaMuxer, and the sound regarded by first wrapper The execute encapsulation of frequency coded data is operated;
Before first wrapper stops encapsulation, the second wrapper is started by the MediaMuxer, and pass through Second wrapper is operated to the audio/video coding data execute encapsulation;
Before second wrapper stops encapsulation, first encapsulation is restarted by the MediaMuxer Device.
Optionally, before first wrapper stops encapsulation, the second wrapper is started by the MediaMuxer, Including:
When current time, which reaches first, opens the moment in advance, second wrapper is started by the MediaMuxer;Its In, described first it is pre- to open the moment be the first preset interval time relative to the lead at the first segmentation moment, first segmentation At the time of moment is that first wrapper stops encapsulation;
Before second wrapper stops encapsulation, first encapsulation is restarted by the MediaMuxer Device, including:
When current time, which reaches second, opens the moment in advance, first encapsulation is restarted by the MediaMuxer Device;Wherein, described second pre- to open the moment be the second preset interval time, described second relative to the lead at the second segmentation moment At the time of splitting the moment for second wrapper stopping encapsulation.
Optionally, methods described also includes:
When reaching the first segmentation moment at current time, first wrapper is controlled to stop encapsulation operation, and protect Deposit the video file that the encapsulation of the first wrapper is obtained;
When reaching the second segmentation moment at current time, second wrapper is controlled to stop encapsulation operation, and protect Deposit the video file that the encapsulation of the second wrapper is obtained.
Optionally, methods described also includes:
At the described first segmentation moment and the second pre- any time opened between the moment, the MediaMuxer is in control Make after the first wrapper stopping encapsulation operation, arrival described second was opened before the time in advance, in addition to:It is described MediaMuxer discharges first wrapper, and re-creates first wrapper;
At the described second segmentation moment and the first pre- any time opened between the moment, the MediaMuxer releases Second wrapper, and re-create second wrapper.
Optionally, methods described also includes:
After the first wrapper is started, detect in the audio/video coding data whether there is key frame arrival, and described After key frame arrives, the step of being operated described in execution by the first wrapper to the audio/video coding data execute encapsulation;
And/or, after the second wrapper is started, detect in the audio/video coding data whether there is key frame arrival, and After key frame arrival, the step operated described in execution by the second wrapper to the audio/video coding data execute encapsulation Suddenly.
Optionally, methods described also includes:
According to the interval time of two neighboring key frame, first preset interval time is determined and/or described second pre- If interval time.
Optionally, the first wrapper of the startup, including:The first video file is created, and in first video file Middle write-in decoding configuration data;
The second wrapper of the startup, including:Create the second video file, and the write-in solution in second video file Code configuration data.
Second aspect, the embodiments of the invention provide a kind of device that seamless video recording is realized in android system application layer, The device includes:Coding control unit and encapsulation control unit;
The coding control unit is used for, by encoder interfaces MediaCodec to preview video data and voice data Encoded, obtain audio/video coding data;The preview video data are the original video number that video acquisition device is collected It is used to carry out the preview frame data that preview is shown on screen in;
The encapsulation control unit is used for, and starts the first wrapper by wrapper interface MediaMuxer, and pass through institute The first wrapper is stated to operate the audio/video coding data execute encapsulation;Before first wrapper stops encapsulation, lead to Cross the MediaMuxer and start the second wrapper, and envelope is performed to the audio/video coding data by second wrapper Dress operation;Before second wrapper stops encapsulation, first wrapper is restarted by the MediaMuxer.
Optionally, the encapsulation control unit can be specifically configured as:When current time, which reaches first, opens the moment in advance, Second wrapper is started by the MediaMuxer;Wherein, described first moment carrying relative to the first segmentation moment is opened in advance Preceding amount is the first preset interval time, at the time of the first segmentation moment is that first wrapper stops encapsulation;
The encapsulation control unit can be additionally configured to:When current time, which reaches second, opens the moment in advance, by described MediaMuxer starts the first wrapper;Wherein, described second pre- to open the moment be the relative to the lead at the second segmentation moment Two preset interval times, at the time of the second segmentation moment is that second wrapper stops encapsulation.
Optionally, the encapsulation control unit can be additionally configured to:The first segmentation moment is reached at current time When, control first wrapper to stop encapsulation operation, and preserve the video file that the encapsulation of the first wrapper is obtained;And, When current time reaches the second segmentation moment, second wrapper is controlled to stop encapsulation operation, and preservation second is encapsulated The video file that device encapsulation is obtained.
Optionally, described device also includes:
Key frame detection unit, for after the encapsulation control unit starts the first wrapper, detecting the audio frequency and video Whether there is key frame arrival in coded data, and after key frame arrival, trigger the encapsulation control unit execution described The step of being operated by first wrapper to the audio/video coding data execute encapsulation;
And/or, for after the encapsulation control unit starts the second wrapper, detecting in the audio/video coding data Whether have a key frame arrival, and after key frame arrival, trigger the encapsulation control unit perform it is described by described the The step of two wrappers are operated to the audio/video coding data execute encapsulation.
The third aspect, the embodiments of the invention provide a kind of terminal device, including:Camera, microphone, processor and Memory;
Be stored with the computer program that can be run on the processor in the memory;The processor passes through default Interface is connected with the camera, microphone and memory;
The camera is used to gather video data;
The microphone is used to gather voice data;
The processor is used to perform the computer program, so that the terminal device realizes any of the above embodiment institute The seamless kinescope method stated.
From above technical scheme, existing video recording interface MediaRecoder integrated packaging video recording stream is different from Journey, the embodiment of the present invention is first encoded using encoder interfaces MediaCodec to preview video data and voice data, is obtained To audio/video coding data, then the audio/video coding data are packaged using wrapper interface MediaMuxer, sealed Dress process is:The encapsulation operation to audio/video coding data is alternately performed by two wrappers, and is stopped in a wrapper Before encapsulation process, another wrapper has pre-actuated and has started encapsulation operation so that two neighboring video file There is lap, Lou second phenomenon can be completely eliminated.In the present embodiment, encoder interfaces MediaCodec is after video recording starts Run always, until whole seamless video process terminates, it is not necessary to which circulation carries out the release of coder resource, reconstruction operation, envelope Two wrappers being controlled of dress device interface MediaMuxer, even if needing to carry out resource release and again after completing once to encapsulate Build, also have another wrapper and be in encapsulation work state, will not occur to leak second phenomenon, really realize seamless video recording.
It should be appreciated that the general description of the above and detailed description hereinafter are only exemplary and explanatory, not The disclosure can be limited.
Brief description of the drawings
Accompanying drawing herein is merged in specification and constitutes the part of this specification, shows the implementation for meeting the present invention Example, and for explaining principle of the invention together with specification.
In order to illustrate more clearly about the embodiment of the present invention or technical scheme of the prior art, below will be to embodiment or existing There is the accompanying drawing used required in technology description to be briefly described, it should be apparent that, for those of ordinary skill in the art Speech, without having to pay creative labor, can also obtain other accompanying drawings according to these accompanying drawings.
Fig. 1 is a kind of stream of method that seamless video recording is realized in android system application layer provided in an embodiment of the present invention Cheng Tu;
Fig. 2 is time shaft schematic diagram when seamless kinescope method provided in an embodiment of the present invention is performed;
Fig. 3 is another method for realizing seamless video recording in android system application layer provided in an embodiment of the present invention Signal flow diagram;
Fig. 4 is the corresponding signal flow diagram of seamless kinescope method shown in Fig. 3;
Fig. 5 is a kind of knot of device that seamless video recording is realized in android system application layer provided in an embodiment of the present invention Structure schematic diagram;
Fig. 6 is a kind of structured flowchart of terminal device with seamless recording function provided in an embodiment of the present invention.
Embodiment
The embodiments of the invention provide a kind of method, device and end that seamless video recording is realized in android system application layer End equipment, to solve the existing leakage for continuing generally existing in videotaping protocol second problem.
Inventor has found that prior art in the original design of android system, is collected by height in research process Recording interface MediaRecorder into encapsulation realizes recording function.The problem of this highly integrated packaging belt comes is exactly to provide Source discharge and rebuild it is time-consuming longer;Collect specifically, being realized using MediaRecorder in recording function, MediaRecorder Into method traversal perform once (including video recording start when establishment/acquisition to various resources, and video recording at the end of to various The release of resource), a video process is completed, a video file is obtained, i.e., the video recording for often completing a period (obtains one Individual video file), the actions such as release encoder, release wrapper, release Camera resources will be performed successively, then started During the video recording of next period, then establishment Camera resources are performed successively, wrapper is created, creates the action such as encoder.Can See, during prior art is based on MediaRecorder realization video recordings, the execution of flow when video recording terminates and restarted Complexity is high, time-consuming longer, is the major reason for causing Lou second problem.
In view of this, the embodiment of the present invention is programmed using the most foundation code of multi-media decoding and encoding, including using volume Code device interface MediaCodec realizes the coding to audio frequency and video, and is worked always in whole seamless video process, using encapsulation Device interface MediaMuxer creates two wrapper Muxer, realizes the encapsulation to audio/video coding data, each wrapper work A video file is once obtained, by controlling two wrapper alternations, the audio frequency and video persistently exported to encoder are realized The continual encapsulation operation of coded data, it is ensured that the leakage second is not present in encapsulation process, so as to ensure to start after video recording each moment Video data can be encoded, encapsulate and write in video file, eliminate leakage second phenomenon, realize seamless lasting video recording.With The embodiment of the present invention is described in detail lower combination accompanying drawing.
The side that seamless video recording is realized in android system application layer that Fig. 1 provides for a feasible embodiment of the invention The flow chart of method.Reference picture 1, the seamless kinescope method at least comprises the following steps:
S11, by encoder interfaces MediaCodec preview video data and voice data are encoded, obtain sound and regard Frequency coded data;
It is used to carry out on screen in the original video data that the preview video data collect for video acquisition device The preview frame data that preview is shown.In practical application, in order that the current Video content of user's real-time tracking preview, it will usually root Interception parts of images frame in the original image gathered according to the picture refreshing rate of screen from camera, i.e., above-mentioned preview video data, It is shown in real time on screen.Due to the original image that camera is gathered, it can only be obtained in local framework (Native) layer of system Arrive, and preview video data can be got in systematic difference layer, therefore in the present embodiment, MediaCodec is for above-mentioned Preview video data are encoded so that this method be implemented without change system bottom (such as above-mentioned Native layers) generation Code, improves coding freedom.
S12, by wrapper interface MediaMuxer start the first wrapper, and pass through first wrapper receive institute State audio/video coding data;
S13, by first wrapper audio/video coding data execute encapsulation is operated, and in first envelope Fill before device stopping encapsulation, perform step S14;
S14, start the second wrapper by the MediaMuxer, and the sound is received by second wrapper and regard Frequency coded data;
S15, by second wrapper audio/video coding data execute encapsulation is operated, and in second envelope Fill before device stopping encapsulation, perform step S12.
In the present embodiment, step S13 just starts the second wrapper before the first wrapper stops encapsulation, and passes through second Wrapper receives audio/video coding data so that, start to this period that the first wrapper stops encapsulation from the second wrapper It is interior, while there is the first wrapper and the second wrapper to receive audio/video coding data and carry out encapsulation operation so that ensure from " by It is existing that during being switched to " being operated by the second wrapper execute encapsulation " will not occur for the first wrapper execute encapsulation operation " the leakage second As;Likewise, in step S15, before the second wrapper stops encapsulation, step S12 is just performed again, start first and encapsulate Device, and audio/video coding data are received by the first wrapper so that, start to the second wrapper from the first wrapper and stop envelope In this period of dress, while there is the second wrapper and the first wrapper to receive audio/video coding data and carry out encapsulation operation, So as to ensure from during " being operated by the second wrapper execute encapsulation " is switched to " being operated by the first wrapper execute encapsulation " Will not occur to leak second phenomenon.
Time shaft schematic diagram when the seamless kinescope method that the present embodiment shown in reference picture 2 is provided is performed, it is known that, this reality Apply each wrapper in example and often perform an encapsulation operation, a video file will be generated;The t1 moment after video recording is started, Audio/video coding data are received by the first wrapper first and are packaged;Then, in first wrapper this was encapsulated At the t2 moment before journey stopping, the audio/video coding data that the second wrapper just starts and exported to current encoder are sealed Dress, now, the first wrapper is also continuing to the audio/video coding data and is being packaged;Then, at t3 moment, first Wrapper stops encapsulation, obtains a video file F1, the second wrapper then continues executing with encapsulation operation;It is similar with the t2 moment , the t4 moment before the second wrapper stops encapsulation, the first wrapper is again started up execute encapsulation operation;At t5 moment, Two wrappers stop encapsulation, obtain video file F2, it is visible that the first wrapper continues executing with encapsulation operation ..., t2~t3 this In one period, recording in this period of t2~t3 is all preserved in the overlapping work of two wrappers in video file F1 and F2 Audio, video data, likewise, within this period of t4~t5, two wrappers also overlapping work so that video file F2 With the audio, video data recorded in this period of t4~t5 is all preserved in F3.
That is, the present embodiment is by there is overlapping alternation between the first wrapper and the second wrapper so that whole record In the two neighboring video file obtained as process, the tail portion of previous video file is all opened with latter video file Head point has overlapping, so as to thoroughly avoid Lou second phenomenon, it is ensured that from start to record a video each into terminal procedure of recording a video when The audio, video data at quarter is all encapsulated into video file, really realizes seamless video recording.
From above technical scheme, the embodiment of the present invention gives up existing video recording interface MediaRecoder integration packaging Preview video data and voice data are first encoded, obtain sound by formula video recording process using encoder interfaces MediaCodec Then the audio/video coding data are packaged, encapsulated by video data encoder using wrapper interface MediaMuxer Cheng Wei:The encapsulation operation to audio/video coding data is alternately performed by two wrappers, and is stopped once in a wrapper Before encapsulation process, another wrapper has pre-actuated and has started encapsulation operation so that two neighboring video file is present Lap, can be completely eliminated Lou second phenomenon.In the present embodiment, encoder interfaces MediaCodec after video recording starts always Operation, until whole seamless video process terminates, it is not necessary to which circulation carries out the release of coder resource, reconstruction operation, wrapper Two wrappers that interface MediaMuxer is controlled, even if needing to carry out resource release and reconstruction after completing once to encapsulate, Also have another wrapper and be in encapsulation work state, will not occur to leak second phenomenon, really realize seamless video recording.
In a feasible embodiment, because MediaCodec is to obtain preview video data from systematic difference layer to come Video coding is carried out, therefore above-mentioned encoder interfaces MediaCodec and encapsulation can be realized respectively based on programming languages such as Java Device interface MediaMuxer, and application package is made as (such as the installation text of the apk forms applied to android system Part) so that any terminal device can not change the premise of system bottom code (need not change or more new system) Under, by installing the application package, to make terminal device realize the seamless recording function described in the present embodiment.It can be seen that, this reality Applying the seamless kinescope method of example offer has very strong portability, and any end can be easily ported to by application package In end equipment.
In a feasible embodiment of the invention, start the first wrapper in above-mentioned steps S12, can specifically include: Create the first video file, and the write-in decoding configuration data in first video file;Accordingly, start in step S14 Second wrapper, can specifically include:Create the second video file, and the write-in decoding configuration number in second video file According to.
That is, each wrapper creates the video file of this encapsulation first when starting a new encapsulation process, specifies The filename of the video file (is such as named as 20160926090000.mp4 according to current system time, represented at 2016 9 Months 26 days 9 points start to record), and the write-in decoding configuration data in the video file, with when playing the video file and playing, The video file is decoded according to the decoding configuration data.
Fig. 3 is another method that seamless video recording is realized in android system application layer provided in an embodiment of the present invention Flow chart, Fig. 4 is the corresponding signal flow diagrams of Fig. 3.Reference picture 3 and Fig. 4, this method comprise the following steps:
S11, by encoder interfaces MediaCodec preview video data and voice data are encoded, obtain sound and regard Frequency coded data;
S12, first wrapper started by wrapper interface MediaMuxer, pass through first wrapper and receive The audio/video coding data, and step S131, S132 and S133 are performed respectively;
S131, by first wrapper audio/video coding data are started with execute encapsulation operation;
S132, judge whether current time is first to open the moment in advance, if it is, continuing executing with step S14, otherwise repeat Perform step S132;
S133, judge whether current time was the first segmentation moment, if it is, performing step S134, otherwise repeat to hold Row step S133;
S134, control first wrapper stop encapsulation operation, and preserve the video recording text that the encapsulation of the first wrapper is obtained Part;
S14, second wrapper started by wrapper interface MediaMuxer, pass through second wrapper and receive The audio/video coding data, and step S151, S152 and S153 are performed respectively;
S151, by second wrapper audio/video coding data execute encapsulation is operated;
S152, judge whether current time is second to open the moment in advance, if it is, return to step S12, is otherwise repeated Step S152;
S153, judge whether current time was the second segmentation moment, if it is, performing step S154, otherwise repeat to hold Row step S153;
S154, control second wrapper stop encapsulation operation, and preserve the video recording text that the encapsulation of the second wrapper is obtained Part.
In the present embodiment, first opens the moment earlier than the first segmentation moment in advance, and the time difference therebetween (calls first in the following text to preset Interval time) it can be configured according to the actual requirements;Likewise, second it is pre- open the moment earlier than the second segmentation moment, the two it Between time difference (calling the second preset interval time in the following text) can also be configured according to the actual requirements.During first predetermined interval Between can be with identical with the second preset interval time, can also be different.
In a feasible embodiment, the video recording duration of each video file before video recording is started, can be set, and First preset interval time and the second preset interval time so that when being packaged by the first wrapper, according to this first (namely at the beginning of the video file that currently preserves of the first wrapper between) and the record between at the beginning of wrapper encapsulation operation As the duration time started determined for the first segmentation moment, during further according to the first segmentation moment and the first predetermined interval pre-set Between determine first to open the moment in advance;Likewise, when being packaged by the second wrapper, according to the second wrapper encapsulation operation At the beginning of between (namely at the beginning of the video file that currently preserves of the second wrapper between) and the video recording duration time started Determined for the second segmentation moment, determine that second opens in advance further according to the second segmentation moment and the second preset interval time pre-set Moment.
It can be seen that, the present embodiment, can be in an encapsulation by parameters such as the video recording duration, the preset interval times that pre-set While device execute encapsulation is operated, the Startup time of another wrapper is determined, it is ensured that the Startup time of another wrapper is early At the time of this wrapper stops encapsulating, really seamless video recording is realized.Meanwhile, when the present embodiment can also adjust predetermined interval Between, so as to adjust the overlapping working time of two wrappers, namely the overlapping time of two neighboring video file is adjusted, to meet Different practical application requests;For example, when the memory space of video recording equipment is smaller, can suitably reduce preset interval time, Avoid storing the overlapping of long period between video file, so as to save the memory space of video file.
In a feasible embodiment of the invention, MediaMuxer, can be with after the first wrapper (step S12) is started First detect in the audio/video coding data (being specifically video data encoder) that the first wrapper is got whether there is key frame Arrive, and encapsulation operation (step S13 or S131) is proceeded by after key frame arrival, then from the key frame;Accordingly, MediaMuxer can first detect the audio frequency and video that the second wrapper is got after the second wrapper (step S14) is started Whether key frame arrival is had in coded data, and execute encapsulation is operated after key frame arrival, then since the key frame (step S15 or S151).
Due to video coding process be by group carry out, each group of coded data all since a key frame (i.e. I frames), Each key frame is a complete picture, but the frame of video between key frame is incomplete, is needed in broadcast decoder Calculated and obtained according to related key frame, therefore, if the first frame of video file is not key frame, the beginning portion when playing Divide to be correctly decoded to calculate and obtain complete picture, cause mosaic effect, therefore, the embodiment of the present invention is starting wrapper Afterwards, key frame is detected, and just starts execute encapsulation when detecting key frame and operated so that the head of each video file Frame is all key frame, can avoid mosaic effect occur when the beginning part of the video file is being played.
In a feasible embodiment of the invention, based on above-mentioned key frame detecting step, above-mentioned seamless kinescope method is also It may include following steps:
According to the interval time of two neighboring key frame, first preset interval time is determined and/or described second pre- If interval time.
Assuming that in video data encoder two neighboring key frame interval time be 1s, then can will described first preset between Every time and the second preset interval time, be both configured to [1s, 2s) between any number.Time shaft with reference to shown in Fig. 2 shows It is intended to, if F1 last frame is key frame, t2 is really to fall the third last key frame and penultimate in F1 Between key frame, therefore the second wrapper is when F1 penultimate key frame arrives, the number in F2 after write-in encapsulation According to, F1 and F2 it is overlapping when an a length of interval time, i.e. 1s;If F1 last frame is not key frame, t2 falls in F1 Most latter two key frame between, therefore the second wrapper writes data since F1 last key frame in F2, F1 and F2 overlapping duration is less than 1s.
It can be seen that, by above-mentioned setting, ensure two neighboring video file have it is overlapping on the premise of, it is ensured that overlapping time is not More than 1s (interval time), thus avoid two neighboring video file overlapping time it is long cause data redundancy, mitigate phase Close memory cell and pressure is stored to video file.
, both can be by the above method, in video process, by detecting audio/video coding in real time in the embodiment of the present invention The interval time of key frame in data, to determine first preset interval time and the second preset interval time, so that it is determined that Each wrapper is corresponding to be split the moment and opens the moment in advance;It can also be encoded before video recording is started previously according in terminal device The relevant parameter of device determines the interval time of key frame, and then when determining first preset interval time and the second predetermined interval Between, so that in video process, each wrapper is determined according to first preset interval time and the second preset interval time It is corresponding to split the moment and open the moment in advance, it is ensured that what startup and stopping to each wrapper were encapsulated is precisely controlled.
In a feasible embodiment of the invention, in above-mentioned seamless kinescope method, after each wrapper stops encapsulation, Following operation can be performed;Discharge the wrapper, and using wrapper create thread and re-create and obtain the wrapper.
Specifically, pre- opening between the moment (i.e. Fig. 3 or the step shown in Fig. 4 at the described first segmentation moment and described second S133 between S152, namely before the first wrapper stops to its next time starting after this encapsulation) any time, it is described MediaMuxer can perform following steps:First wrapper is discharged, and re-creates first wrapper, with described Second opens when reaching constantly (step S152) in advance, can start first wrapper in time;Accordingly, when described second splits Carve and described first pre- opens between the moment that (i.e. Fig. 3 or the step S153 shown in Fig. 4 between S132, namely the second wrapper stops Before only starting after this encapsulation to its next time) any time, the MediaMuxer can perform following steps:Release Second wrapper, and re-create second wrapper, with stay in described first it is pre- open reach constantly when (step S132), and Shi Qidong second wrappers.
It can be seen that, in the present embodiment, the first wrapper complete once encapsulation, it is necessary to carry out resource release and reconstruction when, Through there is the second wrapper to take over its encapsulation work, so as to complete releasing for the first wrapper in the second wrapper course of work Put and reconstruction operation, in case completing to take over the second encapsulation when once encapsulation needs and carries out resource release and reconstruction in the second wrapper Device execute encapsulation works.Meanwhile, wrapper is often completed after an encapsulation process (obtaining a video file), is carried out once releasing Put, rebuild, same wrapper can be avoided to take same system resource for a long time, cause the phenomenons such as system mistake.
In a feasible embodiment of the invention, the guarantor described in the step S134 and S154 of above-mentioned seamless kinescope method Video file is deposited, is specifically as follows:Video file is preserved into buffer unit set in advance;Accordingly, the seamless video recording Method also includes:Video file in the buffer unit is being transferred to hard disk or storage card.
It is used to storing the memory cell of video file that (the read-only of such as terminal device is deposited in practical application, in terminal device Reservoir (Read only Memory, ROM), or embedded SD (Secure Digital) blocks, TF (T-Flash) blocks various etc. deposit Card storage) writing speed may be relatively slow, if its writing speed is less than the frame per second of video file, video file can be caused It is difficult to be stored in memory cell in time, or the correct storage of video file can only be ensured by reducing video recording frame per second.There is mirror In this, the embodiment of the present invention first passes through the larger buffering area of writing speed in terminal device and (is generally random access memory (Ramdom Access Memory, RAM)) caching video file, then the video file of caching is transferred to memory cell successively In.
It can be seen that, the embodiment of the present invention solves the writing speed of video recording frame per second and memory cell not by increasing level cache The problem of matching, on the premise of video recording frame per second is not reduced, it is ensured that video file is correctly stored into corresponding memory cell.
Fig. 5 is a kind of knot for the device that seamless video recording is realized in android system application layer provided in an embodiment of the present invention Structure schematic diagram.Reference picture 5, the device at least includes:
Coding control unit 510, for by encoder interfaces MediaCodec to preview video data and voice data Encoded, obtain audio/video coding data;The preview video data are the original video number that video acquisition device is collected It is used to carry out the preview frame data that preview is shown on screen in;
Control unit 520 is encapsulated, for starting the first wrapper by wrapper interface MediaMuxer, and by described First wrapper is operated to the audio/video coding data execute encapsulation;Before first wrapper stops encapsulation, pass through The MediaMuxer starts the second wrapper, and by second wrapper to the audio/video coding data execute encapsulation Operation;Before second wrapper stops encapsulation, first wrapper is restarted by the MediaMuxer.
From above technical scheme, existing video recording interface MediaRecoder integrated packaging video recording stream is different from Journey, the embodiment of the present invention is first encoded using encoder interfaces MediaCodec to preview video data and voice data, is obtained To audio/video coding data, then the audio/video coding data are packaged using wrapper interface MediaMuxer, sealed Dress process is:The encapsulation operation to audio/video coding data is alternately performed by two wrappers, and is stopped in a wrapper Before encapsulation process, another wrapper has pre-actuated and has started encapsulation operation so that two neighboring video file There is lap, Lou second phenomenon can be completely eliminated.In the present embodiment, encoder interfaces MediaCodec is after video recording starts Run always, until whole seamless video process terminates, it is not necessary to which circulation carries out the release of coder resource, reconstruction operation, envelope Two wrappers being controlled of dress device interface MediaMuxer, even if needing to carry out resource release and again after completing once to encapsulate Build, also have another wrapper and be in encapsulation work state, will not occur to leak second phenomenon, really realize seamless video recording.
In a feasible embodiment of the invention, above-mentioned encapsulation control unit 520 starts the first wrapper, specifically can be with Including:Create the first video file, and the write-in decoding configuration data in first video file;Accordingly, above-mentioned encapsulation Control unit 520 starts the second wrapper, can specifically include:The second video file is created, and in second video file Middle write-in decoding configuration data.
In a feasible embodiment of the invention, to realize before first wrapper stops encapsulation, start the Two wrappers, the encapsulation control unit 520 can be specifically configured as:When current time, which reaches first, opens the moment in advance, lead to Cross the MediaMuxer and start the second wrapper;Wherein, described first moment shifting to an earlier date relative to the first segmentation moment is opened in advance Measure as the first preset interval time, at the time of the first segmentation moment is that first wrapper stops encapsulation.
Likewise, to realize before second wrapper stops encapsulation, starting the first wrapper, the encapsulation control Unit 520 can be specifically configured as:When current time, which reaches second, opens the moment in advance, the is started by the MediaMuxer One wrapper;Wherein, described second pre- to open the moment be the second preset interval time, institute relative to the lead at the second segmentation moment At the time of stating for the second segmentation moment for second wrapper stopping encapsulation.
In a feasible embodiment of the invention, above-mentioned seamless recording apparatus can also include:
Key frame detection unit, for after above-mentioned encapsulation control unit 520 starts the first wrapper, detecting that the sound is regarded Whether there is key frame arrival in frequency coded data, and after key frame arrival, trigger the encapsulation control unit 520 and continue The step of being operated described in performing by first wrapper to the audio/video coding data execute encapsulation;
And/or, for after the encapsulation control unit 520 starts the second wrapper, detecting the audio/video coding number Whether there is key frame arrival in, and after key frame arrival, triggering encapsulation control unit 520 performs described by described The step of second wrapper is operated to the audio/video coding data execute encapsulation.
The embodiment of the present invention is detected, and just start when detecting key frame after wrapper is started to key frame Execute encapsulation is operated so that the first frame of each video file is key frame, can avoid the beginning part in the video file There is mosaic effect when playing.
In a feasible embodiment of the invention, above-mentioned seamless recording apparatus can also include:
Lead determining unit, for the interval time according to two neighboring key frame, determines first predetermined interval Time and/or second preset interval time.
In a feasible embodiment of the invention, encapsulation control unit 520 is additionally configured to:When described first splits Carve and the second pre- any time opened between the moment, discharge first wrapper, and pass through MediaMuxer weights Newly create first wrapper;And, at the described second segmentation moment and the first pre- any time opened between the moment, Second wrapper is discharged, and second wrapper is re-created by the MediaMuxer.
It can be seen that, in the present embodiment, the first wrapper complete once encapsulation, it is necessary to carry out resource release and reconstruction when, Through there is the second wrapper to take over its encapsulation work, so as to complete releasing for the first wrapper in the second wrapper course of work Put and reconstruction operation, in case completing to take over the second encapsulation when once encapsulation needs and carries out resource release and reconstruction in the second wrapper Device execute encapsulation works.Meanwhile, wrapper is often completed after an encapsulation process (obtaining a video file), is carried out once releasing Put, rebuild, same wrapper can be avoided to take same system resource for a long time, cause the phenomenons such as system mistake.
In a feasible embodiment of the invention, above-mentioned seamless recording apparatus can also include:
Caching control unit, video file and the second wrapper for respectively obtaining the encapsulation of the first wrapper are encapsulated To video file preserve to buffer unit, then the video file in the buffer unit is transferred to hard disk or storage card.
The embodiment of the present invention is by increasing level cache, and the writing speed for solving video recording frame per second and memory cell is unmatched Problem, on the premise of video recording frame per second is not reduced, it is ensured that video file is correctly stored into corresponding memory cell.
Fig. 6 is a kind of structured flowchart of the terminal device with seamless recording function provided in an embodiment of the present invention.Reference Fig. 6, the terminal device includes:Camera 610, microphone 620, processor 630 and memory 640.
Wherein, be stored with the computer program that can be run on the processor in the memory;The processor leads to Preset interface is crossed to be connected with the camera, microphone and memory.
The camera 610 is used to gather video data;The Mike 620 is used to gather voice data;The processor 630 are used to perform the computer program stored in the memory, so that the terminal device realizes any one embodiment above Described seamless kinescope method.
It can be seen that, it is different from existing video recording interface MediaRecoder integrated packaging video recording process, the embodiment of the present invention First preview video data and voice data are encoded using encoder interfaces MediaCodec, audio/video coding number is obtained According to then use wrapper interface MediaMuxer is packaged to the audio/video coding data, and encapsulation process is:Pass through two Individual wrapper is alternately performed the encapsulation operation to audio/video coding data, and a wrapper stop encapsulation process it Before, another wrapper has pre-actuated and has started encapsulation operation so that two neighboring video file has lap, can So that Lou second phenomenon is completely eliminated.In the present embodiment, encoder interfaces MediaCodec is run always after video recording starts, until whole Individual seamless video process terminates, it is not necessary to which circulation carries out the release of coder resource, reconstruction operation, wrapper interface Two wrappers that MediaMuxer is controlled, even if needing to carry out resource release and reconstruction after completing once to encapsulate, also can There is another wrapper to be in encapsulation work state, will not occur to leak second phenomenon, really realize seamless video recording.
For convenience of description, it is divided into various units during description apparatus above with function to describe respectively.Certainly, this is being implemented The function of each unit can be realized in same or multiple softwares and/or hardware during invention.
Each embodiment in this specification is described by the way of progressive, identical similar portion between each embodiment Divide mutually referring to what each embodiment was stressed is the difference with other embodiment.Especially for device or For system embodiment, because it is substantially similar to embodiment of the method, so describing fairly simple, related part is referring to method The part explanation of embodiment.Apparatus and system embodiment described above is only schematical, wherein being used as separation The unit of part description can be or may not be it is physically separate, the part shown as unit can be or It can not be physical location, you can with positioned at a place, or can also be distributed on multiple NEs.Can be according to reality Some or all of module therein is selected to realize the purpose of this embodiment scheme the need for border.
Those of ordinary skill in the art are without creative efforts, you can to understand and implement.Above only It is the embodiment of the present invention, it is noted that for those skilled in the art, do not departing from this hair On the premise of bright principle, some improvements and modifications can also be made, these improvements and modifications also should be regarded as the protection model of the present invention Enclose.

Claims (10)

1. a kind of method for realizing seamless video recording in android system application layer, it is characterised in that including:
Preview video data and voice data are encoded by encoder interfaces MediaCodec, audio/video coding number is obtained According to;It is used to the progress preview on screen in the original video data that the preview video data collect for video acquisition device show The preview frame data shown;
First wrapper is started by wrapper interface MediaMuxer, and the audio frequency and video compiled by first wrapper The execute encapsulation operation of code data;
Before first wrapper stops encapsulation, the second wrapper is started by the MediaMuxer, and by described Second wrapper is operated to the audio/video coding data execute encapsulation;
Before second wrapper stops encapsulation, first wrapper is restarted by the MediaMuxer.
2. according to the method described in claim 1, it is characterised in that before first wrapper stops encapsulation, pass through institute State MediaMuxer and start the second wrapper, including:
When current time, which reaches first, opens the moment in advance, second wrapper is started by the MediaMuxer;Wherein, institute State first it is pre- to open the moment be the first preset interval time relative to the lead at the first segmentation moment, the first segmentation moment is At the time of first wrapper stops encapsulation;
Before second wrapper stops encapsulation, first wrapper, bag are restarted by the MediaMuxer Include:
When current time, which reaches second, opens the moment in advance, first wrapper is restarted by the MediaMuxer;Its In, described second it is pre- to open the moment be the second preset interval time relative to the lead at the second segmentation moment, second segmentation At the time of moment is that second wrapper stops encapsulation.
3. method according to claim 2, it is characterised in that also include:
When reaching the first segmentation moment at current time, control first wrapper to stop encapsulation operation, and preserve the The video file that the encapsulation of one wrapper is obtained;
When reaching the second segmentation moment at current time, control second wrapper to stop encapsulation operation, and preserve the The video file that the encapsulation of two wrappers is obtained.
4. method according to claim 3, it is characterised in that also include:
At the described first segmentation moment and the second pre- any time opened between the moment, the MediaMuxer is in control institute State after the first wrapper stopping encapsulation operation, arrival described second was opened before the time in advance, in addition to:The MediaMuxer is released First wrapper is put, and re-creates first wrapper;
At the described second segmentation moment and the first pre- any time opened between the moment, the MediaMuxer releases are described Second wrapper, and re-create second wrapper.
5. method according to claim 2, it is characterised in that also include:
After the first wrapper is started, detect in the audio/video coding data whether there is key frame arrival, and in the key After frame arrives, the step of being operated described in execution by the first wrapper to the audio/video coding data execute encapsulation;
And/or, after the second wrapper is started, detect in the audio/video coding data whether there is key frame arrival, and in institute State after key frame arrival, the step of being operated described in execution by the second wrapper to the audio/video coding data execute encapsulation.
6. method according to claim 5, it is characterised in that also include:
According to the interval time of two neighboring key frame, determine first preset interval time and/or it is described second it is default between Every the time.
7. according to the method described in claim 1, it is characterised in that the first wrapper of the startup, including:First is created to record a video File, and the write-in decoding configuration data in first video file;
The second wrapper of the startup, including:The second video file is created, and decoding is write in second video file and is matched somebody with somebody Put data.
8. a kind of device that seamless video recording is realized in android system application layer, it is characterised in that including:Coding control unit With encapsulation control unit;
The coding control unit is used for, and preview video data and voice data are carried out by encoder interfaces MediaCodec Coding, obtains audio/video coding data;In the original video data that the preview video data collect for video acquisition device For carrying out the preview frame data that preview is shown on screen;
The encapsulation control unit is used for, and starts the first wrapper by wrapper interface MediaMuxer, and pass through described the One wrapper is operated to the audio/video coding data execute encapsulation;Before first wrapper stops encapsulation, pass through institute State MediaMuxer and start the second wrapper, and the audio/video coding data execute encapsulation is grasped by second wrapper Make;Before second wrapper stops encapsulation, first wrapper is restarted by the MediaMuxer.
9. device according to claim 8, it is characterised in that also include:
Key frame detection unit, for after the encapsulation control unit starts the first wrapper, detecting the audio/video coding Whether there is key frame arrival in data, and after key frame arrival, trigger and pass through described in the encapsulation control unit execution The step of first wrapper is operated to the audio/video coding data execute encapsulation;
And/or, for after the encapsulation control unit starts the second wrapper, detect in the audio/video coding data whether There is key frame arrival, and after key frame arrival, trigger and pass through second envelope described in the encapsulation control unit execution The step of dress device is operated to the audio/video coding data execute encapsulation.
10. a kind of terminal device, it is characterised in that including:Camera, Mike, processor and memory;In the memory It is stored with and is stored in the computer program that can be run on the memory and on the processor;The processor passes through pre- If interface is connected with the camera, Mike and memory;
The camera is used to gather video data;
The Mike is used to gather voice data;
The method any one of claim 1-7 is realized described in the computing device during computer program.
CN201710228016.1A 2017-04-10 2017-04-10 Method and device for realizing seamless video recording in application layer and terminal equipment Active CN106998449B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710228016.1A CN106998449B (en) 2017-04-10 2017-04-10 Method and device for realizing seamless video recording in application layer and terminal equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710228016.1A CN106998449B (en) 2017-04-10 2017-04-10 Method and device for realizing seamless video recording in application layer and terminal equipment

Publications (2)

Publication Number Publication Date
CN106998449A true CN106998449A (en) 2017-08-01
CN106998449B CN106998449B (en) 2020-02-04

Family

ID=59435574

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710228016.1A Active CN106998449B (en) 2017-04-10 2017-04-10 Method and device for realizing seamless video recording in application layer and terminal equipment

Country Status (1)

Country Link
CN (1) CN106998449B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107545618A (en) * 2017-09-07 2018-01-05 深圳市麦道微电子技术有限公司 The mechanism that a kind of seamless circulating in drive recorder is made video recording
CN111556351A (en) * 2020-05-15 2020-08-18 宁波菊风系统软件有限公司 RTP file playing system
CN112689108A (en) * 2020-12-22 2021-04-20 山东快课信息科技有限公司 System and method for recording and playing blackboard writing in sections based on key frames

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103842936A (en) * 2011-06-03 2014-06-04 迈克尔·爱德华·扎莱泰尔 Recording, editing and combining multiple live video clips and still photographs into a finished composition
CN105049919A (en) * 2015-07-27 2015-11-11 青岛海信移动通信技术股份有限公司 Method and device for recording multimedia file
CN105430312A (en) * 2015-11-27 2016-03-23 福州瑞芯微电子股份有限公司 Method and system for non-frame-loss segmented storage of video record based on Android system
CN106027935A (en) * 2016-07-13 2016-10-12 深圳市爱培科技术股份有限公司 Frame-missing-free segmental video-recording system and implementation method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103842936A (en) * 2011-06-03 2014-06-04 迈克尔·爱德华·扎莱泰尔 Recording, editing and combining multiple live video clips and still photographs into a finished composition
US9117483B2 (en) * 2011-06-03 2015-08-25 Michael Edward Zaletel Method and apparatus for dynamically recording, editing and combining multiple live video clips and still photographs into a finished composition
CN105049919A (en) * 2015-07-27 2015-11-11 青岛海信移动通信技术股份有限公司 Method and device for recording multimedia file
CN105430312A (en) * 2015-11-27 2016-03-23 福州瑞芯微电子股份有限公司 Method and system for non-frame-loss segmented storage of video record based on Android system
CN106027935A (en) * 2016-07-13 2016-10-12 深圳市爱培科技术股份有限公司 Frame-missing-free segmental video-recording system and implementation method

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107545618A (en) * 2017-09-07 2018-01-05 深圳市麦道微电子技术有限公司 The mechanism that a kind of seamless circulating in drive recorder is made video recording
CN111556351A (en) * 2020-05-15 2020-08-18 宁波菊风系统软件有限公司 RTP file playing system
CN111556351B (en) * 2020-05-15 2022-04-15 宁波菊风系统软件有限公司 RTP file playing system
CN112689108A (en) * 2020-12-22 2021-04-20 山东快课信息科技有限公司 System and method for recording and playing blackboard writing in sections based on key frames

Also Published As

Publication number Publication date
CN106998449B (en) 2020-02-04

Similar Documents

Publication Publication Date Title
US10229651B2 (en) Variable refresh rate video capture and playback
CN106998449A (en) Method, device and the terminal device of seamless video recording are realized in application layer
WO2021008373A1 (en) Display method and apparatus, electronic device, and computer-readable medium
CN108848406B (en) Method and device for recording multimedia file
JP2020507244A (en) Image smoothness improving method and apparatus
US7885514B2 (en) Apparatus and method for determining rendering duration of video frame
CN106937090A (en) The method and device of a kind of video storage
WO2021226535A1 (en) Multi-layer reprojection techniques for augmented reality
CN109240833A (en) Resource allocation method, device, terminal and storage medium
CN105263034A (en) Spot video advertisement playing method and device
CN113225605A (en) Video playing processing method and device, electronic equipment and storage medium
CN106331823B (en) A kind of video broadcasting method and device
CN114040251A (en) Audio and video playing method, system, storage medium and computer program product
CN103164227B (en) The acquisition method of a kind of video in window and device
EP3532919A1 (en) Method apparatus for dynamically reducing application render-to-on screen time in a desktop environment
CN113865620A (en) Time synchronization method and device for AR navigation simulation
CN109840058A (en) Cloud game collecting method and system
CN110139128A (en) A kind of information processing method, blocker, electronic equipment and storage medium
CN107135364A (en) In the native layers of method for realizing seamless video recording, device and terminal device
CN109213534A (en) A kind of method and device of extension live streaming software function
CN108712676B (en) Method and device for automatically playing video based on React framework
WO2005002198A2 (en) Video playback image processing
WO2019136849A1 (en) Method and system for achieving floating layer animation, storage medium, and electronic device
CN104243884B (en) Video recording method and video recording device
CN114071229B (en) Method for solving recovery delay when surface view renderer retransmits video for decoding

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP01 Change in the name or title of a patent holder

Address after: 266071 Shandong city of Qingdao province Jiangxi City Road No. 11

Patentee after: Qingdao Hisense Mobile Communication Technology Co.,Ltd.

Address before: 266071 Shandong city of Qingdao province Jiangxi City Road No. 11

Patentee before: HISENSE MOBILE COMMUNICATIONS TECHNOLOGY Co.,Ltd.

CP01 Change in the name or title of a patent holder