WO2022021973A1 - 一种视频转码方法、装置、电子设备及存储介质 - Google Patents

一种视频转码方法、装置、电子设备及存储介质 Download PDF

Info

Publication number
WO2022021973A1
WO2022021973A1 PCT/CN2021/090639 CN2021090639W WO2022021973A1 WO 2022021973 A1 WO2022021973 A1 WO 2022021973A1 CN 2021090639 W CN2021090639 W CN 2021090639W WO 2022021973 A1 WO2022021973 A1 WO 2022021973A1
Authority
WO
WIPO (PCT)
Prior art keywords
gop
interval
gop interval
transcoding
target
Prior art date
Application number
PCT/CN2021/090639
Other languages
English (en)
French (fr)
Inventor
张文杰
樊鸿飞
荆睿
蔡媛
Original Assignee
北京金山云网络技术有限公司
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 北京金山云网络技术有限公司 filed Critical 北京金山云网络技术有限公司
Publication of WO2022021973A1 publication Critical patent/WO2022021973A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/40Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using video transcoding, i.e. partial or full decoding of a coded input stream followed by re-encoding of the decoded output stream
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N19/00Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
    • H04N19/10Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
    • H04N19/169Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding
    • H04N19/177Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the coding unit, i.e. the structural portion or semantic portion of the video signal being the object or the subject of the adaptive coding the unit being a group of pictures [GOP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/20Servers specifically adapted for the distribution of content, e.g. VOD servers; Operations thereof
    • H04N21/23Processing of content or additional data; Elementary server operations; Server middleware
    • H04N21/234Processing of video elementary streams, e.g. splicing of video streams or manipulating encoded video stream scene graphs
    • H04N21/2343Processing of video elementary streams, e.g. splicing of video streams or manipulating encoded video stream scene graphs involving reformatting operations of video signals for distribution or compliance with end-user requests or end-user device requirements
    • H04N21/234309Processing of video elementary streams, e.g. splicing of video streams or manipulating encoded video stream scene graphs involving reformatting operations of video signals for distribution or compliance with end-user requests or end-user device requirements by transcoding between formats or standards, e.g. from MPEG-2 to MPEG-4 or from Quicktime to Realvideo
    • 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/44Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs
    • H04N21/4402Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs involving reformatting operations of video signals for household redistribution, storage or real-time display
    • H04N21/440218Processing of video elementary streams, e.g. splicing a video clip retrieved from local storage with an incoming video stream or rendering scenes according to encoded video stream scene graphs involving reformatting operations of video signals for household redistribution, storage or real-time display by transcoding between formats or standards, e.g. from MPEG-2 to MPEG-4

Definitions

  • the present application relates to the technical field of video processing, and in particular, to a video transcoding method, apparatus, electronic device, and storage medium.
  • a preset fixed transcoding parameter such as a GOP (Group of Pictures, group of pictures) interval
  • a GOP Group of Pictures, group of pictures
  • one GOP usually includes one I frame, at least one P frame and at least one B frame
  • the I frame is an image frame including a complete picture, that is, a key frame.
  • the applicant of the present application found that the quality of the obtained transcoded video is not very high when the video is transcoded by using a preset fixed GOP interval.
  • the purpose of the embodiments of the present application is to provide a video transcoding method, apparatus, electronic device, and storage medium, so as to improve the quality of the transcoded video.
  • an embodiment of the present application provides a video transcoding method, the method includes: acquiring multiple GOP intervals of a video to be transcoded and a preset transcoding GOP interval; if the multiple GOP intervals satisfy the preset Difference condition, determine the source GOP interval according to multiple GOP intervals; determine the target GOP interval for transcoding the video to be transcoded based on the size relationship between the source GOP interval and the transcoding GOP interval; adopt the target GOP interval, to be transcoded The video is transcoded to obtain the transcoded video.
  • the preset difference condition includes: multiple GOP intervals are the same; and determining the source GOP interval according to the multiple GOP intervals includes: taking the same GOP interval as the source GOP interval.
  • the preset difference condition includes: the difference between any two GOP intervals in the multiple GOP intervals is less than a preset GOP interval difference threshold; or each GOP interval in the multiple GOP intervals is different from the multiple GOP intervals.
  • the difference between the average values of the intervals is within a preset deviation range;
  • determining the source GOP interval according to multiple GOP intervals includes: taking the average value of the multiple GOP intervals as the source GOP interval.
  • the method further includes: if the multiple GOP intervals do not meet the preset difference condition, transcoding The code GOP interval is taken as the target GOP interval, and the steps of using the target GOP interval to transcode the video to be transcoded to obtain the transcoded video are performed.
  • determining the target GOP interval for transcoding the to-be-transcoded video includes: if the transcoding GOP interval is an integer multiple of the source GOP interval, or the source GOP interval If the interval is an integer multiple of the transcoding GOP interval, the transcoding GOP interval is determined as the target GOP interval; if the transcoding GOP interval is between the source GOP interval that is a preset fractional multiple and the source GOP interval that is 2 times the source GOP interval, the source GOP interval is determined as the target GOP interval. The GOP interval is determined as the target GOP interval.
  • determining the target GOP interval for transcoding the video to be transcoded includes: if the transcoding GOP interval is less than the source GOP interval of a preset fractional multiple, Divide the source GOP interval by the transcoding GOP interval to obtain the calculation result; if the calculation result is not an integer, determine the target GOP interval according to the relationship between the remainder in the calculation result and the transcoding GOP interval that is multiples of the preset fraction.
  • determining the target GOP interval according to the relationship between the remainder in the calculation result and the transcoding GOP interval of a preset fractional multiple includes: if the remainder is not greater than the transcoding GOP interval of the preset fractional multiple, then Take the quotient in the calculation result as the target GOP interval change period m; take the transcoding GOP interval as the 1st to m-1th target GOP interval in the change period; take the sum of the transcoding GOP interval and the remainder as the mth Target GOP interval; if the remainder is greater than the transcoding GOP interval of the preset fraction multiple, add 1 to the quotient in the calculation result and use it as the target GOP interval change period n; take the transcoding GOP interval as the first to The n-1 th target GOP interval; the remainder is taken as the n th target GOP interval; using the target GOP interval, transcode the video to be transcoded to obtain the transcoded video, including: adopting the determined m target GOP intervals , and according to the target GOP interval change period m, transcode the to-be
  • an embodiment of the present application further provides a video transcoding device, the device comprising: a first picture group interval acquisition module configured to acquire multiple GOP intervals of the video to be transcoded and a preset transcoding GOP interval
  • the second group of pictures interval acquisition module is set to if a plurality of GOP intervals meet the preset difference condition, then according to a plurality of GOP intervals, determine the source GOP interval;
  • the target group of pictures interval determination module is set to be based on the source GOP interval and the rotation
  • the size relationship of the code GOP interval determines the target GOP interval for transcoding the video to be transcoded; the transcoding module is set to use the target GOP interval to transcode the to-be-transcoded video to obtain the transcoded video.
  • the preset difference condition includes: multiple GOP intervals are the same; the second GOP interval obtaining module is set to: take the same GOP interval as the source GOP interval.
  • the preset difference condition includes: the difference between any two GOP intervals in the multiple GOP intervals is less than a preset GOP interval difference threshold; or each GOP interval in the multiple GOP intervals is different from the multiple GOP intervals.
  • the difference between the average values of the intervals is within a preset deviation range, and the second group of pictures interval acquisition module is set to: take the average value of multiple GOP intervals as the source GOP interval.
  • the target group of pictures interval determination module is further configured to: after acquiring multiple GOP intervals of the video to be transcoded and the preset transcoding GOP interval, if the multiple GOP intervals do not meet the preset difference If the value condition is met, the transcoding GOP interval is used as the target GOP interval, and the transcoding module is triggered to perform the transcoding operation.
  • the target GOP interval determination module includes: a first determination submodule, configured to: if the transcoding GOP interval is an integer multiple of the source GOP interval, or the source GOP interval is an integer multiple of the transcoding GOP interval, then The transcoding GOP interval is determined as the target GOP interval; the second determination submodule is set to determine the source GOP interval if the transcoding GOP interval is between the source GOP interval of a preset fraction multiple and the source GOP interval of 2 times is the target GOP interval.
  • the target GOP interval determination module includes: a calculation submodule, configured to divide the source GOP interval by the transcoding GOP interval if the transcoding GOP interval is less than the source GOP interval of a preset fractional multiple to obtain: The calculation result; the fourth determination submodule is set to determine the target GOP interval according to the relationship between the remainder in the calculation result and the transcoding GOP interval that is multiples of the preset fraction if the calculation result is not an integer.
  • the fourth determination submodule is set to: if the remainder is not greater than the transcoding GOP interval of a preset fractional multiple, then the quotient in the calculation result is used as the target GOP interval variation period m; the transcoding GOP The interval is the 1st to m-1th target GOP interval in the change period m; the sum of the transcoding GOP interval and the remainder is taken as the mth target GOP interval; m is a positive integer; code GOP interval, add 1 to the quotient in the calculation result and take it as the target GOP interval change period n; take the transcoding GOP interval as the 1st to n-1th target GOP interval in the change period n; take the remainder as the nth target GOP interval target GOP intervals; n is a positive integer; the transcoding module is set to: use the determined m target GOP intervals, and change the period m according to the target GOP interval, transcode the video to be transcoded, and obtain the transcoded video ; Or adopt the determined n target GOP intervals, and according to
  • embodiments of the present application further provide an electronic device, including a processor and a computer-readable storage medium, where the computer-readable storage medium stores executable program codes that can be executed by the processor, and the processor reads the above
  • the executable program code stored in the computer-readable storage medium runs the program corresponding to the above-mentioned executable program code, so as to execute: a video transcoding method provided by the first aspect of the embodiments of the present application.
  • the embodiments of the present application further provide a computer-readable storage medium, where executable program codes are stored in the computer-readable storage medium, and when the executable program codes are executed by a processor, the above-mentioned first aspect provides A video transcoding method.
  • an embodiment of the present application further provides a computer program product including instructions, which, when running on a computer, enables the computer to execute the video transcoding method provided in the first aspect.
  • an embodiment of the present application further provides a computer program that, when running on a computer, causes the computer to execute the video transcoding method provided in the first aspect above.
  • a video transcoding method, device, electronic device, and storage medium provided by the embodiments of the present application, when the video to be transcoded is transcoded, multiple GOP intervals of the video to be transcoded and a preset transcoding GOP interval are first obtained; Then judge whether the multiple GOP intervals satisfy the preset difference condition, and if so, determine the source GOP interval according to the multiple GOP intervals; The target GOP interval of the code; finally, the target GOP interval is used to transcode the video to be transcoded to obtain the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.
  • any product or method of the present application does not necessarily require achieving all of the above-mentioned advantages at the same time.
  • FIG. 1 is a flowchart of a first implementation manner of a video transcoding method according to an embodiment of the application
  • FIG. 2 is a flowchart of a second implementation manner of a video transcoding method according to an embodiment of the present application
  • FIG. 3 is a flowchart of a third implementation manner of a video transcoding method according to an embodiment of the present application.
  • FIG. 4 is a flowchart of a fourth implementation manner of a video transcoding method according to an embodiment of the present application.
  • FIG. 5 is a schematic structural diagram of a video transcoding apparatus according to an embodiment of the application.
  • FIG. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
  • a preset fixed transcoding parameter for example, a GOP interval
  • each GOP of the video to be transcoded is first decoded, and then the decoded video is re-encoded by using a preset GOP interval, so that the transcoded video can be obtained.
  • the B-frame image and P-frame image in the GOP usually need to be encoded and decoded based on the I-frame image. Therefore, the encoded B-frame image and the encoded P-frame image are the same as Compared with the corresponding original image, there is usually an error. When the distance between the encoded B-frame image and the encoded P-frame image and the corresponding I-frame image in the GOP is farther, the error is also larger.
  • the I-frame image of the GOP re-determined based on the preset GOP interval may be the B-frame image or P-frame in the to-be-transcoded video. image. If the corresponding B-frame image or P-frame image is encoded and decoded based on the I-frame image of the re-determined GOP, error accumulation will be formed, which will reduce the encoding quality of the re-encoded video to be transcoded, resulting in the obtained The quality of the transcoded video is not very high.
  • the embodiments of the present application provide a video transcoding method, apparatus, electronic device, and storage medium, so as to improve the quality of the transcoded video.
  • FIG. 1 it is a flowchart of a first implementation manner of a video transcoding method according to an embodiment of the present application.
  • the method may include:
  • the video to be transcoded when the video to be transcoded is to be transcoded, the video to be transcoded may be decoded first. After decoding the video to be transcoded, multiple GOP intervals of the video to be transcoded can be obtained. In some examples, the number of the multiple GOP intervals is not limited, and may be preset according to an empirical value, for example, may be set to 60, 100, or 150, etc.
  • the transcoding GOP interval is preset.
  • the transcoding GOP interval may be a preset general transcoding GOP interval, or a dedicated transcoding GOP interval may be preset for the video to be transcoded. After the transcoding GOP interval is set, you can save it. When transcoding the video to be transcoded, you can directly read the saved transcoding GOP interval.
  • the preset difference condition is set to determine whether the multiple GOP intervals are the same or similar.
  • the source GOP interval may be determined according to multiple GOP intervals.
  • the source GOP interval and the transcoding GOP interval may be directly related to the source GOP interval.
  • the GOP interval is determined as the target GOP interval; it is also possible to directly determine the transcoding GOP interval as the target GOP interval based on the size relationship between the source GOP interval and the transcoding GOP interval; it can also be based on the size relationship between the source GOP interval and the transcoding GOP interval,
  • the source GOP interval and the transcoding GOP interval are calculated to obtain the target GOP interval.
  • the target GOP interval can be used to transcode the video to be transcoded, so that the transcoded video can be obtained.
  • a to-be-transcoded video when a to-be-transcoded video is transcoded, first obtains multiple GOP intervals of the to-be-transcoded video and a preset transcoding GOP interval; and then judges whether the multiple GOP intervals satisfy The preset difference condition, if satisfied, determines the source GOP interval according to multiple GOP intervals; and determines the target GOP interval for transcoding the video to be transcoded based on the size relationship between the source GOP interval and the transcoding GOP interval; and finally adopts Target GOP interval, transcode the video to be transcoded, and obtain the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.
  • the preset difference condition may include: multiple GOP intervals are the same; for this, when the source GOP interval is determined according to the multiple GOP intervals, the same GOP interval may be used as the source GOP interval.
  • the multiple GOP intervals of the video to be transcoded may or may not be the same. Therefore, the above-mentioned preset difference condition may also include: the difference between any two GOP intervals in the multiple GOP intervals The value is less than the preset GOP interval difference threshold; or the difference between each GOP interval in the multiple GOP intervals and the average value of the multiple GOP intervals is within the preset deviation range;
  • the multiple GOP intervals when the multiple GOP intervals are different, it can be determined whether the difference between any two GOP intervals in the multiple GOP intervals is less than a preset GOP interval difference threshold, or it can be determined whether the difference between the multiple GOP intervals is Whether the difference between each GOP interval and the average value of the multiple GOP intervals is within a preset deviation range.
  • the difference between any two GOP intervals in the multiple GOP intervals is smaller than the preset GOP interval difference threshold, or the difference between each GOP interval in the multiple GOP intervals and the average value of the multiple GOP intervals is within the preset GOP interval difference threshold If the deviation is within the range, it can be shown that each GOP interval fluctuates slightly within a certain range above and below the average value of the multiple GOP intervals, and it can be considered that the GOP intervals are similar, therefore, it can be considered that the multiple GOP intervals satisfy the predetermined
  • the difference condition is set, and the average value of the multiple GOP intervals is used as the source GOP interval.
  • the preset deviation range may be a deviation range value set in advance according to experience.
  • the video transcoding method of the embodiment of the present application can also be used to determine the target GOP interval for transcoding the video to be transcoded, and then use the target GOP
  • the video to be transcoded is transcoded at intervals, so that when the target GOP interval is determined, the source GOP interval can be considered, so it can be adapted to transcode different videos with different source GOP intervals.
  • the quality of the transcoded video is improved.
  • the multiple GOP intervals may be close, or there may be at least two GOP intervals with a relatively large difference, or there may be a difference between at least one GOP interval and the average value of the multiple GOP intervals within a preset deviation range
  • the preset transcoding GOP interval can be directly used as the target GOP interval, and then the target GOP interval is used to perform the transcoding video. Transcode to get the transcoded video.
  • the embodiments of the present application provide a variety of possible
  • the implementation manner, as shown in FIG. 2 , FIG. 3 and FIG. 4 is an exemplary implementation manner of determining a target transcoding interval in a video transcoding method according to an embodiment of the present application.
  • FIG. 2 it is a flowchart of the second implementation manner of a video transcoding method according to an embodiment of the present application, and the method may include:
  • step S230 determine the size relationship between the source GOP interval and the transcoding GOP interval; if the transcoding GOP interval is an integer multiple of the source GOP interval, or the source GOP interval is an integer multiple of the transcoding GOP interval, then execute step S240, if the transcoding GOP interval The interval is between the source GOP interval of a preset fractional multiple and the source GOP interval of 2 times, then step S250 is performed;
  • step S240 determine the transcoding GOP interval as the target GOP interval, and execute step S260;
  • step S250 determine the source GOP interval as the target GOP interval, and execute step S260;
  • the transcoding GOP interval when judging the size relationship between the source GOP interval and the transcoding GOP interval, it can be determined whether the transcoding GOP interval is an integer multiple of the source GOP interval or whether the source GOP interval is an integer multiple of the transcoding GOP interval, if Yes, then the transcoding GOP interval can be determined as the target GOP interval.
  • the transcoding GOP interval when judging the size relationship between the source GOP interval and the transcoding GOP interval, it can also be determined whether the transcoding GOP interval is between the source GOP interval that is a preset fraction multiple of the source GOP interval and the source GOP interval that is twice the source GOP interval, if Yes, the source GOP interval can be determined as the target GOP interval.
  • the transcoding GOP interval N turns is an integer multiple of the source GOP interval N source , or determine whether the source GOP interval is an integer multiple of N source. Whether the interval N source is an integer multiple of the transcoding GOP interval N turns , if so, the transcoding GOP interval N turns may be determined as the target GOP interval N reset .
  • the preset fraction times corresponding to the source GOP interval are set in advance based on experience, for example, it may be 1/2 times. In this case, it can be determined whether the transcoding GOP interval N turns is greater than 1/2N source , and less than 2 times the N source . If so, the source GOP interval N source may be determined as the target GOP interval N reset .
  • N source 60
  • steps S210 , S220 and S260 in the embodiments of the present application are the same as or similar to steps S110 , S120 and S140 in the first implementation of the video transcoding method in the embodiments of the present application, and are not repeated here.
  • FIG. 3 it is a flowchart of a third implementation manner of a video transcoding method according to an embodiment of the present application, and the method may include:
  • the value closest to the transcoding GOP interval is determined as the target GOP interval
  • the above-mentioned transcoding GOP interval may or may not be an integral multiple of the source GOP interval.
  • the transcoding GOP interval may be located at k times. Between the source GOP interval and k-1 times the source GOP interval.
  • k times the source GOP interval and k-1 times the source GOP interval may be calculated first, and then k times the source GOP interval and k-1 times the source GOP interval may be calculated first.
  • the value closest to the transcoding GOP interval is determined as the target GOP interval.
  • the I-frame image of the determined target GOP interval can be made the same as the I-frame image of at least one GOP interval in the multiple source GOP intervals of the video to be transcoded, and the same as The transcoding GOP interval is close. Therefore, the accumulation of errors can be reduced, and the encoding quality of the re-encoded video to be transcoded can be improved, so as to improve the quality of the obtained transcoded video.
  • the determined I-frame image of the target GOP interval may be the same as the I-frame image of the fourth GOP interval in the source GOP interval, or may be the same as the I-frame image of the fourth GOP interval in the source GOP interval.
  • the I-frame image of the sixth GOP interval in the source GOP interval is the same, so that during transcoding, the I-frame image used is at least the same as an original image frame of the video to be transcoded.
  • steps S310 , S320 and S350 in the embodiments of the present application are the same as or similar to steps S110 , S120 and S140 in the first implementation of the video transcoding method in the embodiments of the present application, and are not repeated here.
  • FIG. 4 it is a flowchart of a fourth implementation manner of a video transcoding method according to an embodiment of the present application, and the method may include:
  • step S430 determine the size relationship between the source GOP interval and the transcoding GOP interval; if the transcoding GOP interval is less than the source GOP interval of a preset fraction multiple, then execute step S440;
  • step S440 divide the source GOP interval by the transcoding GOP interval to obtain a calculation result; if the calculation result is not an integer, then execute step S450;
  • the transcoding GOP interval when the transcoding GOP interval is not an integer multiple of the source GOP interval, the transcoding GOP interval may be smaller than the source GOP interval by a preset fractional multiple, wherein the source GOP interval corresponds to a preset fraction
  • the times may be set empirically in advance, for example, the preset fraction times of the source GOP interval may be 1/2. Then the transcoding GOP interval N turns may be less than 1/2 times the source GOP interval N source .
  • the source GOP interval may be divided by the transcoding GOP interval to obtain a calculation result, and then it is determined whether the calculation result is an integer. If it is not an integer, the target GOP interval may be determined according to the relationship between the remainder in the calculation result and the transcoding GOP interval that is multiples of the preset fraction. Then, using the target GOP interval, the video to be transcoded is transcoded to obtain the transcoded video.
  • the target GOP interval when the target GOP interval is determined according to the relationship between the remainder in the calculation result and the transcoding GOP interval of a preset fractional multiple, it may be determined whether the remainder in the calculation result is greater than the transcoding of the preset fractional multiple GOP interval; wherein, the preset fraction times corresponding to the transcoding GOP interval may also be set according to experience, for example, may be set to 1/2.
  • the quotient in the calculation result is taken as the target GOP interval change period m; the transcoding GOP interval is taken as the 1st to m-1th targets in the change period m GOP interval; take the sum of the transcoding GOP interval and the remainder as the mth target GOP interval; m is a positive integer;
  • the video to be transcoded is transcoded to obtain the transcoded video.
  • n is a positive integer
  • the video to be transcoded is transcoded to obtain the transcoded video.
  • the video to be transcoded is transcoded, so that the transcoded video can be obtained.
  • the determined 2 target GOP intervals 60 and 89 are used first, and the video to be transcoded is divided into a plurality of GOPs to be transcoded according to the target GOP interval change period, and then each code GOP for transcoding.
  • the target GOP is divided into one GOP at an interval of 60, . . . and circulates in sequence, so that the video to be transcoded can be divided into multiple GOPs to be transcoded according to the change period of the target GOP interval.
  • the video to be transcoded is transcoded, so that the transcoded video can be obtained.
  • the determined I-frame image of the target GOP interval when determining the target GOP interval, can be made the same as the I-frame image of at least one GOP interval in the multiple source GOP intervals of the video to be transcoded, and, Same as transcoding GOP interval. Therefore, the accumulation of errors can be reduced, and the encoding quality of the re-encoded video to be transcoded can be improved, so as to improve the quality of the obtained transcoded video.
  • steps S410 , S420 and S460 in the embodiments of the present application are the same as or similar to steps S110 , S120 and S140 in the first implementation of the video transcoding method in the embodiments of the present application, and are not repeated here.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, it is assumed that The preset fractional multiplier of the source GOP interval is 1/2, and the preset fractional multiplication of the transcoding GOP interval is also 1/2. Then, as shown in Figure 2, Figure 3 and Figure 4, it is determined that the video to be transcoded is transcoded.
  • the way the target GOP interval can be expressed as follows:
  • N reset k ⁇ Nsource
  • r is the above-mentioned target GOP interval change period m or n, 1 ⁇ i ⁇ r, The following conditions:
  • the above video transcoding method can be applied to any electronic device having a video transcoding function.
  • it can be applied to a user terminal or a server.
  • the above video transcoding method can be integrated into an offline video transcoding tool; if the user terminal has the video transcoding tool installed, the user can upload the video files that need to be transcoded to The video transcoding tool performs transcoding and outputs the transcoding result for users to use.
  • the above video transcoding method can be integrated into a software with a video playback function; if the software is installed on the user terminal, after the software obtains the video stream from the server, it can use the above The method transcodes the video stream, and then performs the video playback operation.
  • the user terminal When applied to the server, the user terminal can send a video stream acquisition request carrying the video format to the server; after the server receives the request, if it is determined that the format of the original video stream is different from the video format carried in the request, the above method can be used.
  • the video stream is first transcoded, and then the transcoded video stream is sent to the user terminal for playback.
  • an embodiment of the present application further provides a video transcoding apparatus.
  • FIG. 5 it is a schematic structural diagram of a video transcoding apparatus according to an embodiment of the present application.
  • the apparatus may include:
  • the first picture group interval obtaining module 510 is configured to obtain a plurality of GOP intervals of the video to be transcoded and a preset transcoding GOP interval;
  • the second GOP interval obtaining module 520 is configured to determine the source GOP interval according to the plurality of GOP intervals if the multiple GOP intervals satisfy the preset difference condition;
  • the target GOP interval determination module 530 is set to determine the target GOP interval that the video to be transcoded is transcoded based on the size relationship between the source GOP interval and the transcoding GOP interval;
  • the transcoding module 540 is configured to use the target GOP interval to transcode the video to be transcoded to obtain the transcoded video.
  • a video transcoding apparatus when transcoding a to-be-transcoded video, it first acquires multiple GOP intervals of the to-be-transcoded video and a preset transcoding GOP interval; and then judges whether the multiple GOP intervals satisfy The preset difference condition, if satisfied, determines the source GOP interval according to multiple GOP intervals; and determines the target GOP interval for transcoding the video to be transcoded based on the size relationship between the source GOP interval and the transcoding GOP interval; and finally adopts Target GOP interval, transcode the video to be transcoded, and obtain the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.
  • the preset difference condition includes: multiple GOP intervals are the same; the second GOP interval obtaining module 520 is set to: take the same GOP interval as the source GOP interval;
  • the preset difference condition includes: a difference between any two GOP intervals in the multiple GOP intervals is less than a preset GOP interval difference threshold; or each GOP interval in the multiple GOP intervals is different from the multiple GOP intervals
  • the difference between the average values of is within the preset deviation range, and the second picture group interval acquisition module 520 is set to:
  • the average of multiple GOP intervals is taken as the source GOP interval.
  • the target group of pictures interval determination module 530 is further configured to:
  • the encoding module 540 After acquiring multiple GOP intervals of the video to be transcoded and the preset transcoding GOP interval, if the multiple GOP intervals do not meet the preset difference condition, the transcoding GOP interval is used as the target GOP interval, and the transcoding GOP interval is triggered.
  • the encoding module 540 performs the transcoding operation.
  • the target group of pictures interval determination module 530 includes:
  • the first determination submodule is set to if the transcoding GOP interval is an integer multiple of the source GOP interval, or the source GOP interval is an integer multiple of the transcoding GOP interval, then the transcoding GOP interval is determined as the target GOP interval;
  • the second determining submodule is configured to determine the source GOP interval as the target GOP interval if the transcoding GOP interval is between the source GOP interval of a preset fractional multiple and the source GOP interval twice as large.
  • the target group of pictures interval determination module 530 includes:
  • the target group of pictures interval determination module 530 includes:
  • the calculation submodule is configured to divide the source GOP interval by the transcoding GOP interval if the transcoding GOP interval is less than the source GOP interval of a preset fractional multiple to obtain the calculation result;
  • the fourth determining submodule is configured to determine the target GOP interval according to the relationship between the remainder in the calculation result and the transcoding GOP interval that is multiples of the preset fraction if the calculation result is not an integer.
  • the fourth determination sub-module is set to:
  • the quotient in the calculation result is taken as the target GOP interval change period m; the transcoding GOP interval is taken as the 1st to m-1th targets in the change period m GOP interval; take the sum of the transcoding GOP interval and the remainder as the mth target GOP interval; m is a positive integer;
  • n is a positive integer
  • the transcoding module 540 is set to:
  • the video to be transcoded is transcoded to obtain the transcoded video
  • the video to be transcoded is transcoded to obtain the transcoded video.
  • FIG. 6 it is a schematic structural diagram of a video transcoding method according to an embodiment of the present application applied to an electronic device.
  • the electronic device may include a processor 601 and a computer-readable Storage medium 602, the computer-readable storage medium 602 stores executable program codes that can be executed by the processor 601, and the processor 601 executes and executes the above-mentioned executable program by reading the executable program codes stored in the above-mentioned computer-readable storage medium.
  • the source GOP interval is determined according to the multiple GOP intervals
  • the video to be transcoded is transcoded to obtain the transcoded video.
  • the above-mentioned computer-readable storage medium 602 may include random access memory (Random Access Memory, RAM), and may also include non-volatile memory (Non-Volatile Memory, NVM), such as at least one disk storage.
  • RAM Random Access Memory
  • NVM Non-Volatile Memory
  • the memory may also be at least one storage device located remotely from the aforementioned processor.
  • the above-mentioned processor 601 can be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; it can also be a digital signal processor (Digital Signal Processing, DSP), dedicated Integrated Circuit (Application Specific Integrated Circuit, ASIC), Field-Programmable Gate Array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
  • a central processing unit Central Processing Unit, CPU
  • NP Network Processor
  • DSP Digital Signal Processing
  • ASIC Application Specific Integrated Circuit
  • FPGA Field-Programmable Gate Array
  • FPGA Field-Programmable Gate Array
  • the above-mentioned processor runs the program corresponding to the above-mentioned executable program code by reading the executable program code stored in the above-mentioned computer-readable storage medium, and can also execute the method for switching a network card mode provided by the embodiment of the present application. any steps.
  • An electronic device when transcoding a video to be transcoded, first obtains multiple GOP intervals of the to-be-transcoded video and a preset transcoding GOP interval; and then judges whether the multiple GOP intervals satisfy the preset If the difference condition is satisfied, the source GOP interval is determined according to multiple GOP intervals; and based on the size relationship between the source GOP interval and the transcoding GOP interval, the target GOP interval for transcoding the video to be transcoded is determined; finally, the target GOP interval is adopted Interval, transcode the video to be transcoded to get the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.
  • Embodiments of the present application further provide a computer-readable storage medium, where executable program codes are stored in the computer-readable storage medium, and when the executable program codes are executed by a processor, the one provided by the embodiments of the present application is implemented.
  • the video transcoding method for example, can implement the following steps:
  • the source GOP interval is determined according to the multiple GOP intervals
  • the video to be transcoded is transcoded to obtain the transcoded video.
  • a computer-readable storage medium when transcoding a video to be transcoded, first obtain multiple GOP intervals of the to-be-transcoded video and a preset transcoding GOP interval; then determine whether the multiple GOP intervals are The preset difference condition is met, if so, the source GOP interval is determined according to multiple GOP intervals; and based on the size relationship between the source GOP interval and the transcoding GOP interval, the target GOP interval for transcoding the video to be transcoded is determined; finally Using the target GOP interval, the video to be transcoded is transcoded to obtain the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.
  • the embodiment of the present application also provides a computer program product including an instruction, which, when running on a computer, causes the computer to execute a video transcoding method provided by the embodiment of the present application, for example, the following steps may be performed:
  • the source GOP interval is determined according to the multiple GOP intervals
  • the video to be transcoded is transcoded to obtain the transcoded video.
  • a computer program product including an instruction provided by an embodiment of the present application, when transcoding a to-be-transcoded video, first obtains multiple GOP intervals of the to-be-transcoded video and a preset transcoding GOP interval; then determines multiple GOP intervals Whether the preset difference condition is met, if so, the source GOP interval is determined according to multiple GOP intervals; and based on the size relationship between the source GOP interval and the transcoding GOP interval, the target GOP interval for transcoding the video to be transcoded is determined; Finally, using the target GOP interval, the video to be transcoded is transcoded to obtain the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.
  • the embodiments of the present application also provide a computer program, which, when running on a computer, enables the computer to execute a video transcoding method provided by the embodiments of the present application, for example, the following steps may be performed:
  • the source GOP interval is determined according to the multiple GOP intervals
  • the video to be transcoded is transcoded to obtain the transcoded video.
  • a computer program provided by an embodiment of the present application when transcoding a video to be transcoded, first obtains multiple GOP intervals of the to-be-transcoded video and a preset transcoding GOP interval; and then judges whether the multiple GOP intervals satisfy the preset If the difference condition is satisfied, the source GOP interval is determined according to multiple GOP intervals; and based on the size relationship between the source GOP interval and the transcoding GOP interval, the target GOP interval for transcoding the video to be transcoded is determined; finally, the target GOP interval is adopted Interval, transcode the video to be transcoded to get the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.
  • a video transcoding method, device, electronic device, and storage medium provided by the embodiments of the present application, when transcoding a to-be-transcoded video, first obtain multiple GOP intervals of the to-be-transcoded video and a preset transcoding GOP interval Then judge whether a plurality of GOP intervals meet the preset difference condition, if satisfied, then according to a plurality of GOP intervals, determine the source GOP interval; The target GOP interval for transcoding; finally, the target GOP interval is used to transcode the video to be transcoded to obtain the transcoded video.
  • the target GOP interval for transcoding the video to be transcoded is determined based on the size relationship between the source GOP interval and the transcoding GOP interval, and then the target GOP interval is used to transcode the to-be-transcoded video, that is, when determining the target GOP interval.
  • the source GOP interval is taken into account, so transcoding of different videos with different source GOP intervals can be accommodated.
  • the quality of the transcoded video is improved.

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

本申请实施例提供了一种视频转码方法、装置、电子设备及存储介质,其中,该方法包括: 获取待转码视频的多个GOP间隔和设置的转码GOP间隔; 如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔; 基于源GOP间隔和转码GOP间隔的大小关系确定目标GOP间隔; 采用目标GOP间隔对待转码视频进行转码,得到转码后的视频。通过在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定GOP间隔对视频进行转码方法,提高了转码后的视频的质量。

Description

一种视频转码方法、装置、电子设备及存储介质
本申请要求于2020年07月27日提交中国专利局、申请号为202010730912.X发明名称为“一种视频转码方法、装置、电子设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及视频处理技术领域,特别是涉及一种视频转码方法、装置、电子设备及存储介质。
背景技术
随着互联网技术的发展,视频业务提供商可以通过互联网为用户提供各种各样的视频服务,从而丰富了人们的日常生活和娱乐。然而,由于网络带宽的不稳定性,不同终端的处理能不同,并且,不同的用户对视频的需求也不同,因此,为了适应不同的情况,通常需要对视频进行转码。
目前,在采用相关技术对视频进行转码时,通常是采用预先设置好的固定转码参数,例如:GOP(Group of Pictures,画面组)间隔,对待转码视频进行转码。其中,一个GOP中通常包含一个I帧、至少一个P帧和至少一个B帧,而该I帧是包含完整画面的图像帧,也即关键帧。
然而,本申请申请人发现,采用预先设置好的固定GOP间隔对视频进行转码,获得的转码后的视频的质量不是很高。
发明内容
本申请实施例的目的在于提供一种视频转码方法、装置、电子设备及存储介质,以提高转码后的视频的质量。
具体技术方案如下:
第一方面,本申请实施例提供了一种视频转码方法,该方法包括:获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔;如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一实施方式中,预设差值条件包括:多个GOP间隔相同;根据多个GOP间隔,确定源GOP间隔,包括:将相同的GOP间隔作为源GOP间隔。
在一实施方式中,预设差值条件包括:多个GOP间隔中的任两个GOP间隔的差值小于预设GOP间隔差值阈值;或者多个GOP间隔中的各个GOP间隔与多个GOP间隔的平均值的差值均在预设偏差范围内;根据多个GOP间隔,确定源GOP间隔,包括:将多个GOP间隔的平均值作为源GOP间隔。
在一实施方式中,在获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔之后,该方法还包括:如果多个GOP间隔不满足预设差值条件,则将转码GOP间隔作为目标GOP间隔,执行采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频的步骤。
在一实施方式中,基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,包括:若转码GOP间隔是源GOP间隔的整数倍,或源GOP间隔是转码GOP间隔的整数倍,则将转码GOP间隔确定为目标GOP间隔;若转码GOP间隔位于预设分数倍的源GOP间隔与2倍的源GOP间隔之间,则将源GOP间隔确定为目标GOP间隔。
在一实施方式中,基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,包括:若转码GOP间隔位于k倍的源GOP间隔与k-1倍的源GOP间隔之间,则将k倍的源GOP间隔与k-1倍的源GOP间隔中,最接近转码GOP间隔的值确定为目标GOP间隔;其中,k>=2,且k为整数。
在一实施方式中,基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,包括:若转码GOP间隔小于预设分数倍的源GOP间隔,则将源GOP间隔除以转码GOP间隔,得到计算结果;如果计算结果不为整数,则根据计算结果中的余数和预设分数倍的转码GOP间隔的大小关系,确定目标GOP间隔。
在一实施方式中,根据计算结果中的余数和预设分数倍的转码GOP间隔的大小关系,确定目标GOP间隔,包括:如果余数不大于预设分数倍的转码GOP间隔,则将计算结果中的商数作为目标GOP间隔变化周期m;将转码GOP间隔作为该变化周期中第1至第m-1个目标GOP间隔;将转码GOP间隔与余数之和作为第m个目标GOP间隔;如果余数大于预设分数倍的转码GOP间隔,则将计算结果中的商数加1并作为目标GOP间隔变化周期n;将转码GOP间隔作为该变化周期中第1至第n-1个目标GOP间隔;将余数作为第n个目标GOP间隔;采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频,包括:采用确定出的m个目标GOP间隔,并按照目标GOP间隔变化周期m,对待转码视频进行转码,得到转码后的视频;或者采用确定出的n个目标GOP间隔,并按照目标GOP间隔变化周期n,对待转码视频进行转码,得到转码后的视频。
第二方面,本申请实施例还提供了一种视频转码装置,该装置包括:第一画面组间隔获取模块,设置为获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;第二画面组间隔获取模块,设置为如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;目标画面组间隔确定模块,设置为基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码 视频进行转码的目标GOP间隔;转码模块,设置为采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一实施方式中,预设差值条件包括:多个GOP间隔相同;第二画面组间隔获取模块,设置为:将相同的GOP间隔作为源GOP间隔。
在一实施方式中,预设差值条件包括:多个GOP间隔中的任两个GOP间隔的差值小于预设GOP间隔差值阈值;或者多个GOP间隔中的各个GOP间隔与多个GOP间隔的平均值的差值均在预设偏差范围内,第二画面组间隔获取模块,设置为:将多个GOP间隔的平均值作为源GOP间隔。
在一实施方式中,目标画面组间隔确定模块,还设置为:在获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔之后,如果多个GOP间隔不满足预设差值条件,则将转码GOP间隔作为目标GOP间隔,并触发转码模块进行转码操作。
在一实施方式中,目标画面组间隔确定模块,包括:第一确定子模块,设置为若转码GOP间隔是源GOP间隔的整数倍,或源GOP间隔是转码GOP间隔的整数倍,则将转码GOP间隔确定为目标GOP间隔;第二确定子模块,设置为若转码GOP间隔位于预设分数倍的源GOP间隔与2倍的源GOP间隔之间,则将源GOP间隔确定为目标GOP间隔。
在一实施方式中,目标画面组间隔确定模块,包括:第三确定子模块,设置为若转码GOP间隔位于k倍的源GOP间隔与k-1倍的源GOP间隔之间,则将k倍的源GOP间隔与k-1倍的源GOP间隔中,最接近转码GOP间隔的值确定为目标GOP间隔;其中,k>=2,且k为整数。
在一实施方式中,目标画面组间隔确定模块,包括:计算子模块,设置为若转码GOP间隔小于预设分数倍的源GOP间隔,则将源GOP间隔除以转码GOP间隔,得到计算结果;第四确定子模块,设置为如果计算结果不为整数,则根据计算结果中的余数和预设分数倍的转码GOP间隔的大小关系,确定目标GOP间隔。
在一实施方式中,第四确定子模块,设置为:如果余数不大于预设分数倍的转码GOP间隔,则将计算结果中的商数作为目标GOP间隔变化周期m;将转码GOP间隔作为变化周期m中第1至第m-1个目标GOP间隔;将转码GOP间隔与余数之和作为第m个目标GOP间隔;m为正整数;如果余数大于预设分数倍的转码GOP间隔,则将计算结果中的商数加1并作为目标GOP间隔变化周期n;将转码GOP间隔作为变化周期n中第1至第n-1个目标GOP间隔;将余数作为第n个目标GOP间隔;n为正整数;转码模块,设置为:采用确定出的m个目标GOP间隔,并按照目标GOP间隔变化周期m,对待转码视频进行转码,得到转码后的视频;或者采用确定出的n个目标GOP间隔,并按照目标GOP间隔变化周期 n,对待转码视频进行转码,得到转码后的视频。
第三方面,本申请实施例还提供了一种电子设备,包括处理器和计算机可读存储介质,计算机可读存储介质存储有能够被处理器执行的可执行程序代码,处理器通过读取上述计算机可读存储介质中存储的可执行程序代码来运行与上述可执行程序代码对应的程序,以执行:本申请实施例第一方面所提供的一种视频转码方法。
第四方面,本申请实施例还提供了一种计算机可读存储介质,计算机可读存储介质内存储有可执行程序代码,可执行程序代码被处理器执行时,实现上述第一方面所提供的一种视频转码方法。
第五方面,本申请实施例还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述第一方面所提供的一种视频转码方法。
第六方面,本申请实施例还提供了一种计算机程序,当其在计算机上运行时,使得计算机执行上述第一方面所提供的一种视频转码方法。
本申请实施例提供的一种视频转码方法、装置、电子设备及存储介质,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。当然,实施本申请的任一产品或方法并不一定需要同时达到上述的所有优点。
附图说明
为了更清楚地说明本申请实施例和相关技术的技术方案,下面对实施例和相关技术中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的实施例。
图1为本申请实施例的一种视频转码方法第一种实施方式的流程图;
图2为本申请实施例的一种视频转码方法第二种实施方式的流程图;
图3为本申请实施例的一种视频转码方法第三种实施方式的流程图;
图4为本申请实施例的一种视频转码方法第四种实施方式的流程图;
图5为本申请实施例的一种视频转码装置的结构示意图;
图6为本申请实施例的一种电子设备的结构示意图。
具体实施方式
为使本申请的目的、技术方案、及优点更加清楚明白,以下参照附图并举实施例,对本申请进一步详细说明。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
目前,在采用相关技术在对视频进行转码时,通常是采用预先设置好的固定转码参数,例如,GOP间隔,对待转码视频进行转码。例如,先对待转码视频的每个GOP进行解码,然后采用预先设置好的GOP间隔,对该解码后的视频重新进行编码,从而可以得到转码后的视频。
而由于在对一个GOP进行编解码时,该GOP内的B帧图像和P帧图像通常需要基于该I帧图像进行编解码,因此,该编码后的B帧图像和编码后的P帧图像与对应的原始图像相比,通常是存在误差的。当该编码后的B帧图像和编码后的P帧图像与对应的GOP内的I帧图像距离越远,误差也越大。
因此,当采用预先设置好的GOP间隔对待转码视频进行转码时,则基于预先设置好的GOP间隔重新确定出的GOP的I帧图像可能是待转码视频中的B帧图像或者P帧图像。如果再基于该重新确定出的GOP的I帧图像对对应的B帧图像或P帧图像进行编解码,则会形成误差积累,从而会降低对待转码视频进行重新编码的编码质量,造成获得的转码后的视频的质量不是很高。
为了解决相关技术存在的问题,本申请实施例提供了一种视频转码方法、装置、电子设备及存储介质,以提高转码后的视频的质量。
下面,首先对本申请实施例的一种视频转码方法进行介绍,如图1所示,为本申请实施例的一种视频转码方法第一种实施方式的流程图,该方法可以包括:
S110,获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;
S120,如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
S130,基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;
S140,采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一些示例中,当要对待转码视频进行转码时,可以先对待转码视频进 行解码。在对待转码视频进行解码后,可以得到待转码视频的多个GOP间隔。在一些示例中,该多个GOP间隔的数量不作限定,可以根据经验值预先设置,例如可以设置为60、100或者150等。
在本实施例中,转码GOP间隔是预先设置的。在一些示例中,转码GOP间隔可以是预先设置的通用的转码GOP间隔,也可以针对待转码视频预先设置一个专用的转码GOP间隔。转码GOP间隔设置好后,可以进行保存。在对待转码视频进行转码时,可以直接读取保存的转码GOP间隔。
在获取到该多个GOP间隔和转码GOP间隔后,则可以先判断该多个GOP间隔是否满足预设差值条件,其中,该预设差值条件设置为判断该多个GOP间隔是否相同或相近。
如果满足预设差值条件,则可以根据多个GOP间隔,确定源GOP间隔。
本实施例中,在基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔时,可以基于源GOP间隔和转码GOP间隔的大小关系,直接将源GOP间隔确定为目标GOP间隔;也可以基于源GOP间隔和转码GOP间隔的大小关系,直接将转码GOP间隔确定为目标GOP间隔;也可以基于源GOP间隔和转码GOP间隔的大小关系,对源GOP间隔和转码GOP间隔进行计算,获得目标GOP间隔。
在确定出目标GOP间隔后,则可以采用目标GOP间隔,对待转码视频进行转码,从而可以得到转码后的视频。
本申请实施例提供的一种视频转码方法,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。
在一些示例中,该预设差值条件可以包括:多个GOP间隔相同;对此,在根据多个GOP间隔,确定源GOP间隔时,可以将相同的GOP间隔作为源GOP间隔。
在又一些示例中,该待转码视频的多个GOP间隔可能相同,也可能不相同,因此,上述的预设差值条件还可以包括:多个GOP间隔中的任两个GOP 间隔的差值小于预设GOP间隔差值阈值;或者多个GOP间隔中的各个GOP间隔与多个GOP间隔的平均值的差值均在预设偏差范围内;
在一实施方式中,当该多个GOP间隔不同时,可以判断该多个GOP间隔中的任两个GOP间隔的差值是否小于预设GOP间隔差值阈值,或者判断该多个GOP间隔中的各个GOP间隔与该多个GOP间隔的平均值的差值是否均在预设偏差范围内。
如果多个GOP间隔中的任两个GOP间隔的差值小于预设GOP间隔差值阈值,或者该多个GOP间隔中的各个GOP间隔与该多个GOP间隔的平均值的差值均在预设偏差范围内,则可以说明各个GOP间隔是在该多个GOP间隔的平均值上下的一定范围内小幅度波动,则可以认为该各个GOP间隔相近,因此,可以认为该多个GOP间隔满足预设差值条件,然后将该多个GOP间隔的平均值作为源GOP间隔。
在又一些示例中,该预设偏差范围可以是预先根据经验设置的偏差范围值。
通过本申请实施例,可以在该待转码视频的各个GOP间隔相差较小时,也可以采用本申请实施例视频转码方法来确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,从而可以使得在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频进行转码。相对于相关技术中采用预先设置好的固定GOP间隔对视频进行转码方法,提高了转码后的视频的质量。
在一些示例中,该多个GOP间隔可能相近,也可能存在相差比较大的至少两个GOP间隔,或者存在至少1个GOP间隔与该多个GOP间隔的平均值的差值位于预设偏差范围之外,此时,可以认为该多个GOP间隔不满足预设差值条件,则可以直接将预先设置好的转码GOP间隔作为目标GOP间隔,进而采用该目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一些示例中,在通过图1的步骤S130,基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔时,本申请实施例提供了多种可能的实现方式,如图2、图3和图4所示,为本申请实施例一种视频转码方法中示例性的确定目标转码间隔的实现方式。
如图2所示,为本申请实施例的一种视频转码方法第二种实施方式的流程图,该方法可以包括:
S210,获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;
S220,如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
S230,判断源GOP间隔和转码GOP间隔的大小关系;若转码GOP间隔是 源GOP间隔的整数倍,或源GOP间隔是转码GOP间隔的整数倍,则执行步骤S240,若转码GOP间隔位于预设分数倍的源GOP间隔与2倍的源GOP间隔之间,则执行步骤S250;
S240,将转码GOP间隔确定为目标GOP间隔,并执行步骤S260;
S250,将源GOP间隔确定为目标GOP间隔,并执行步骤S260;
S260,采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一些示例中,在判断源GOP间隔和转码GOP间隔的大小关系时,可以判断转码GOP间隔是否是源GOP间隔的整数倍或者判断源GOP间隔是否是转码GOP间隔的整数倍,如果是,则可以将转码GOP间隔确定为目标GOP间隔。
在又一些示例中,在判断源GOP间隔和转码GOP间隔的大小关系时,还可以判断转码GOP间隔是否位于预设分数倍的源GOP间隔与2倍的源GOP间隔之间,如果是,则可以将源GOP间隔确定为目标GOP间隔。
例如,假设源GOP间隔为N ,转码GOP间隔为N ,目标GOP间隔为N 重置,则可以判断转码GOP间隔N 是否是源GOP间隔N 的整数倍,或者判断源GOP间隔N 是否是转码GOP间隔N 的整数倍,如果是,则可以将转码GOP间隔N 确定为目标GOP间隔N 重置
示例性的,假设N =60,N =20,则确定出的目标GOP间隔N 重置=N =60;又假设N =60,N =180,则确定出的目标GOP间隔N 重置=N =60。
在一些示例中,该源GOP间隔对应的预设分数倍是预先根据经验设置的,例如,可以是1/2倍,此时,则可以判断转码GOP间隔N 是否大于1/2N ,且小于2倍的N 。如果是,则可以将源GOP间隔N 确定为目标GOP间隔N 重置
示例性的,假设N =60,则当30<N <120时,则确定出的目标GOP间隔为源GOP间隔,也即N 重置=N =60。
可以理解的是,本申请实施例中的步骤S210、S220和S260,与本申请实施例的视频转码方法第一种实施方式中的步骤S110、S120和S140相同或相似,这里不再赘述。
如图3所示,为本申请实施例的一种视频转码方法第三种实施方式的流程图,该方法可以包括:
S310,获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;
S320,如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
S330,判断源GOP间隔和转码GOP间隔的大小关系;若转码GOP间隔位于k倍的源GOP间隔与k-1倍的源GOP间隔之间,则执行步骤S340;其中,k>=2, 且k为整数;
S340,将k倍的源GOP间隔与k-1倍的源GOP间隔中,最接近转码GOP间隔的值确定为目标GOP间隔;
S350,采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一些示例中,上述的转码GOP间隔可能是源GOP间隔的整数倍,也可能不是,当该转码GOP间隔不是源GOP间隔的整数倍时,则该转码GOP间隔可能位于k倍的源GOP间隔与k-1倍的源GOP间隔之间。
当该转码GOP间隔位于k倍的源GOP间隔与k-1倍的源GOP间隔之间时,可以先计算k倍的源GOP间隔和k-1倍的源GOP间隔,然后将k倍的源GOP间隔与k-1倍的源GOP间隔中,最接近转码GOP间隔的值确定为目标GOP间隔。
示例性的,假设N =60,N =9,则该N =60位于7倍的N =9和6倍的N =9之间,由于7倍的N 更接近N =60,因此,可以将7倍的N 对应的值63,确定为目标GOP间隔,也即,N 重置=7×N =63。
又假设N =60,N =28,则该N 位于2倍的N 和3倍的N 之间,由于2倍的N 更接近N ,因此,可以将2倍的N 对应的值56,确定为目标GOP间隔,也即,N 重置=2×N =56。
通过本申请实施例,可以在确定目标GOP间隔时,使得确定出目标GOP间隔的I帧图像与待转码视频的多个源GOP间隔中的至少一个GOP间隔的I帧图像相同,并且,与转码GOP间隔接近。从而可以降低误差积累,进而提高对待转码视频进行重新编码的编码质量,以提高获得的转码后的视频的质量。
例如,假设待转码视频的源GOP间隔是10个,则确定出的目标GOP间隔的I帧图像,可能与该源GOP间隔中的第4个GOP间隔的I帧图像相同,也可能与该源GOP间隔中的第6个GOP间隔的I帧图像相同,这样,可以使得在转码时,使用的I帧图像至少与待转码视频的一个原始图像帧相同。
可以理解的是,本申请实施例中的步骤S310、S320和S350,与本申请实施例的视频转码方法第一种实施方式中的步骤S110、S120和S140相同或相似,这里不再赘述。
如图4所示,为本申请实施例的一种视频转码方法第四种实施方式的流程图,该方法可以包括:
S410,获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;
S420,如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
S430,判断源GOP间隔和转码GOP间隔的大小关系;若转码GOP间隔小于预设分数倍的源GOP间隔,则执行步骤S440;
S440,将源GOP间隔除以转码GOP间隔,得到计算结果;如果计算结果不为整数,则执行步骤S450;
S450,根据计算结果中的余数和预设分数倍的转码GOP间隔的大小关系,确定目标GOP间隔;
S460,采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一些示例中,当该转码GOP间隔不是源GOP间隔的整数倍时,则该转码GOP间隔可能小于预设分数倍的源GOP间隔,其中,该源GOP间隔对应的预设分数倍可以是预先根据经验设置的,例如,该源GOP间隔的预设分数倍可以是1/2。则该转码GOP间隔N 可能小于1/2倍的源GOP间隔N
当该转码GOP间隔小于预设分数倍的源GOP间隔时,则可以将源GOP间隔除以转码GOP间隔,得到计算结果,然后判断该计算结果是否为整数。如果不为整数,则可以根据计算结果中的余数和预设分数倍的转码GOP间隔的大小关系,确定目标GOP间隔。然后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
在一些示例中,在根据计算结果中的余数和预设分数倍的转码GOP间隔的大小关系,确定目标GOP间隔时,可以判断计算结果中的余数是否大于预设分数倍的转码GOP间隔;其中,该转码GOP间隔对应的预设分数倍也可以是根据经验设置的,例如,可以设置为1/2。
如果余数不大于预设分数倍的转码GOP间隔,则将计算结果中的商数作为目标GOP间隔变化周期m;将转码GOP间隔作为变化周期m中第1至第m-1个目标GOP间隔;将转码GOP间隔与余数之和作为第m个目标GOP间隔;m为正整数;
然后采用确定出的m个目标GOP间隔,并按照目标GOP间隔变化周期m,对待转码视频进行转码,得到转码后的视频。
如果余数大于预设分数倍的转码GOP间隔,则将计算结果中的商数加1并作为目标GOP间隔变化周期n;将转码GOP间隔作为变化周期n中第1至第n-1个目标GOP间隔;将余数作为第n个目标GOP间隔;n为正整数;
然后采用确定出的n个目标GOP间隔,并按照目标GOP间隔变化周期n,对待转码视频进行转码,得到转码后的视频。
例如,假设N =60,N =149,则该N 小于1/2倍的N ,此时,可以将N =149除以N =60,得到计算结果2和余数29,然后,判断该余数29是否大于1/2倍的转码GOP间隔N =60,如果否,则可以将2作为目标GOP间隔变化周期,将转码GOP间隔作为该变化周期中第1个目标GOP间隔,将转码GOP间隔N =60与余数29之和89作为第2个目标GOP间隔。
最后,采用确定出的2个目标GOP间隔60和89,按照目标GOP间隔变化周期2,对待转码视频进行转码,从而可以得到转码后的视频。在一实施方式中,先采用确定出的2个目标GOP间隔60和89,并按照目标GOP间隔变化周期,将该待转码视频分为多个待转码GOP,然后分别对每个待转码GOP进行转码。
在将待转码视频分为多个待转码GOP时,是先采用第一个目标GOP间隔60分出一个GOP,然后采用第二个目标GOP间隔89分出一个GOP,再采用第一个目标GOP间隔60分出一个GOP,…,依次循环,从而可以实现按照目标GOP间隔变化周期,将该待转码视频分为多个待转码GOP。
又例如,假设N =60,N =153,则该N 小于1/2倍的N ,此时,可以将N =153除以N =60,得到计算结果2和余数33,然后,判断该余数33是否大于1/2倍的转码GOP间隔N =60,如果是,则可以将2加上1作为目标GOP间隔变化周期,将转码GOP间隔作为该变化周期中第1个目标GOP间隔和第二个目标GOP间隔,将余数33作为第3个目标GOP间隔。
最后,采用确定出的3个目标GOP间隔60、60和33,按照目标GOP间隔变化周期3,对待转码视频进行转码,从而可以得到转码后的视频。
通过本申请实施例,可以在确定目标GOP间隔时,使得确定出的目标GOP间隔的I帧图像与待转码视频的多个源GOP间隔中的至少一个GOP间隔的I帧图像相同,并且,与转码GOP间隔相同。从而可以降低误差积累,进而提高对待转码视频进行重新编码的编码质量,以提高获得的转码后的视频的质量。
可以理解的是,本申请实施例中的步骤S410、S420和S460,与本申请实施例的视频转码方法第一种实施方式中的步骤S110、S120和S140相同或相似,这里不再赘述。
在本申请实施例的一种可能的实现方式中,当采用程序来执行步骤S130,基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔时,假设源GOP间隔的预设分数倍为1/2,转码GOP间隔的预设分数倍也为1/2,则图2、图3以及图4所示的确定对待转码视频进行转码的目标GOP间隔的方式可以是如下表示方式:
如果N =k×N ,则N 重置=N
如果N ≠k×N ,且(k×N -N )≤N -(k-1)×N ,则N 重置=k×N
如果N ≠k×N ,且N -(k-1)×N ≤(k×N -N ),则N 重置=(k-1)×N
如果
Figure PCTCN2021090639-appb-000001
则N 重置=N
如果N =k×N ,则N 重置=N
如果N ≠k×N ,且
Figure PCTCN2021090639-appb-000002
Figure PCTCN2021090639-appb-000003
其中,r为上述的目标GOP间隔变化周期m或n,1≤i≤r,
Figure PCTCN2021090639-appb-000004
满足以下条件:
Figure PCTCN2021090639-appb-000005
需要说明的是,上述视频转码方法可以应用于任意一种具有视频转码功能的电子设备中。例如,可以应用于用户终端,也可以应用于服务器。
当应用于用户终端时,可以是线下转码,也可以是线上转码。对于线下转码而言,上述视频转码方法可以集成在一个线下视频转码工具中;在用户终端安装有该视频转码工具的情况下,用户可以将需要转码的视频文件上传到该视频转码工具中进行转码,并输出转码结果供用户使用。对于线上转码而言,上述视频转码方法可以集成在一个具有视频播放功能的软件中;在用户终端安装有该软件的情况下,该软件在从服务器获取到视频流后,可以使用上述方法对该视频流进行转码,再进行视频播放操作。
当应用于服务器时,用户终端可以向服务器发送携带视频格式的视频流获取请求;服务器接收到该请求后,若确定原始视频流的格式与该请求中携带的视频格式不同,则可以使用上述方法先对视频流进行转码操作,再将转码后的视频流发送给用户终端进行播放。
相应于上述的方法实施例,本申请实施例还提供了一种视频转码装置,如图5所示,为本申请实施例一种视频转码装置的结构示意图,该装置可以包括:
第一画面组间隔获取模块510,设置为获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;
第二画面组间隔获取模块520,设置为如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
目标画面组间隔确定模块530,设置为基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;
转码模块540,设置为采用目标GOP间隔,对待转码视频进行转码,得到 转码后的视频。
本申请实施例提供的一种视频转码装置,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。
在一些示例中,预设差值条件包括:多个GOP间隔相同;第二画面组间隔获取模块520,设置为:将相同的GOP间隔作为源GOP间隔;
在一些示例中,预设差值条件包括:多个GOP间隔中的任两个GOP间隔的差值小于预设GOP间隔差值阈值;或者多个GOP间隔中的各个GOP间隔与多个GOP间隔的平均值的差值均在预设偏差范围内,第二画面组间隔获取模块520,设置为:
将多个GOP间隔的平均值作为源GOP间隔。
在一些示例中,目标画面组间隔确定模块530,还设置为:
在获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔之后,如果多个GOP间隔不满足预设差值条件,则将转码GOP间隔作为目标GOP间隔,并触发转码模块540进行转码操作。
在一些示例中,目标画面组间隔确定模块530,包括:
第一确定子模块,设置为若转码GOP间隔是源GOP间隔的整数倍,或源GOP间隔是转码GOP间隔的整数倍,则将转码GOP间隔确定为目标GOP间隔;
第二确定子模块,设置为若转码GOP间隔位于预设分数倍的源GOP间隔与2倍的源GOP间隔之间,则将源GOP间隔确定为目标GOP间隔。
在一些示例中,目标画面组间隔确定模块530,包括:
第三确定子模块,设置为若转码GOP间隔位于k倍的源GOP间隔与k-1倍的源GOP间隔之间,则将k倍的源GOP间隔与k-1倍的源GOP间隔中,最接近转码GOP间隔的值确定为目标GOP间隔;其中,k>=2,且k为整数。
在一些示例中,目标画面组间隔确定模块530,包括:
计算子模块,设置为若转码GOP间隔小于预设分数倍的源GOP间隔,则将源GOP间隔除以转码GOP间隔,得到计算结果;
第四确定子模块,设置为如果计算结果不为整数,则根据计算结果中的余数和预设分数倍的转码GOP间隔的大小关系,确定目标GOP间隔。
在一些示例中,第四确定子模块,设置为:
如果余数不大于预设分数倍的转码GOP间隔,则将计算结果中的商数作为目标GOP间隔变化周期m;将转码GOP间隔作为变化周期m中第1至第m-1个目标GOP间隔;将转码GOP间隔与余数之和作为第m个目标GOP间隔;m为正整数;
如果余数大于预设分数倍的转码GOP间隔,则将计算结果中的商数加1并作为目标GOP间隔变化周期n;将转码GOP间隔作为变化周期n中第1至第n-1个目标GOP间隔;将余数作为第n个目标GOP间隔;n为正整数;
转码模块540,设置为:
采用确定出的m个目标GOP间隔,并按照目标GOP间隔变化周期m,对待转码视频进行转码,得到转码后的视频;或者
采用确定出的n个目标GOP间隔,并按照目标GOP间隔变化周期n,对待转码视频进行转码,得到转码后的视频。
本申请实施例还提供了一种电子设备,如图6所示,为本申请实施例的一种视频转码方法应用于电子设备的结构示意图,该电子设备可以包括处理器601和计算机可读存储介质602,计算机可读存储介质602存储有能够被处理器601执行的可执行程序代码,处理器601通过读取上述计算机可读存储介质中存储的可执行程序代码来运行与上述可执行程序代码对应的程序,以执行:本申请实施例所提供的一种视频转码方法;例如,可以执行如下步骤:
获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔;
如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;
采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
上述的计算机可读存储介质602可以包括随机存取存储器(Random Access Memory,RAM),也可以包括非易失性存储器(Non-Volatile Memory,NVM),例如至少一个磁盘存储器。在一实施方式中,存储器还可以是至少一个位于远离前述处理器的存储装置。
上述的处理器601可以是通用处理器,包括中央处理器(Central Processing Unit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(Digital Signal Processing,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array, FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。
当然,上述处理器通过读取上述计算机可读存储介质中存储的可执行程序代码来运行与上述可执行程序代码对应的程序,还能够执行本申请实施例所提供的一种网卡模式切换方法的任意步骤。
本申请实施例提供的一种电子设备,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质内存储有可执行程序代码,该可执行程序代码被处理器执行时,实现本申请实施例所提供的一种视频转码方法,例如,可以实现如下步骤:
获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔;
如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;
采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
本申请实施例提供的一种计算机可读存储介质,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。
本申请实施例还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行本申请实施例所提供的一种视频转码方法,例如,可以执行如下步骤:
获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔;
如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;
采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
本申请实施例提供的一种包含指令的计算机程序产品,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。
本申请实施例还提供了一种计算机程序,当其在计算机上运行时,使得计算机执行本申请实施例所提供的一种视频转码方法,例如,可以执行如下步骤:
获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔;
如果多个GOP间隔满足预设差值条件,则根据多个GOP间隔,确定源GOP间隔;
基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;
采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。
本申请实施例提供的一种计算机程序,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确 定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。
对于视频转码装置/电子设备/计算机可读存储介质/计算机程序产品/计算机程序的实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括要素的过程、方法、物品或者设备中还存在另外的相同要素。
本说明书中的各个实施例均采用相关的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
以上所述仅为本申请的较佳实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本申请保护的范围之内。
工业实用性
基于本申请实施例提供的一种视频转码方法、装置、电子设备及存储介质,在对待转码视频转码时,先获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;然后判断多个GOP间隔是否满足预设差值条件,如果满足,则根据多个GOP间隔,确定源GOP间隔;并基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔;最后采用目标GOP间隔,对待转码视频进行转码,得到转码后的视频。由于先基于源GOP间隔和转码GOP间隔的大小关系,确定对待转码视频进行转码的目标GOP间隔,再用目标GOP间隔对待转码视频进行转码,也就是在确定目标GOP间隔时,考虑了源GOP间隔,因此能够适应对不同源GOP间隔的不同视频的转码。相对于相关技术中采用预先设置好的固定的转码GOP间隔对视频进行转码的方法,提高了转码后的视频的质量。

Claims (20)

  1. 一种视频转码方法,所述方法包括:
    获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔;
    如果所述多个GOP间隔满足预设差值条件,则根据所述多个GOP间隔,确定源GOP间隔;
    基于所述源GOP间隔和所述转码GOP间隔的大小关系,确定对所述待转码视频进行转码的目标GOP间隔;
    采用所述目标GOP间隔,对所述待转码视频进行转码,得到转码后的视频。
  2. 根据权利要求1所述的方法,其中,所述预设差值条件包括:所述多个GOP间隔相同;根据所述多个GOP间隔,确定源GOP间隔,包括:
    将相同的GOP间隔作为所述源GOP间隔。
  3. 根据权利要求1所述的方法,其特征在于,所述预设差值条件包括:所述多个GOP间隔中的任两个GOP间隔的差值小于预设GOP间隔差值阈值;或者所述多个GOP间隔中的各个GOP间隔与所述多个GOP间隔的平均值的差值均在预设偏差范围内;所述根据所述多个GOP间隔,确定源GOP间隔,包括:
    将所述多个GOP间隔的平均值作为所述源GOP间隔。
  4. 根据权利要求2或3所述的方法,其中,在所述获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔之后,所述方法还包括:
    如果所述多个GOP间隔不满足所述预设差值条件,则将所述转码GOP间隔作为所述目标GOP间隔,执行所述采用所述目标GOP间隔,对所述待转码视频进行转码,得到转码后的视频的步骤。
  5. 根据权利要求1所述的方法,其中,所述基于所述源GOP间隔和所述转码GOP间隔的大小关系,确定对所述待转码视频进行转码的目标GOP间隔,包括:
    若所述转码GOP间隔是所述源GOP间隔的整数倍,或所述源GOP间隔是所述转码GOP间隔的整数倍,则将所述转码GOP间隔确定为所述目标GOP间隔;
    若所述转码GOP间隔位于预设分数倍的所述源GOP间隔与2倍的所述源GOP间隔之间,则将所述源GOP间隔确定为目标GOP间隔。
  6. 根据权利要求1所述的方法,其中,所述基于所述源GOP间隔和所述转码GOP间隔的大小关系,确定对所述待转码视频进行转码的目标GOP间隔,包括:
    若所述转码GOP间隔位于k倍的所述源GOP间隔与k-1倍的所述源GOP间隔之间,则将k倍的所述源GOP间隔与k-1倍的所述源GOP间隔中,最接近所述转码GOP间隔的值确定为所述目标GOP间隔;其中,k>=2,且所述k为整数。
  7. 根据权利要求1所述的方法,其中,所述基于所述源GOP间隔和所述转码GOP间隔的大小关系,确定对所述待转码视频进行转码的目标GOP间隔,包括:
    若所述转码GOP间隔小于预设分数倍的所述源GOP间隔,则将所述源GOP间隔除以所述转码GOP间隔,得到计算结果;
    如果所述计算结果不为整数,则根据所述计算结果中的余数和预设分数倍的所述转码GOP间隔的大小关系,确定所述目标GOP间隔。
  8. 根据权利要求7所述的方法,其中,所述根据所述计算结果中的余数和预设分数倍的所述转码GOP间隔的大小关系,确定所述目标GOP间隔,包括:
    如果所述余数不大于所述预设分数倍的所述转码GOP间隔,则将所述计算结果中的商数作为所述目标GOP间隔变化周期m;将所述转码GOP间隔作为所述变化周期m中第1至第m-1个目标GOP间隔;将所述转码GOP间隔与所述余数之和作为第m个目标GOP间隔;所述m为正整数;
    如果所述余数大于所述预设分数倍的所述转码GOP间隔,则将所述计算结果中的商数加1并作为所述目标GOP间隔变化周期n;将所述转码GOP间隔作为所述变化周期n中第1至第n-1个目标GOP间隔;将所述余数作为第n个目标GOP间隔;所述n为正整数;
    所述采用所述目标GOP间隔,对所述待转码视频进行转码,得到转码后的视频,包括:
    采用确定出的m个目标GOP间隔,并按照所述目标GOP间隔变化周期m,对所述待转码视频进行转码,得到转码后的视频;或者,
    采用确定出的n个目标GOP间隔,并按照所述目标GOP间隔变化周期n,对所述待转码视频进行转码,得到转码后的视频。
  9. 一种视频转码装置,所述装置包括:
    第一画面组间隔获取模块,设置为获取待转码视频的多个GOP间隔和预先设置的转码GOP间隔;
    第二画面组间隔获取模块,设置为如果所述多个GOP间隔满足预设差值条件,则根据所述多个GOP间隔,确定源GOP间隔;
    目标画面组间隔确定模块,设置为基于所述源GOP间隔和所述转码GOP间隔的大小关系,确定对所述待转码视频进行转码的目标GOP间隔;
    转码模块,设置为采用所述目标GOP间隔,对所述待转码视频进行转码,得到转码后的视频。
  10. 根据权利要求9所述的装置,其中,所述预设差值条件包括:所述多个GOP间隔相同;所述第二画面组间隔获取模块,还设置为:
    将相同的GOP间隔作为所述源GOP间隔。
  11. 根据权利要求9所述的装置,其中,所述预设差值条件包括:所述多个GOP间隔中的任两个GOP间隔的差值小于预设GOP间隔差值阈值;或者所述多个GOP间隔中的各个GOP间隔与所述多个GOP间隔的平均值的差值均在预设偏差范围内,所述第二画面组间隔获取模块,还设置为:
    将所述多个GOP间隔的平均值作为所述源GOP间隔。
  12. 根据权利要求10或11所述的装置,其中,所述目标画面组间隔确定模块,还设置为:
    在所述获取待转码视频的多个画面组GOP间隔和预先设置的转码GOP间隔之后,如果所述多个GOP间隔不满足所述预设差值条件,则将所述转码GOP间隔作为所述目标GOP间隔,并触发所述转码模块进行转码操作。
  13. 根据权利要求9所述的装置,其中,所述目标画面组间隔确定模块,包括:
    第一确定子模块,设置为若所述转码GOP间隔是所述源GOP间隔的整数倍,或所述源GOP间隔是所述转码GOP间隔的整数倍,则将所述转码GOP间隔确定为所述目标GOP间隔;
    第二确定子模块,设置为若所述转码GOP间隔位于预设分数倍的所述源GOP间隔与2倍的所述源GOP间隔之间,则将所述源GOP间隔确定为目标GOP间隔。
  14. 根据权利要求9所述的装置,其中,所述目标画面组间隔确定模块,包括:
    第三确定子模块,设置为若所述转码GOP间隔位于k倍的所述源GOP间隔与k-1倍的所述源GOP间隔之间,则将k倍的所述源GOP间隔与k-1倍的所述源GOP间隔中,最接近所述转码GOP间隔的值确定为所述目标GOP间隔;其中,k>=2,且所述k为整数。
  15. 根据权利要求9所述的装置,其中,所述目标画面组间隔确定模块,包括:
    计算子模块,设置为若所述转码GOP间隔小于预设分数倍的所述源GOP间隔,则将所述源GOP间隔除以所述转码GOP间隔,得到计算结果;
    第四确定子模块,设置为如果所述计算结果不为整数,则根据所述计算 结果中的余数和预设分数倍的所述转码GOP间隔的大小关系,确定所述目标GOP间隔。
  16. 根据权利要求15所述的装置,其中,所述第四确定子模块,还设置为:
    如果所述余数不大于所述预设分数倍的所述转码GOP间隔,则将所述计算结果中的商数作为所述目标GOP间隔变化周期m;将所述转码GOP间隔作为所述变化周期m中第1至第m-1个目标GOP间隔;将所述转码GOP间隔与所述余数之和作为第m个目标GOP间隔;所述m为正整数;
    如果所述余数大于所述预设分数倍的所述转码GOP间隔,则将所述计算结果中的商数加1并作为所述目标GOP间隔变化周期n;将所述转码GOP间隔作为所述变化周期n中第1至第n-1个目标GOP间隔;将所述余数作为第n个目标GOP间隔;所述n为正整数;
    所述转码模块,还设置为:
    采用确定出的m个目标GOP间隔,并按照所述目标GOP间隔变化周期m,对所述待转码视频进行转码,得到转码后的视频;或者,
    采用确定出的n个目标GOP间隔,并按照所述目标GOP间隔变化周期n,对所述待转码视频进行转码,得到转码后的视频。
  17. 一种电子设备,包括处理器和计算机可读存储介质,所述计算机可读存储介质存储有能够被所述处理器执行的可执行程序代码,所述处理器通过读取所述计算机可读存储介质中存储的可执行程序代码来运行与上述可执行程序代码对应的程序,以执行:权利要求1~8任一项所述的方法步骤。
  18. 一种计算机可读存储介质,所述计算机可读存储介质内存储有可执行程序代码,所述可执行程序代码被处理器执行时,实现权利要求1~8任一项所述的方法步骤。
  19. 一种包含可执行程序代码的计算机程序产品,所述可执行程序代码在计算机上运行时,使得计算机执行:权利要求1-8任一所述的方法步骤。
  20. 一种计算机程序,所述计算机程序在计算机上运行时,使得计算机执行:权利要求1-8任一所述的方法步骤。
PCT/CN2021/090639 2020-07-27 2021-04-28 一种视频转码方法、装置、电子设备及存储介质 WO2022021973A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010730912.X 2020-07-27
CN202010730912.XA CN111787328B (zh) 2020-07-27 2020-07-27 一种视频转码方法、装置、电子设备及存储介质

Publications (1)

Publication Number Publication Date
WO2022021973A1 true WO2022021973A1 (zh) 2022-02-03

Family

ID=72764240

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/090639 WO2022021973A1 (zh) 2020-07-27 2021-04-28 一种视频转码方法、装置、电子设备及存储介质

Country Status (2)

Country Link
CN (1) CN111787328B (zh)
WO (1) WO2022021973A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111787328B (zh) * 2020-07-27 2022-11-04 北京金山云网络技术有限公司 一种视频转码方法、装置、电子设备及存储介质

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101917612A (zh) * 2009-12-17 2010-12-15 新奥特(北京)视频技术有限公司 一种流媒体视频编码方法及装置
CN103220550A (zh) * 2012-01-19 2013-07-24 华为技术有限公司 视频转换的方法及装置
CN103702138A (zh) * 2013-11-29 2014-04-02 乐视网信息技术(北京)股份有限公司 自适应指定转码的方法和系统
US9544664B1 (en) * 2011-06-08 2017-01-10 Arris Enterprises, Inc. Group of pictures size adjustment
US20180139479A1 (en) * 2012-01-31 2018-05-17 Comcast Cable Communications, Llc System And Method For Data Stream Fragmentation
CN111787328A (zh) * 2020-07-27 2020-10-16 北京金山云网络技术有限公司 一种视频转码方法、装置、电子设备及存储介质

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110062262B (zh) * 2019-04-12 2022-05-03 北京字节跳动网络技术有限公司 视频数据的转码控制方法、装置、电子设备和存储介质
CN110784718B (zh) * 2019-10-31 2021-07-20 广州市网星信息技术有限公司 视频数据编码方法、装置、设备和存储介质

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101917612A (zh) * 2009-12-17 2010-12-15 新奥特(北京)视频技术有限公司 一种流媒体视频编码方法及装置
US9544664B1 (en) * 2011-06-08 2017-01-10 Arris Enterprises, Inc. Group of pictures size adjustment
CN103220550A (zh) * 2012-01-19 2013-07-24 华为技术有限公司 视频转换的方法及装置
US20180139479A1 (en) * 2012-01-31 2018-05-17 Comcast Cable Communications, Llc System And Method For Data Stream Fragmentation
CN103702138A (zh) * 2013-11-29 2014-04-02 乐视网信息技术(北京)股份有限公司 自适应指定转码的方法和系统
CN111787328A (zh) * 2020-07-27 2020-10-16 北京金山云网络技术有限公司 一种视频转码方法、装置、电子设备及存储介质

Also Published As

Publication number Publication date
CN111787328A (zh) 2020-10-16
CN111787328B (zh) 2022-11-04

Similar Documents

Publication Publication Date Title
US20190297327A1 (en) Video encoding processing method, computer device and storage medium
US10187680B2 (en) Adaptive bit rate system architectures using named domain networking
US9271003B2 (en) Real-time audio or video transcoding
CN110446072B (zh) 视频流切换方法、电子设备和存储介质
CN110546953B (zh) 复杂度自适应单程转码与双程转码
US8892764B1 (en) Dynamic selection of parameter sets for transcoding media data
US9420282B2 (en) Video coding redundancy reduction
WO2022042156A1 (zh) 基于场景切换的图像组划分方法及装置、视频编码方法及装置
SE529152C2 (sv) Bestämning av antalet enkelriktade och dubbelriktade rörelsekompenserade bildrutor som ska kodas för en videosekvens och upptäckning av scenklipp i videosekvensen
CN110582012B (zh) 视频切换方法、视频处理方法、装置及存储介质
US11611789B2 (en) Adaptive bitrate streaming
US11356739B2 (en) Video playback method, terminal apparatus, and storage medium
US10819951B2 (en) Recording video from a bitstream
WO2022021973A1 (zh) 一种视频转码方法、装置、电子设备及存储介质
WO2023226915A1 (zh) 视频传输方法、系统、设备及存储介质
US20240187548A1 (en) Dynamic resolution switching in live streams based on video quality assessment
US20130007206A1 (en) Transmission apparatus, control method for transmission apparatus, and storage medium
CN114430488A (zh) 一种视频编码和视频解码的方法及装置
US11334979B2 (en) System and method to detect macroblocking in images
WO2017018072A1 (ja) 配信レート選択装置、配信レート選択方法、及びプログラム
CN107277650B (zh) 视频文件切割方法及装置
JP2008311824A (ja) 画像符号化装置および画像符号化プログラム
US20180367792A1 (en) Imaging apparatus, processing method for imaging apparatus, and storage medium
CN110855619A (zh) 播放音视频数据的处理方法、装置、存储介质及终端设备
Nicholls et al. Scalable video by software

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21850854

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21850854

Country of ref document: EP

Kind code of ref document: A1