CN108650545B - Method and device for recording multimedia file - Google Patents

Method and device for recording multimedia file Download PDF

Info

Publication number
CN108650545B
CN108650545B CN201810646664.3A CN201810646664A CN108650545B CN 108650545 B CN108650545 B CN 108650545B CN 201810646664 A CN201810646664 A CN 201810646664A CN 108650545 B CN108650545 B CN 108650545B
Authority
CN
China
Prior art keywords
multimedia
writer
data
file
buffer queue
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.)
Active
Application number
CN201810646664.3A
Other languages
Chinese (zh)
Other versions
CN108650545A (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 CN201810646664.3A priority Critical patent/CN108650545B/en
Publication of CN108650545A publication Critical patent/CN108650545A/en
Application granted granted Critical
Publication of CN108650545B publication Critical patent/CN108650545B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/40Client devices specifically adapted for the reception of or interaction with content, e.g. set-top-box [STB]; Operations thereof
    • H04N21/43Processing of content or additional data, e.g. demultiplexing additional data from a digital video stream; Elementary client operations, e.g. monitoring of home network or synchronising decoder's clock; Client middleware
    • H04N21/433Content storage operation, e.g. storage operation in response to a pause request, caching operations
    • H04N21/4334Recording operations

Abstract

The embodiment of the invention provides a method and a device for recording a multimedia file, wherein the method comprises the following steps: when a recording request of a multimedia file is received, a data source, an encoder, a packer, a first multimedia writer and a second multimedia writer are created; continuously acquiring multimedia data through a data source; the encoder continuously encodes the multimedia data and writes the encoded multimedia data into a preset buffer queue; the first multimedia writer reads the encoded multimedia data from the buffer queue and writes the encoded multimedia data into a first multimedia file; judging whether the first multimedia file exceeds a preset file size threshold value or not; and if so, switching to a second multimedia writer to read the encoded multimedia data from the buffer queue and write the encoded multimedia data into a second multimedia file. The embodiment of the invention ensures continuous work during switching, avoids the blank of recording and realizes seamless continuous recording.

Description

Method and device for recording multimedia file
The application is a divisional application of Chinese patent application 201510447305.1 entitled "a method and apparatus for recording multimedia files" filed on 27.7.2015.
Technical Field
The present invention relates to the technical field of multimedia, and in particular, to a method and an apparatus for recording a multimedia file.
Background
In the field of video monitoring such as a vehicle data recorder and field monitoring, a long-time video recording is generally needed.
In the current video recording tool, due to the limitations of the file system and the computing platform, the upper limit of the size of the recorded video file needs to be set during recording, and a plurality of video files are used for continuously storing the recorded video.
However, when recording of a video file is completed, the video recording tool needs to be closed, and when recording of a video file is resumed, the video recording tool needs to be restarted, and when the video recording tool is started, operations such as initialization need to be performed.
Therefore, a long time is consumed in the video file switching process, recording cannot be performed in the switching process, a blank in monitoring time is caused, and the loss of video data in the monitoring field with strict requirements may have a serious problem.
Disclosure of Invention
In view of the above problems, embodiments of the present invention are provided to provide a method for recording a multimedia file and a corresponding apparatus for recording a multimedia file, which overcome the above problems.
In order to solve the above problem, an embodiment of the present invention discloses a method for recording a multimedia file, including:
when a recording request of a multimedia file is received, a data source, an encoder, a packer, a first multimedia writer and a second multimedia writer are created;
continuously acquiring multimedia data through a data source;
the encoder continuously encodes the multimedia data and writes the encoded multimedia data into a preset buffer queue;
the first multimedia writer reads the encoded multimedia data from the buffer queue and writes the encoded multimedia data into a first multimedia file;
judging whether the first multimedia file exceeds a preset file size threshold value or not; and if so, switching to a second multimedia writer to read the encoded multimedia data from the buffer queue and write the encoded multimedia data into a second multimedia file.
Preferably, the first multimedia writer comprises a first writer and a first packetizer, and the second multimedia writer comprises a second writer and a second packetizer.
Preferably, the step of reading the encoded multimedia data from the buffer queue by the first multimedia writer and writing the encoded multimedia data into the first multimedia file comprises:
the first packetizer reads the encoded multimedia data from the buffer queue;
the first packer packs the encoded multimedia data into multimedia data packets;
the first writer writes the multimedia data packet to a first multimedia file.
Preferably, the step of reading the multimedia data packet from the buffer queue by the first multimedia writer and writing the first multimedia file comprises:
when the first multimedia file exceeds a preset file size threshold, a first multimedia writer generates a packaging completion event;
the first multimedia writer broadcasts the encapsulation completion event.
Preferably, the step of determining whether the first multimedia file exceeds a preset file size threshold includes:
determining whether a package complete event broadcast by a first multimedia writer is received; if yes, the first multimedia file is judged to exceed a preset file size threshold value.
Preferably, the step of switching to the second multimedia writer to read the encoded multimedia data from the buffer queue and write the second multimedia file comprises:
stopping the first packetizer and the first writer, and simultaneously, storing the first multimedia by the first writer;
starting a second packer and a second writer;
the second packer reads the encoded multimedia data from the buffer queue;
the second packer packs the encoded multimedia data into multimedia data packets;
the second writer writes the multimedia data packet to a second multimedia file.
Preferably, the buffer queue is configured with a mutual exclusion lock, and the step of switching to a second multimedia writer to read the encoded multimedia data from the buffer queue includes:
the first packer releases the buffer queue;
the second packer locks the buffer queue;
and the second packer reads the encoded multimedia data from the buffer queue through a reading interface provided by the buffer queue.
Preferably, the data source comprises a camera and/or a microphone, and the multimedia data comprises video data and/or audio data;
the step of continuously acquiring multimedia data by the data source comprises:
acquiring video data from a camera through a preset camera source class CameraSource;
and/or the presence of a gas in the gas,
and audio data is collected from the microphone through a preset audio source type AudioSource.
The embodiment of the invention also discloses a method for recording the multimedia file, which comprises the following steps:
when a recording request of a multimedia file is received, a data source, an encoder, a packer, a first writer and a second writer are created;
continuously acquiring multimedia data through a data source;
the encoder continuously encodes the multimedia data;
the packer continuously packs the encoded multimedia data into multimedia data packets and writes the multimedia data packets into a preset buffer queue;
the first writer reads the multimedia data packet from the buffer queue and writes a first multimedia file;
judging whether the first multimedia file exceeds a preset file size threshold value or not; and if so, switching to a second writer to read the multimedia data packet from the buffer queue and write a second multimedia file.
Preferably, the step of writing the first multimedia file comprises:
when the first multimedia file exceeds a preset file size threshold, a first writer generates a packaging completion event;
the first writer broadcasts the package complete event.
Preferably, the step of determining whether the first multimedia file exceeds a preset file size threshold includes:
determining whether a package complete event broadcast by a first writer is received; if yes, the first multimedia file is judged to exceed a preset file size threshold value.
Preferably, the step of switching to the second writer to read the multimedia data packet from the buffer queue includes:
stopping the first writer, and simultaneously, storing the first multimedia by the first writer;
starting the second writer;
the second writer reads the multimedia data packet from the buffer queue.
Preferably, the buffer queue is configured with a mutual exclusion lock, and the step of switching to the second writer to read the multimedia data packet from the buffer queue includes:
the first writer releases the buffer queue;
locking the buffer queue by a second writer;
and the second writer reads the multimedia data packet from the buffer queue through a reading interface provided by the buffer queue.
Preferably, the data source comprises a camera and/or a microphone, and the multimedia data comprises video data and/or audio data;
the step of continuously acquiring multimedia data by the data source comprises:
acquiring video data from a camera through a preset camera source class CameraSource;
and/or the presence of a gas in the gas,
and audio data is collected from the microphone through a preset audio source type AudioSource.
The embodiment of the invention also discloses a device for recording the multimedia file, which comprises:
the recording tool creating module is used for creating a data source, an encoder, a packer, a first multimedia writer and a second multimedia writer when receiving a recording request of a multimedia file;
the multimedia data acquisition module is used for continuously acquiring multimedia data through a data source;
the encoding module is used for continuously encoding the multimedia data by an encoder and writing the encoded multimedia data into a preset buffer queue;
the first packaging module is used for reading the encoded multimedia data from the buffer queue by a first multimedia writer and writing the encoded multimedia data into a first multimedia file;
the file size judging module is used for judging whether the first multimedia file exceeds a preset file size threshold value or not; if so, calling a second packaging module;
and the second packaging module is used for switching to a second multimedia writer to read the encoded multimedia data from the buffer queue and write the encoded multimedia data into a second multimedia file.
Preferably, the first multimedia writer comprises a first writer and a first packetizer, and the second multimedia writer comprises a second writer and a second packetizer.
Preferably, the first package module includes:
the first reading submodule is used for reading the encoded multimedia data from the buffer queue by the first packetizer;
the first packetizer is used for packetizing the encoded multimedia data into multimedia data packets;
and the first writing submodule is used for writing the multimedia data packet into a first multimedia file by a first writer.
Preferably, the first package module includes:
the packaging completion event generation submodule is used for generating a packaging completion event by the first multimedia writer when the first multimedia file exceeds a preset file size threshold;
and the encapsulation completion event broadcasting sub-module is used for broadcasting the encapsulation completion event by the first multimedia writer.
Preferably, the file size determining module includes:
an encapsulation completion event judgment sub-module for judging whether an encapsulation completion event broadcasted by the first multimedia writer is received; if yes, calling an encapsulation completion judgment submodule;
and the packaging completion judgment submodule is used for judging that the first multimedia file exceeds a preset file size threshold.
Preferably, the second package module includes:
the stopping submodule is used for stopping the first packetizer and the first writer, and meanwhile, the first writer performs storage processing on the first multimedia;
the starting submodule is used for starting the second packer and the second writer;
the second reading submodule is used for reading the encoded multimedia data from the buffer queue by a second packer;
the second packing submodule is used for packing the encoded multimedia data into a multimedia data packet by a second packer;
and the second writing submodule is used for writing the multimedia data packet into a second multimedia file by a second writer.
Preferably, the cache queue is configured with a mutual exclusion lock, and the second encapsulation module includes:
the releasing submodule is used for releasing the cache queue by the first packetizer;
a locking submodule, configured to lock the cache queue by a second packer;
and the interface reading submodule is used for reading the encoded multimedia data from the buffer queue through a reading interface provided by the buffer queue by the second packer.
Preferably, the data source may include a camera and/or a microphone, and the multimedia data may include video data and/or audio data;
the multimedia data acquisition module comprises:
the video data acquisition submodule is used for acquiring video data from the camera through a preset camera source class CameraSource;
and/or the presence of a gas in the gas,
and the audio data acquisition sub-module is used for acquiring audio data from the microphone through a preset audio source type AudioSource.
The embodiment of the invention also discloses a device for recording the multimedia file, which comprises:
the recording tool creating module is used for creating a data source, an encoder, a packer, a first writer and a second writer when receiving a recording request of a multimedia file;
the multimedia data acquisition module is used for continuously acquiring multimedia data through a data source;
an encoding module for continuously encoding the multimedia data by an encoder;
the packaging module is used for continuously packaging the encoded multimedia data into multimedia data packets by the packager and writing the multimedia data packets into a preset buffer queue;
the first packaging module is used for reading the multimedia data packet from the cache queue by a first writer and writing a first multimedia file;
the file size judging module is used for judging whether the first multimedia file exceeds a preset file size threshold value or not; if so, calling a second packaging module;
and the second packaging module is used for switching to a second writer to read the multimedia data packet from the buffer queue and write a second multimedia file.
Preferably, the first package module includes:
the packaging completion event generation submodule is used for generating a packaging completion event by the first writer when the first multimedia file exceeds a preset file size threshold;
and the packaging completion event broadcasting submodule is used for broadcasting the packaging completion event by the first writer.
Preferably, the file size determining module includes:
a packaging completion event judgment sub-module for judging whether a packaging completion event broadcasted by the first writer is received; if yes, calling an encapsulation completion judgment submodule;
and the packaging completion judgment submodule is used for judging that the first multimedia file exceeds a preset file size threshold.
Preferably, the second package module includes:
the stopping submodule is used for stopping the first writer, and meanwhile, the first writer performs storage processing on the first multimedia;
the starting submodule is used for starting the second writer;
and the second reading submodule is used for reading the multimedia data packet from the buffer queue by a second writer.
Preferably, the cache queue is configured with a mutual exclusion lock, and the second encapsulation module includes:
a releasing submodule, configured to release the cache queue by a first writer;
a locking submodule for locking the cache queue by a second writer;
and the interface reading submodule is used for reading the multimedia data packet from the buffer queue through a reading interface provided by the buffer queue by a second writer.
Preferably, the data source may include a camera and/or a microphone, and the multimedia data may include video data and/or audio data;
the multimedia data acquisition module comprises:
the video data acquisition submodule is used for acquiring video data from the camera through a preset camera source class CameraSource;
and/or the presence of a gas in the gas,
and the audio data acquisition sub-module is used for acquiring audio data from the microphone through a preset audio source type AudioSource.
The embodiment of the invention has the following advantages:
the embodiment of the invention is provided with two multimedia writers, multimedia data continuously acquired by a data source are continuously coded and stored in a cache queue, when a first multimedia writer finishes packaging a first multimedia file, the first multimedia writer is switched to a second multimedia writer to package a second multimedia file, and in the switching process, recording tools such as the data source and an encoder can continuously and normally work, so that the closing of the recording tools such as the data source and the encoder during switching is avoided, the initialization operation of the recording tools such as the data source and the encoder after switching is further avoided, the continuous work during switching is ensured, the blank of recording is avoided, and the seamless continuous recording is realized.
The multiplexing encoder in the embodiment of the invention has the advantages that the switching process of the first multimedia writer and the second multimedia writer is transparent to a data source and the encoder, and the data synchronization of the first multimedia writer and the second multimedia writer during switching is ensured through the buffer queue protected by the mutual exclusion lock.
The embodiment of the invention is provided with two writers, multimedia data continuously acquired by a data source are continuously coded and packaged and stored in a cache queue, when a first multimedia file is packaged by a first writer and is nearly finished, the first writer is switched to a second writer to package a second multimedia file, and in the switching process, recording tools such as the data source, an encoder and a packager can continuously and normally work, so that the closing of the recording tools such as the data source, the encoder and the packager during switching is avoided, further, the initialization operation of the recording tools such as the data source, the encoder and the packager after switching is avoided, the continuous work during switching is ensured, the blank of recording is avoided, and the seamless continuous recording is realized.
The multiplexing packer of the embodiment of the invention has the advantages that the switching process of the first writer and the second writer is transparent to a data source, an encoder and the packer, and the data synchronization of the first writer and the second writer during switching is ensured through the buffer queue protected by the mutual exclusion lock.
Drawings
Fig. 1 is a flowchart of the steps of an embodiment 1 of a method for recording a multimedia file according to the present invention;
fig. 2 is a flowchart illustrating steps of an embodiment 2 of a method for recording a multimedia file according to the present invention;
FIG. 3 is a block diagram of a multimedia file recording apparatus 1 according to an embodiment of the present invention
Fig. 4 is a block diagram of a multimedia file recording apparatus according to embodiment 2 of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in further detail below.
Referring to fig. 1, a flowchart illustrating steps of an embodiment of a method for recording a multimedia file according to the present invention is shown, which may specifically include the following steps:
step 101, when a recording request of a multimedia file is received, a data source, an encoder, a packer, a first multimedia writer and a second multimedia writer are created;
it should be noted that the embodiments of the present invention can be applied to an electronic device with a camera, for example, a mobile phone, a tablet computer, a smart wearable device (such as a smart watch and smart glasses), a car recorder, a video monitor, and the like.
Most of the electronic devices can support operating systems such as Windows phone, Android (Android), IOS, Windows, and the like, and can generally run video recording applications such as camera applications to realize a video recording function.
In order to enable a person skilled in the art to better understand the embodiment of the present invention, in the embodiment of the present invention, Android is described as an example of an operating system.
Android is a Linux-based operating system with free and open source codes, which can be roughly divided into four layers, from the upper layer to the lower layer, an Application layer (Applications), an Application Framework layer (Application Framework), a system runtime layer (Libraries), and a Linux Kernel layer (Linux).
Furthermore, in the Android system, a Java virtual machine Dalvik is added to the Linux system, a Java Application Framework is built on the Dalvik virtual machine, and an Application program runs on the Java-based Application Framework, so that the Application Framework can be roughly divided into a Java layer and a Native layer.
In a specific implementation, the recording request of the multimedia file may refer to an instruction for recording, which is sent by a user by clicking a designated control (e.g., a recording start control) through a camera application.
Upon receiving a recording request for a multimedia file, a multimedia recording object MediaRecorder may be created, the multimedia recording object MediaRecorder object creates a multimedia recording service instance stagefight recorder, the stagefight recorder creates a data source DataSource, an encoder Codec, a first multimedia writer MediaWriter, a second multimedia writer MediaWriter, i.e. a multimedia recording service instance stagefight recorder, which may play the role of Controller, based on settings (e.g. encoding format) and control messages received from an application recording the video, completing the creation and setting of the recording tool.
Specifically, the application for recording video can create a MediaRecorder object in a Java layer to realize recording and video.
The MediaRecorder object is a stagefright recorder, which creates a recording service instance by the recording service module MPS of the application framework layer, controlling the recording of multimedia files.
Wherein, the stagefrightRecorder is an entity object created by MPS for recording operation.
The video recording application and the MPS realize inter-process communication through an AIDL interface, and the Android system provides packaged help for the convenience of camera application development.
Applications such as recording video communicate with the MPS via the MediaRecorder object and the MediaRecorderClient.
The MediaRecorder object is an application running in the process space of the video recording application representing the MPS, and the MediaRecorder client runs in the multimedia server process space representing the video recording.
It should be noted that, in order to implement the hot backup mechanism, in the embodiment of the present invention, the control logic of the Controller may be modified at the Native layer, a media writer, MediaWriter, is added, and the control parameter for continuous recording is added at the Java layer.
Wherein the first multimedia writer MediaWriter and the second multimedia writer MediaWriter are working multimedia writers mediawriters and backup multimedia writers mediawriters.
In an embodiment of the present invention, the first multimedia writer MediaWriter may be a working multimedia writer MediaWriter, and the second multimedia writer MediaWriter may be a backup multimedia writer MediaWriter.
The Android native multimedia recording framework simplifies the design of the packer and the Writer, and combines the functions of the packer and the Writer into one multimedia Writer, namely the MediaWriter.
That is, in the embodiment of the present invention, the first multimedia Writer MediaWriter may include a first Writer and a first Packetizer, and the second multimedia Writer MediaWriter may include a second Writer and a second Packetizer, so that the first Packetizer multiplexes the encoder Codec with the second Packetizer.
Step 102, continuously acquiring multimedia data through a data source;
in a specific implementation, the data source data may include a Camera and/or a microphone MIC, and the multimedia data may include video data and/or audio data;
in the embodiment of the present invention, video data, such as YUV data, may be collected from the Camera through a preset Camera source class Camera resource;
and/or the presence of a gas in the gas,
audio data, such as PCM data, may be collected from the microphone MIC via a preset audio source class AudioSource.
103, continuously encoding the multimedia data by an encoder, and writing the encoded multimedia data into a preset buffer queue;
the transmission process of the recorded multimedia data is message-driven, and the message of the multimedia data generated by the data source is injected into the message queue of the encoder Codec.
After detecting the message, the encoder Codec may call a read function of a MediaSource (a data source type of an Android platform) to obtain video data and audio data, and encode the video data and the audio data according to a set encoding format, so as to compress the video data and the audio data into data of various encoding formats.
The encoding of multimedia data refers to a method of converting a file in a certain video format into a file in another video format by using a specific compression technology, such as h.261, h.263, h.264, and the like.
The encoder Codec may store the encoded multimedia data in an internal buffer queue.
Specifically, the buffer queue provides a write interface (put) and a read interface (read) for the external object, and the encoder Codec can call the write interface (put) to write the encoded multimedia data into the buffer queue.
104, reading the encoded multimedia data from the buffer queue by a first multimedia writer, and writing the encoded multimedia data into a first multimedia file;
in a specific implementation, the working first multimedia writer MediaWriter may call a read interface (read) of the buffer queue, read the encoded multimedia data from the buffer queue, and package the first multimedia file according to a set output format (e.g., MP4, 3GP, etc.).
In a preferred embodiment of the present invention, step 104 may comprise the following sub-steps:
sub-step S11, the first packetizer reads the encoded multimedia data from the buffer queue;
a sub-step S12, packing the encoded multimedia data into multimedia data packets by the first packer;
a substep S13, writing the multimedia data packet into a first multimedia file by a first writer;
a substep S14, when the first multimedia file exceeds a preset file size threshold, the first multimedia writer generates a package complete event;
in sub-step S15, the first multimedia writer broadcasts the package complete event.
The first packer reads the code stream output by the encoder Codec and is responsible for partitioning and packing the code stream output by the encoder Codec so as to facilitate storage or transmission.
The first Writer, Writer, writes the multimedia data packet of the first Packetizer Packetizer Packetizer number into a first multimedia file.
If the first Writer Writer detects that the first multimedia file exceeds the file size threshold, a package completion event can be generated and broadcasted to the Controller to inform the Controller that the package of the first multimedia file is nearly completed.
Step 105, judging whether the first multimedia file exceeds a preset file size threshold value; if yes, go to step 106;
in a specific implementation, the Controller may determine whether a package complete event broadcast by a first multimedia writer, MediaWriter, is received; if yes, the first multimedia file is judged to exceed a preset file size threshold value.
And 106, switching to a second multimedia writer to read the encoded multimedia data from the buffer queue and write the encoded multimedia data into a second multimedia file.
The embodiment of the invention applies a hot backup mechanism, and if the Controller learns that the first multimedia file exceeds the preset file size threshold value, namely the encapsulation is close to completion, the Controller can be switched to a second multimedia writer, namely the MediaWriter, to encapsulate the second multimedia file.
When switching to the second multimedia writer MediaWriter for packaging, the second multimedia writer MediaWriter switches from the backup multimedia writer MediaWriter to the working multimedia writer MediaWriter, and the first multimedia writer MediaWriter switches from the working multimedia writer MediaWriter to the backup multimedia writer MediaWriter.
In a preferred embodiment of the present invention, step 106 may comprise the following sub-steps:
a substep S21, stopping the first packetizer and the first writer, and simultaneously, performing a saving process on the first multimedia by the first writer;
substep S22, starting a second packer and a second writer;
sub-step S23, the second packer reads the encoded multimedia data from the buffer queue;
a sub-step S24, packing the encoded multimedia data into multimedia data packets by the second packer;
in sub-step S25, the second writer writes the multimedia data packet to a second multimedia file.
The first packer, the first Writer, the second packer, and the second Writer have a thread of work.
The first multimedia Writer MediaWriter is switched to a standby state by closing the first Packetizer, the thread in which the first Writer writers works, stopping the work of the first Writer.
The second multimedia Writer MediaWriter is switched to a working state by starting the second packer, the thread in which the second Writer works, and starting the work of the second Writer.
And the second packer continues to read the code stream output by the encoder Codec, and is responsible for partitioning and packing the code stream output by the encoder Codec so as to facilitate storage or transmission.
And the second Writer Writer writes the multimedia data packet packed by the second packer into a second multimedia file.
Of course, if the second Writer detects that the second multimedia file exceeds the file size threshold, a package completion event may be generated, broadcasted to the Controller, and notifies the Controller that the package of the second multimedia file is nearly completed, and the first multimedia Writer MediaWriter is switched again to continue the package.
Specifically, the Controller sends a stop message to the first Packetizer and the first Writer, and when the first Packetizer and the first Writer receive the stop message, the first Packetizer and the first Writer may close the thread in which the first Packetizer and the first Writer work, and at the same time, the first Writer performs saving processing on the first multimedia, which generally includes writing of a first multimedia file, saving of header information, and file closing.
The header information may include encoded information and the like for subsequent playing.
The Controller sends a start message to the second packer and the second Writer, and when the second packer and the second Writer receive the start message, the Controller may start the thread in which the second packer and the second Writer work.
It should be noted that, the embodiment of the present invention may modify the stagefight recorder framework, when switching the multimedia writers mediawriters, i.e. closing one of the multimedia writers mediawriters and starting the other multimedia writer mediawriters, the operation of the other recording tools (i.e. data source, encoder Codec) is not stopped, and after the other multimedia writer mediawriters are started, the output information of the encoder Codec may be normally monitored.
Of course, if the recording end indication is monitored, for example, the user clicks a designated control (e.g., a recording end control) through the camera application, the operation of all recording tools may be stopped, that is, the Controller may send a message to notify the data source DataSource, the encoder Codec, and the working multimedia writer MediaWriter to stop operating.
In another preferred embodiment of the present invention, the cache queue is configured with a mutual exclusion lock to protect the cache queue.
Specifically, the mutex lock can provide a mutually exclusive method, and by means of locking and unlocking of threads, for a certain data structure, it is ensured that only one thread can access the mutex lock at a certain time, that is, two threads cannot lock the same mutex object at the same time.
If thread a attempts to lock a mutex object, while thread b has locked the same mutex object, thread a will go to sleep.
Once thread b releases the mutex object (which may be called by pthread _ mutex _ unlock ()), thread a can lock the mutex object (i.e., thread a may return from the pthread _ mutex _ lock () function call while the mutex object is locked).
Similarly, while thread a is locking a mutex object, thread c will also temporarily enter a sleep state if thread c attempts to lock the mutex object.
All threads that are locked on a locked mutex object (that can call the pthread _ mutex _ lock () function call) will enter a sleep state and these sleeping threads will "queue" access to this mutex object.
Then in an embodiment of the present invention, step 106 may comprise the following sub-steps:
substep S31, the first packer releases the buffer queue;
substep S32, the second packer locks the buffer queue;
and in sub-step S33, the second packer reads the encoded multimedia data from the buffer queue through the read interface provided by the buffer queue.
In the embodiment of the invention, the buffer queue is protected as a mutual exclusion object, the thread of the first packer cannot read the encoded multimedia data from the buffer queue if the thread of the first packer releases the buffer queue, and the thread of the second packer locks the buffer queue and can read the encoded multimedia data from the buffer queue.
The consumer of the multimedia data after being encoded by the encoder Codec, i.e. the packer packetzer (including the first packer packetzer and the second packer packetzer), provides an implementation of a read data interface (read), i.e. a read request read is mapped onto a read interface (get) of the cache queue.
In this way, a read request issued by any one of the packers (including the first packer and the second packer) can be correctly responded.
The multiplexing encoder in the embodiment of the invention has the advantages that the switching process of the first multimedia writer and the second multimedia writer is transparent to a data source and the encoder, and the data synchronization of the first multimedia writer and the second multimedia writer during switching is ensured through the buffer queue protected by the mutual exclusion lock.
The embodiment of the invention is provided with two multimedia writers, multimedia data continuously acquired by a data source are continuously coded and stored in a cache queue, when a first multimedia writer finishes packaging a first multimedia file, the first multimedia writer is switched to a second multimedia writer to package a second multimedia file, and in the switching process, recording tools such as the data source and an encoder can continuously and normally work, so that the closing of the recording tools such as the data source and the encoder during switching is avoided, the initialization operation of the recording tools such as the data source and the encoder after switching is further avoided, the continuous work during switching is ensured, the blank of recording is avoided, and the seamless continuous recording is realized.
Referring to fig. 2, a flowchart illustrating steps of embodiment 2 of a method for recording a multimedia file according to the present invention is shown, which may specifically include the following steps:
step 201, when a recording request of a multimedia file is received, a data source, an encoder, a packer, a first writer and a second writer are created;
it should be noted that the embodiments of the present invention can be applied to an electronic device with a camera, for example, a mobile phone, a tablet computer, a smart wearable device (such as a smart watch and smart glasses), a car recorder, a video monitor, and the like.
Most of the electronic devices can support operating systems such as Windows phone, Android (Android), IOS, Windows, and the like, and can generally run video recording applications such as camera applications to realize a video recording function.
In order to enable a person skilled in the art to better understand the embodiment of the present invention, in the embodiment of the present invention, Android is described as an example of an operating system.
Android is a Linux-based operating system with free and open source codes, which can be roughly divided into four layers, from the upper layer to the lower layer, an Application layer (Applications), an Application Framework layer (Application Framework), a system runtime layer (Libraries), and a Linux Kernel layer (Linux).
Furthermore, in the Android system, a Java virtual machine Dalvik is added to the Linux system, a Java Application Framework is built on the Dalvik virtual machine, and an Application program runs on the Java-based Application Framework, so that the Application Framework can be roughly divided into a Java layer and a Native layer.
In a specific implementation, the recording request of the multimedia file may refer to an instruction for recording, which is sent by a user by clicking a designated control (e.g., a recording start control) through a camera application.
Upon receiving a recording request for a multimedia file, a multimedia recording object MediaRecorder may be created, the multimedia recording object MediaRecorder object creates a multimedia recording service instance stagefight recorder, the stagefight recorder creates a data source DataSource, an encoder Codec, a first multimedia writer MediaWriter, a second multimedia writer MediaWriter, i.e. a multimedia recording service instance stagefight recorder, which may play the role of Controller, based on settings (e.g. encoding format) and control messages received from an application recording the video, completing the creation and setting of the recording tool.
Specifically, the application for recording video can create a MediaRecorder object in a Java layer to realize recording and video.
The MediaRecorder object is a stagefright recorder, which creates a recording service instance by the recording service module MPS of the application framework layer, controlling the recording of multimedia files.
Wherein, the stagefrightRecorder is an entity object created by MPS for recording operation.
The video recording application and the MPS realize inter-process communication through an AIDL interface, and the Android system provides packaged help for the convenience of camera application development.
Applications such as recording video communicate with the MPS via the MediaRecorder object and the MediaRecorderClient.
The MediaRecorder object is an application running in the process space of the video recording application representing the MPS, and the MediaRecorder client runs in the multimedia server process space representing the video recording.
It should be noted that, in order to implement the hot backup mechanism, in the embodiment of the present invention, the control logic of the Controller may be modified at the Native layer, a media writer, MediaWriter, is added, and the control parameter for continuous recording is added at the Java layer.
Wherein the first multimedia writer MediaWriter and the second multimedia writer MediaWriter are working multimedia writers mediawriters and backup multimedia writers mediawriters.
In an embodiment of the present invention, the first multimedia writer MediaWriter may be a working multimedia writer MediaWriter, and the second multimedia writer MediaWriter may be a backup multimedia writer MediaWriter.
The Android native multimedia recording framework simplifies the design of the packer and the Writer, and combines the functions of the packer and the Writer into one multimedia Writer, namely the MediaWriter.
That is, in the embodiment of the present invention, the first multimedia Writer MediaWriter may include a first Writer and a packer, the second multimedia Writer MediaWriter may include a second Writer and a packer, and then the first Writer multiplexes the packer with the second Writer.
Step 202, continuously collecting multimedia data through a data source;
in a specific implementation, the data source data may include a Camera and/or a microphone MIC, and the multimedia data may include video data and/or audio data;
in the embodiment of the present invention, video data, such as YUV data, may be collected from the Camera through a preset Camera source class Camera resource;
and/or the presence of a gas in the gas,
audio data, such as PCM data, may be collected from the microphone MIC via a preset audio source class AudioSource.
Step 203, the encoder continuously encodes the multimedia data;
the transmission process of the recorded multimedia data is message-driven, and the message of the multimedia data generated by the data source is injected into the message queue of the encoder Codec.
After detecting the message, the encoder Codec may call a read function of a MediaSource (a data source type of an Android platform) to obtain video data and audio data, and encode the video data and the audio data according to a set encoding format, so as to compress the video data and the audio data into data of various encoding formats.
The encoding of multimedia data refers to a method of converting a file in a certain video format into a file in another video format by using a specific compression technology, such as h.261, h.263, h.264, and the like.
Step 204, the packer continuously packs the encoded multimedia data into multimedia data packets and writes the multimedia data packets into a preset buffer queue;
the packer reads the code stream output by the encoder Codec, and is responsible for dividing and packing the code stream output by the encoder Codec for storage or transmission.
The packer packetzer may store the packed multimedia data packets in an internal buffer queue.
Specifically, the cache queue provides a write interface (put) and a read interface (read) for the external object, and the packer can call the write interface (put) to write the packed multimedia data packet into the cache queue.
Step 205, the first writer reads the multimedia data packet from the buffer queue and writes the multimedia data packet into a first multimedia file;
in a specific implementation, the working first Writer may call a read interface (read) of the buffer queue, read the multimedia data packet from the buffer queue, and encapsulate the first multimedia file.
In a preferred embodiment of the present invention, step 205 may comprise the following sub-steps:
a substep S41, when the first multimedia file exceeds a preset file size threshold, the first writer generates a package complete event;
in sub-step S42, the first writer broadcasts the package complete event.
In this embodiment of the present invention, if the first Writer detects that the first multimedia file exceeds the file size threshold, a package complete event may be generated and broadcast to the Controller, which notifies the Controller that the package of the first multimedia file is nearly completed.
Step 206, judging whether the first multimedia file exceeds a preset file size threshold value; if yes, go to step 207;
in a specific implementation, the Controller may determine whether a package complete event broadcast by the first Writer is received; if yes, the first multimedia file is judged to exceed a preset file size threshold value.
Step 207, switching to a second writer to read the multimedia data packet from the buffer queue, and writing the multimedia data packet into a second multimedia file.
The embodiment of the invention applies a hot backup mechanism, and if the Controller learns that the first multimedia file exceeds the preset file size threshold value, namely the encapsulation is close to completion, the Controller can switch to the second Writer Writer to encapsulate the second multimedia file.
When switching to the second Writer for packaging, the second Writer is switched from the backup Writer to the working Writer, and the first Writer is switched from the working Writer to the backup Writer.
In a preferred embodiment of the present invention, step 207 may comprise the following sub-steps:
a substep S51, stopping the first writer, and simultaneously, the first writer performs a saving process on the first multimedia;
a substep S52 of starting the second writer;
in sub-step S53, the second writer reads the multimedia data packet from the buffer queue.
Both the first Writer and the second Writer have a thread of operation.
The first Writer is switched to the standby state by closing the thread in which the first Writer works, stopping the work of the first Writer.
The second Writer MediaWriter is switched to the operating state by starting the thread in which the second Writer works, starting the work of the second Writer.
And the second Writer Writer continuously reads the multimedia data packet packaged by the packer from the buffer queue and writes the multimedia data packet into a second multimedia file.
Of course, if the second Writer detects that the second multimedia file exceeds the file size threshold, a package completion event may be generated, broadcasted to the Controller, and notifies the Controller that the package of the second multimedia file is nearly completed, and the first Writer is switched again to continue packaging.
Specifically, the Controller sends a stop message to the first Writer, and when the first Writer receives the stop message, the thread in which the first Writer writes may be closed, and at the same time, the first Writer performs a saving process on the first multimedia, which generally includes writing of the first multimedia file, saving of header information, and file closing.
The header information may include encoded information and the like for subsequent playing.
The Controller sends a start message to the second Writer, which when it receives the start message, can start the thread in which the second Writer works.
It should be noted that, the embodiment of the present invention may modify the stagefight recorder framework, when switching of the Writer writers is performed, that is, when one of the Writer writers is turned off and the other Writer is turned on, the operation of the other recording tools (that is, the data source, the encoder Codec and the packer) is not stopped, and after the other Writer is turned on, the output information of the packer can be normally monitored.
Of course, if the recording end indication is monitored, for example, the user clicks a designated control (e.g., a recording end control) through the camera application, the operation of all recording tools may be stopped, that is, the Controller may send a message to notify the data source DataSource, the encoder Codec, and the working multimedia writer MediaWriter to stop operating.
In another preferred embodiment of the present invention, the cache queue is configured with a mutual exclusion lock to protect the cache queue.
Specifically, the mutex lock can provide a mutually exclusive method, and by means of locking and unlocking of threads, for a certain data structure, it is ensured that only one thread can access the mutex lock at a certain time, that is, two threads cannot lock the same mutex object at the same time.
If thread a attempts to lock a mutex object, while thread b has locked the same mutex object, thread a will go to sleep.
Once thread b releases the mutex object (which may be called by pthread _ mutex _ unlock ()), thread a can lock the mutex object (i.e., thread a may return from the pthread _ mutex _ lock () function call while the mutex object is locked).
Similarly, while thread a is locking a mutex object, thread c will also temporarily enter a sleep state if thread c attempts to lock the mutex object.
All threads that are locked on a locked mutex object (that can call the pthread _ mutex _ lock () function call) will enter a sleep state and these sleeping threads will "queue" access to this mutex object.
Then in an embodiment of the present invention, step 207 may comprise the following sub-steps:
substep S61, the first writer releases the buffer queue;
substep S62, the second writer locks the buffer queue;
in sub-step S63, the second writer reads the multimedia data packet from the buffer queue through the read interface provided by the buffer queue.
In the embodiment of the present invention, the buffer queue is protected as a mutex object, the thread of the first Writer releases the buffer queue, and the multimedia data packet cannot be read from the buffer queue, and the thread of the second Writer locks the buffer queue, and the multimedia data packet can be read from the buffer queue.
The packager packer provides an implementation of a read data interface (read) to its consumer of multimedia data packets, i.e., Writer writers (including first Writer writers and second Writer writers), i.e., maps read requests onto read interfaces (gets) of a buffer queue.
Thus, a read request read can be correctly responded to regardless of which Writer (including the first Writer and the second Writer) issues.
The multiplexing packer of the embodiment of the invention has the advantages that the switching process of the first writer and the second writer is transparent to a data source, an encoder and the packer, and the data synchronization of the first writer and the second writer during switching is ensured through the buffer queue protected by the mutual exclusion lock.
The embodiment of the invention is provided with two writers, multimedia data continuously acquired by a data source are continuously coded and packaged and stored in a cache queue, when a first multimedia file is packaged by a first writer and is nearly finished, the first writer is switched to a second writer to package a second multimedia file, and in the switching process, recording tools such as the data source, an encoder and a packager can continuously and normally work, so that the closing of the recording tools such as the data source, the encoder and the packager during switching is avoided, further, the initialization operation of the recording tools such as the data source, the encoder and the packager after switching is avoided, the continuous work during switching is ensured, the blank of recording is avoided, and the seamless continuous recording is realized.
It should be noted that, for simplicity of description, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present invention is not limited by the illustrated order of acts, as some steps may occur in other orders or concurrently in accordance with the embodiments of the present invention. Further, those skilled in the art will appreciate that the embodiments described in the specification are presently preferred and that no particular act is required to implement the invention.
Referring to fig. 3, a block diagram of a multimedia file recording apparatus in embodiment 1 of the present invention is shown, which may specifically include the following modules:
a recording tool creating module 301, configured to create a data source, an encoder, a packer, a first multimedia writer, and a second multimedia writer when receiving a recording request of a multimedia file;
a multimedia data acquisition module 302, configured to continuously acquire multimedia data through a data source;
an encoding module 303, configured to continuously encode the multimedia data by an encoder, and write the encoded multimedia data into a preset buffer queue;
a first encapsulation module 304, configured to read the encoded multimedia data from the buffer queue by a first multimedia writer, and write a first multimedia file;
a file size determining module 305, configured to determine whether the first multimedia file exceeds a preset file size threshold; if so, the second encapsulation module 306 is invoked;
and the second encapsulation module 306 is configured to switch to a second multimedia writer to read the encoded multimedia data from the buffer queue and write the encoded multimedia data into a second multimedia file.
In a particular implementation, the first multimedia writer includes a first writer and a first packetizer, and the second multimedia writer includes a second writer and a second packetizer.
In a preferred embodiment of the present invention, the first packaging module 304 may include the following sub-modules:
the first reading submodule is used for reading the encoded multimedia data from the buffer queue by the first packetizer;
the first packetizer is used for packetizing the encoded multimedia data into multimedia data packets;
and the first writing submodule is used for writing the multimedia data packet into a first multimedia file by a first writer.
In another preferred embodiment of the present invention, the first packaging module 304 may include the following sub-modules:
the packaging completion event generation submodule is used for generating a packaging completion event by the first multimedia writer when the first multimedia file exceeds a preset file size threshold;
and the encapsulation completion event broadcasting sub-module is used for broadcasting the encapsulation completion event by the first multimedia writer.
In a preferred embodiment of the present invention, the file size determining module 305 may include the following sub-modules:
an encapsulation completion event judgment sub-module for judging whether an encapsulation completion event broadcasted by the first multimedia writer is received; if yes, calling an encapsulation completion judgment submodule;
and the packaging completion judgment submodule is used for judging that the first multimedia file exceeds a preset file size threshold.
In a preferred embodiment of the present invention, the second packaging module 306 may include the following sub-modules:
the stopping submodule is used for stopping the first packetizer and the first writer, and meanwhile, the first writer performs storage processing on the first multimedia;
the starting submodule is used for starting the second packer and the second writer;
the second reading submodule is used for reading the encoded multimedia data from the buffer queue by a second packer;
the second packing submodule is used for packing the encoded multimedia data into a multimedia data packet by a second packer;
and the second writing submodule is used for writing the multimedia data packet into a second multimedia file by a second writer.
In another preferred embodiment of the present invention, the cache queue is configured with a mutex lock, and the second encapsulating module 306 may include the following sub-modules:
the releasing submodule is used for releasing the cache queue by the first packetizer;
a locking submodule, configured to lock the cache queue by a second packer;
and the interface reading submodule is used for reading the encoded multimedia data from the buffer queue through a reading interface provided by the buffer queue by the second packer.
In a preferred example of the embodiment of the present invention, the data source may include a camera and/or a microphone, and the multimedia data may include video data and/or audio data;
the multimedia data acquisition module 302 may include the following sub-modules:
the video data acquisition submodule is used for acquiring video data from the camera through a preset camera source class CameraSource;
and/or the presence of a gas in the gas,
and the audio data acquisition sub-module is used for acquiring audio data from the microphone through a preset audio source type AudioSource.
Referring to fig. 4, a block diagram of a multimedia file recording apparatus in embodiment 2 of the present invention is shown, which may specifically include the following modules:
a recording tool creating module 401, configured to create a data source, an encoder, a packer, a first writer, and a second writer when receiving a recording request of a multimedia file;
a multimedia data collection module 402 for continuously collecting multimedia data through a data source;
an encoding module 403 for continuously encoding the multimedia data by an encoder;
a packing module 404, configured to pack, by a packer, the encoded multimedia data into a multimedia data packet, and write the multimedia data packet into a preset buffer queue;
a first encapsulation module 405, configured to read a multimedia data packet from the buffer queue by a first writer, and write a first multimedia file;
a file size determining module 406, configured to determine whether the first multimedia file exceeds a preset file size threshold; if so, the second encapsulation module 406 is invoked;
and the second encapsulation module 407 is configured to switch to a second writer to read the multimedia data packet from the buffer queue and write a second multimedia file.
In a preferred embodiment of the present invention, the first packaging module 405 may include the following sub-modules:
the packaging completion event generation submodule is used for generating a packaging completion event by the first writer when the first multimedia file exceeds a preset file size threshold;
and the packaging completion event broadcasting submodule is used for broadcasting the packaging completion event by the first writer.
In a preferred embodiment of the present invention, the file size determining module 406 may include the following sub-modules:
a packaging completion event judgment sub-module for judging whether a packaging completion event broadcasted by the first writer is received; if yes, calling an encapsulation completion judgment submodule;
and the packaging completion judgment submodule is used for judging that the first multimedia file exceeds a preset file size threshold.
In a preferred embodiment of the present invention, the second packaging module 407 may include the following sub-modules:
the stopping submodule is used for stopping the first writer, and meanwhile, the first writer performs storage processing on the first multimedia;
the starting submodule is used for starting the second writer;
and the second reading submodule is used for reading the multimedia data packet from the buffer queue by a second writer.
In another preferred embodiment of the present invention, the cache queue is configured with a mutex lock, and the second encapsulation module 407 may include the following sub-modules:
a releasing submodule, configured to release the cache queue by a first writer;
a locking submodule for locking the cache queue by a second writer;
and the interface reading submodule is used for reading the multimedia data packet from the buffer queue through a reading interface provided by the buffer queue by a second writer.
In a preferred example of the embodiment of the present invention, the data source may include a camera and/or a microphone, and the multimedia data may include video data and/or audio data;
the multimedia data acquisition module 402 may include the following sub-modules:
the video data acquisition submodule is used for acquiring video data from the camera through a preset camera source class CameraSource;
and/or the presence of a gas in the gas,
and the audio data acquisition sub-module is used for acquiring audio data from the microphone through a preset audio source type AudioSource.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
Embodiments of the present invention are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present invention have been described, additional variations and modifications of these embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the embodiments of the invention.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The method for recording a multimedia file and the device for recording a multimedia file provided by the invention are described in detail, and a specific example is applied in the text to explain the principle and the implementation mode of the invention, and the description of the embodiment is only used for helping to understand the method and the core idea of the invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (7)

1. A method for recording a multimedia file, comprising:
when receiving a recording request of a multimedia file, an electronic device with a camera creates a data source, an encoder, a packer, a first multimedia writer and a second multimedia writer, wherein the first multimedia writer comprises a first writer and a first packer, the second multimedia writer comprises a second writer and a second packer, and the first packer and the second packer multiplex the encoder;
continuously acquiring multimedia data through a data source;
the encoder continuously encodes the multimedia data and writes the encoded multimedia data into a preset buffer queue;
the first multimedia writer reads the encoded multimedia data from the buffer queue and writes the encoded multimedia data into a first multimedia file;
judging whether the first multimedia file exceeds a preset file size threshold value or not; and if so, switching to a second multimedia writer to read the encoded multimedia data from the buffer queue and write the encoded multimedia data into a second multimedia file.
2. The method of claim 1, wherein the step of the first multimedia writer reading the encoded multimedia data from the buffer queue and writing the first multimedia file comprises:
the first packetizer reads the encoded multimedia data from the buffer queue;
the first packer packs the encoded multimedia data into multimedia data packets;
the first writer writes the multimedia data packet to a first multimedia file.
3. The method of claim 1 or 2, wherein the step of the first multimedia writer reading the encoded multimedia data from the buffer queue and writing the first multimedia file comprises:
when the first multimedia file exceeds a preset file size threshold, a first multimedia writer generates a packaging completion event;
the first multimedia writer broadcasts the encapsulation completion event.
4. The method of claim 3, wherein the step of determining whether the first multimedia file exceeds a preset file size threshold comprises:
determining whether a package complete event broadcast by a first multimedia writer is received; if yes, the first multimedia file is judged to exceed a preset file size threshold value.
5. The method of claim 1, wherein switching to a second multimedia writer to read encoded multimedia data from the buffer queue and write a second multimedia file comprises:
stopping the first packetizer and the first writer, and simultaneously, storing the first multimedia by the first writer;
starting a second packer and a second writer;
the second packer reads the encoded multimedia data from the buffer queue;
the second packer packs the encoded multimedia data into multimedia data packets;
the second writer writes the multimedia data packet to a second multimedia file.
6. The method of claim 1, wherein the buffer queue is configured with a mutex lock, and wherein switching to a second multimedia writer to read encoded multimedia data from the buffer queue comprises:
the first packer releases the buffer queue;
the second packer locks the buffer queue;
and the second packer reads the encoded multimedia data from the buffer queue through a reading interface provided by the buffer queue.
7. An apparatus for recording a multimedia file, comprising:
the recording tool creating module is used for creating a data source, an encoder, a packer, a first multimedia writer and a second multimedia writer when an electronic device with a camera receives a recording request of a multimedia file, wherein the first multimedia writer comprises a first writer and a first packer, the second multimedia writer comprises a second writer and a second packer, and the first packer and the second packer multiplex the encoder;
the multimedia data acquisition module is used for continuously acquiring multimedia data through a data source;
the encoding module is used for continuously encoding the multimedia data by an encoder and writing the encoded multimedia data into a preset buffer queue;
the first packaging module is used for reading the encoded multimedia data from the buffer queue by a first multimedia writer and writing the encoded multimedia data into a first multimedia file;
the file size judging module is used for judging whether the first multimedia file exceeds a preset file size threshold value or not; if so, calling a second packaging module;
and the second packaging module is used for switching to a second multimedia writer to read the encoded multimedia data from the buffer queue and write the encoded multimedia data into a second multimedia file.
CN201810646664.3A 2015-07-27 2015-07-27 Method and device for recording multimedia file Active CN108650545B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810646664.3A CN108650545B (en) 2015-07-27 2015-07-27 Method and device for recording multimedia file

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810646664.3A CN108650545B (en) 2015-07-27 2015-07-27 Method and device for recording multimedia file
CN201510447305.1A CN105049919B (en) 2015-07-27 2015-07-27 A kind of method for recording and device of multimedia file

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
CN201510447305.1A Division CN105049919B (en) 2015-07-27 2015-07-27 A kind of method for recording and device of multimedia file

Publications (2)

Publication Number Publication Date
CN108650545A CN108650545A (en) 2018-10-12
CN108650545B true CN108650545B (en) 2021-01-19

Family

ID=54456042

Family Applications (4)

Application Number Title Priority Date Filing Date
CN201810646021.9A Active CN108881770B (en) 2015-07-27 2015-07-27 Method and device for recording multimedia file
CN201810646664.3A Active CN108650545B (en) 2015-07-27 2015-07-27 Method and device for recording multimedia file
CN201810646022.3A Active CN108848406B (en) 2015-07-27 2015-07-27 Method and device for recording multimedia file
CN201510447305.1A Active CN105049919B (en) 2015-07-27 2015-07-27 A kind of method for recording and device of multimedia file

Family Applications Before (1)

Application Number Title Priority Date Filing Date
CN201810646021.9A Active CN108881770B (en) 2015-07-27 2015-07-27 Method and device for recording multimedia file

Family Applications After (2)

Application Number Title Priority Date Filing Date
CN201810646022.3A Active CN108848406B (en) 2015-07-27 2015-07-27 Method and device for recording multimedia file
CN201510447305.1A Active CN105049919B (en) 2015-07-27 2015-07-27 A kind of method for recording and device of multimedia file

Country Status (1)

Country Link
CN (4) CN108881770B (en)

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105430312B (en) * 2015-11-27 2018-06-29 福州瑞芯微电子股份有限公司 Based on the video recording of android system without frame losing fragmented storage method and system
CN106899880B (en) * 2015-12-19 2020-02-18 联芯科技有限公司 Method and system for storing multimedia data in segments
CN106027935A (en) * 2016-07-13 2016-10-12 深圳市爱培科技术股份有限公司 Frame-missing-free segmental video-recording system and implementation method
CN106162310A (en) * 2016-07-13 2016-11-23 浪潮电子信息产业股份有限公司 A kind of video image code stream recording method
CN106341636A (en) * 2016-09-29 2017-01-18 珠海全志科技股份有限公司 Android system-based continuous recording system and method
WO2018129736A1 (en) * 2017-01-16 2018-07-19 陈银芳 Video shooting method and apparatus
CN106998449B (en) * 2017-04-10 2020-02-04 青岛海信移动通信技术股份有限公司 Method and device for realizing seamless video recording in application layer and terminal equipment
CN107135364B (en) * 2017-04-10 2020-04-28 青岛海信移动通信技术股份有限公司 Method and device for realizing seamless video recording on native layer and terminal equipment
CN107800988A (en) * 2017-11-08 2018-03-13 青岛海信移动通信技术股份有限公司 A kind of method and device of video record, electronic equipment
CN111755017B (en) * 2020-07-06 2021-01-26 全时云商务服务股份有限公司 Audio recording method and device for cloud conference, server and storage medium
CN112423018A (en) * 2020-10-27 2021-02-26 深圳Tcl新技术有限公司 Media file coding transmission method, device, equipment and readable storage medium
CN113709398A (en) * 2021-08-24 2021-11-26 天津津航计算技术研究所 Video recording design method based on LVDS input
CN114466149A (en) * 2022-02-18 2022-05-10 展讯半导体(成都)有限公司 Video segment recording method, device, terminal equipment and storage medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101272501A (en) * 2008-05-07 2008-09-24 北京数码视讯科技股份有限公司 Video/audio encoding and decoding method and device

Family Cites Families (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2001268566A (en) * 2000-03-16 2001-09-28 Nec Corp Image processor, its method and computer readable recording medium
GB0214444D0 (en) * 2002-06-21 2002-07-31 Thirdspace Living Ltd User interface system
US7198341B1 (en) * 2002-07-01 2007-04-03 Rast Rodger H Enhanced electronic ink displays
CN100518274C (en) * 2006-01-13 2009-07-22 英业达股份有限公司 Media record device and method
JP2008016911A (en) * 2006-07-03 2008-01-24 Sony Corp Apparatus and method for recording/reproducing and program
CN101141727B (en) * 2007-10-19 2011-06-01 孟智平 Switch storage method and related equipment of terminal data
JP2009147549A (en) * 2007-12-12 2009-07-02 Samsung Techwin Co Ltd Moving image recording apparatus, moving image reproducing apparatus and program
US8280832B1 (en) * 2009-03-04 2012-10-02 The Mathworks, Inc. Proving latency associated with references to a data store
KR101574207B1 (en) * 2009-10-16 2015-12-14 삼성전자주식회사 Data storage device and data storing method thereof
CN101827209B (en) * 2009-11-27 2011-07-20 云南金隆伟业科技有限公司 High-definition video-circulating memory IP camera
CN102098423B (en) * 2009-12-10 2013-03-27 北大方正集团有限公司 Seamless file collection method and system
JP2012114751A (en) * 2010-11-25 2012-06-14 Jvc Kenwood Corp Stereoscopic video imaging device and stereoscopic video imaging method
CN102184101B (en) * 2011-04-27 2014-02-05 赵悦 Software application frame and development system thereof for smartphones
CN202103788U (en) * 2011-05-31 2012-01-04 中国电子科技集团公司第三十研究所 Monitoring system combining radio frequency identification and video shooting
CN104063184B (en) * 2013-03-19 2017-08-04 财团法人工业技术研究院 Magnetic disc storage method and its non-volatile storage medium and electronic installation
CN104079951B (en) * 2013-03-26 2017-11-03 联想(北京)有限公司 Multimedia file processing method and electronic equipment
CN103325399B (en) * 2013-05-15 2016-04-06 北京汉邦高科数字技术股份有限公司 A kind of method play and back up video file
CN103517021A (en) * 2013-09-13 2014-01-15 广东欧珀移动通信有限公司 Method and terminal for Android terminal to automatically perform recording continuously
CN103780949B (en) * 2014-01-28 2016-11-16 佛山络威网络技术有限公司 A kind of multi-medium data method for recording
CN108184083B (en) * 2015-04-09 2020-09-11 Oppo广东移动通信有限公司 Method, device and terminal for acquiring video maximization and computer readable storage medium

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101272501A (en) * 2008-05-07 2008-09-24 北京数码视讯科技股份有限公司 Video/audio encoding and decoding method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于EPON网络电视的MPEG-2编码模块设计;孙俊;《中国优秀硕士学位论文全文数据库 信息科技辑》;20080315(第3期);全文 *

Also Published As

Publication number Publication date
CN108881770A (en) 2018-11-23
CN108881770B (en) 2021-01-05
CN108848406B (en) 2020-11-24
CN108848406A (en) 2018-11-20
CN108650545A (en) 2018-10-12
CN105049919A (en) 2015-11-11
CN105049919B (en) 2018-07-31

Similar Documents

Publication Publication Date Title
CN108650545B (en) Method and device for recording multimedia file
CN105049920B (en) A kind of method for recording and device of multimedia file
CN106131550B (en) Method and device for playing multimedia file
CN112235597B (en) Method and device for synchronous protection of streaming media live broadcast audio and video and computer equipment
CN114237498B (en) Snapshot generation method and system for cloud primary storage data volume
CN113225605B (en) Video playing processing method and device, electronic equipment and storage medium
US11343544B2 (en) Selective use of cameras in a distributed surveillance system
US20210409792A1 (en) Distributed surveillance system with distributed video analysis
CN105049904A (en) Play method and play device of multi-media files
CN106998449B (en) Method and device for realizing seamless video recording in application layer and terminal equipment
CN113938642A (en) Distributed monitoring system with abstraction function layer
CN111918074A (en) Live video fault early warning method and related equipment
US9026983B2 (en) Flexible and scalable software system architecture for implementing multimedia applications
US20210409817A1 (en) Low latency browser based client interface for a distributed surveillance system
CN114449200A (en) Audio and video call method and device and terminal equipment
TW201234289A (en) Autonomous intelligent content items
CN202759536U (en) Highly reliable vehicle-loaded video storage apparatus and vehicle-loaded video apparatus
CN113905266B (en) Audio and video data processing method, device, equipment and storage medium
CN107135364B (en) Method and device for realizing seamless video recording on native layer and terminal equipment
CN116055738B (en) Video compression method and electronic equipment
CN104240732A (en) Compact disc write-in method and device
CN114339389B (en) Audio-video system
US11463739B2 (en) Parameter based load balancing in a distributed surveillance system
CN117834982A (en) Video playing processing method and device, electronic equipment and storage medium
CN109871281B (en) Data interaction method and device based on InSE security chip

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: 266100 No. 151, Zhuzhou Road, Laoshan District, Shandong, Qingdao

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

Address before: 266100 No. 151, Zhuzhou Road, Laoshan District, Shandong, Qingdao

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

CP01 Change in the name or title of a patent holder