FFmpeg converts one image and one MP3 audio file into MP4

Source: Internet
Author: User

The company's project needs to merge one image and one MP3 audio file into MP4 and play the video on HTML5. It was originally thought to be a very simple matter, so a simple FFMPEG command was quickly written for execution.

FFmpeg-I 2.mp3-F image2-I 3.jpg-acodec AAC-strict-2-vcodec libx264-ar 22050-AB 128 K-AC 2-y 4.mp4

At the beginning, the merged MP4 video can be played on HTML5, but the problem arises. When I change an image, I find that the video cannot be played and the video format is incorrect. After that, I tried to change a lot of images, but some were unsuccessful.

I click on the right-click button to view the images. All the examples are the same. jpg, 300px * 300px, and 96 DPI.

After checking for a long time, I did not find the cause. Finally, I used FFMPEG to view the image parameters to find the problem.

FFmpeg command for viewing Image Parameters FFMPEG-I 3.jpg

650) This. length = 650; "src =" http://s3.51cto.com/wyfs02/M02/4D/5F/wKiom1RQWoqiHz2DAAB8Lt0ZO40720.jpg "Title =" 1.png" width = "626" Height = "77" border = "0" hspace = "0" vspace = "0" style = "width: 626px; Height: 77px; "alt =" wkiom1rqwoqihz2daab8lt0zo407108jpg "/>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/4D/5F/wKioL1RQW9CDOpKVAAC4yw98LvE746.jpg "Title =" 2.png" alt = "wkiol1rqw9cdopkvaac4yw98lve746.jpg"/>

In comparison, it is found that there is a different parameter, that is, yuvj420p.

Main YUV sampling formats
The main sampling formats are YCbCr, and YCbCr. YCbCr is commonly used. It means that each vertex stores an 8-bit brightness value (that is, the Y value), and each 2x2 points stores a Cr and CB value, the image does not feel much changed to the naked eye. Therefore, the original RGB (R, G, and B are all 8bit unsigned) models, 4 points require 8x3 = 24 bites (such as the first figure ). Now, we only need 8 + (8/4) + (8/4) = 12 bites, and each point occupies 12 bites on average (such as the second figure ). In this way, the image data is halved.
The above only provides a theoretical example, which may be different in actual data storage. Below are several specific storage formats:
(1) YUV 4: 4
The sampling rate of the three channels of YUV is the same. Therefore, in the generated image, the information of the three components of each pixel is complete (each component is usually 8 bits). After 8 bits quantization, each uncompressed pixel occupies 3 bytes.
The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]
The stored code stream is y0 U0 V0 Y1 U1 V1 Y2 U2 V2 Y3 U3 v3
(2) YUV
The sampling rate of each chromatic aberration channel is half of the brightness channel, so the color sampling rate in the horizontal direction is only half. For non-compressed 8-bit quantization images, each macro pixel consisting of two adjacent horizontal pixels occupies 4 bytes of memory.
The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]
The stored code stream is y0 U0 Y1 V1 Y2 U2 Y3 v3
The mapped pixel is: [y0 U0 V1] [Y1 U0 V1] [Y2 U2 V3] [Y3 U2 V3]
(3) YUV
The color sampling at is a sample of the color in the horizontal direction. This is acceptable for low-end users and consumer products. For a non-compressed 8-bit video, each macro pixel consisting of four adjacent horizontal pixels occupies 6 bytes of memory.
The following four pixels are: [y0 U0 V0] [Y1 U1 V1] [Y2 U2 V2] [Y3 U3 V3]
The stored code stream is y0 U0 Y1 Y2 V2 Y3.
The mapped pixel is: [y0 U0 V2] [Y1 U0 V2] [Y2 U0 V2] [Y3 U0 V2]
(4) yuv4: 2: 0
Doesn't mean only y, CB, and no Cr component. It means that for each scanned line, only one color component is stored at a sampling rate of 2 to 1. Perform a line-by-line scan. The adjacent scan rows store different color components. That is to say, if a row is, the next row is, And the next row is... And so on. For each color component, the sampling rate in both the horizontal and vertical directions is, so the color sampling rate is. For non-compressed 8-bit quantization videos, each macro pixel consisting of 2x2, 2 rows, and 2 columns of adjacent pixels occupies 6 bytes of memory.

Finally, add the FFMPEG video conversion command with the yuvj420p parameter.

Ffmpeg-i 2.mp3-F image2-I 3.jpg-acodec AAC-strict-2-vcodec libx264-ar 22050-AB 128 K-AC 2-pix_fmt yuvj420p-y 4.mp4

The transcoded MP4 is OK.






FFmpeg converts one image and one MP3 audio file into MP4

Contact Us

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

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

A Free Trial That Lets You Build Big!

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

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

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