Introduction to video format and encoding

Today, I encountered a format problem when writing a video uploaded on a website, so I learned about the related concepts of video format and encoding. Here is a summary.

The difference between video format and video encoding

The first thing to be clear is that video format and video encoding are actually two concepts.

Like AVI, MP4are actually video formats , and H.264, H.265are video encoding formats .

H.264Also called AVC, H.265also called HEVC. You can remember this, because it is often mentioned, but it is actually talking about the same thing.

container format

A video format is actually a container format used to organize various types of data streams. Like the container format for ZIParchive files ( archive filesMP4 ), and the container format just mentioned above is for multimedia playback.

The general video container format contains audio data in different formats, but more advanced container formats can also contain multiple audio and video streams, subtitles, metadata (such as audio and video encoding formats), and audio and video synchronization information.

In addition, although the container format contains different data streams, most container formats are designed for specific data requirements, so the container format name already implies what software should be used to open the data stored in the file, such as MP4sure It is a video file.

Most of the above is the Wikipedia of the container format for reference, here is the link: Container format .

Learn more about video encoding

As mentioned above, the container format only specifies how to store multiple types of data, but does not limit the type of data, so even if it is a file of the same video format, the video encoding format inside may be completely different. This results in all possible MP4files, but some can be played on the browser, and some cannot, because their video encoding formats are different.

Due to some historical reasons (mainly because some video codec formats have patent fees, that is, you have to pay to use the codec tools invented by others), major browser manufacturers do not have a uniformly supported video encoding format. Major browser vendors support the following:

As you can see from the picture above, for MP4this type of video format, these browsers only support H264and AACencode video, so if you upload a H.265video encoded by .mp4, it cannot be played, because the browser does not support.

View video encoding format

Through the FFmpeg tool, we can view the relevant data of the corresponding video file:

FFmpeg is a very commonly used video processing tool with many powerful functions, here is the download link: FFmpeg .

ffprobe test.mp4 -show_streams -select_streams v -print_format json
# test.mp4可以改成对应文件名

Some results are shown above. We can see that most of the keys contain codeckeywords. This is a compound word of coder and decoder, which means a codec. It is mainly used to indicate what the video encoding format is. We can see that it is h264.

In addition, we can also see a codec_tagkey, which is codeca piece of information used to supplement information, because usually a key codechas a lot of information, here codec_tagit is used to indicate the encapsulation format of video encoding, we can see that it is avc1. When I uploaded the video of the video today, the browser could not play it because the video encoding format was h264not .avc1

For the difference between avc1and h264, you can see this answer: The difference between avc1 and h264

Toggle codec_tag

For the above situation, the FFmpeg tool can also handle it, converting the tag of the specified H.264 video to avc1:

ffmpeg -i source.mp4 -c:v copy -tag:v avc1 -c:a copy target.mp4
# source.mp4和target.mp4可以改成对于文件名

reference link

  1. What is Codec Tag?
  2. FFmpeg video processing introductory tutorial

Guess you like

Origin blog.csdn.net/weixin_55658418/article/details/129643965