C#, practical code, essential functions for organizing video files, methods and source programs for extracting summary information of video files such as avi, mpeg, mp4, rmvb, mkv, flv, etc.

This article briefly introduces video files such as avi, mpeg, mp4, rmvb, mkv, flv, etc., and gives the C# source code for extracting the summary information (resolution, duration) of these files with the open source ffmpeg program.

1. Introduction to Video Files

1.1 AVI (*.avi file)

The full name of AVI in English is Audio Video Interleaved, which is the audio and video interleaved format. It is a multimedia container format launched by Microsoft in November 1992 as part of its Windows video software.
AVI files contain audio (voice) and video (image) data in a file container, allowing audio and video to be played back synchronously. Similar to the DVD-Video format, AVI files support multiple audio and video streams. AVI information is mainly used on multimedia discs to save various image information such as TV and movies.
It was launched by Microsoft Corporation in 1992, and it has been recognized and known by people along with Windows 3.1. The so-called "audio and video interleaving" means that video and audio can be interleaved together for synchronous playback. The advantage of this video format is that it can be used across multiple platforms, but its disadvantage is that the volume is too large, and what is worse is that the compression standard is not uniform. The most common phenomenon is that the high-version Windows media player cannot play AVI edited with early encoding. format video, and the lower version of Windows Media Player cannot play the AVI format video edited with the latest encoding, so when we play some AVI format videos, the video cannot be played or even can be played due to video encoding problems. However, there are some inexplicable problems such as the inability to adjust the playback progress and only sound but no image during playback. If users encounter these problems when playing AVI format video, they can be solved by downloading the corresponding decoder. AVI is a common packaging format for video files, such as titles of some games, educational software, and multimedia discs, there will be many AVIs. AVI can be played directly in all versions of the Windows operating system, and there are several formats of its own, the most common one is Intel Indeo(R) Video R3.2. Microsoft video etc.
AVI contains three parts: file header, data block and index block.
The data block contains the actual data stream, that is, image and sound sequence data. This is the main body of the file and the main part that determines the size of the file. The size of a video file is equal to the data rate of the file multiplied by the playing time of the video, and the index block includes a list of data blocks and their positions in the file to provide random access to data in the file. The file header includes the general information of the file, defines the data format, and parameters such as the compression algorithm used.
nAVI format
nAVI is the abbreviation of newAVI, which is a new video format developed by an underground organization called ShadowRealm (not much related to the AVI format we mentioned above). It is derived from the modification of the Microsoft ASF compression algorithm, but it is different from the ASF video format in the network image video described below. It sacrifices the video "streaming" characteristics of the original ASF video file and increases the number of frames. rate to greatly improve the clarity of ASF video files.
The full English name of DV is Digital Video Format, which is a home digital video format jointly proposed by Sony, Panasonic, JVC and other manufacturers. Digital video cameras use this format to record video data. It can transmit video data to the computer through the IEEE 1394 interface of the computer, and can also record the edited video data in the computer to the digital video camera. The file extension of this video format is generally .avi, so it is also called DV-AVI format.
In October 2007, the reason for the inversion of AVI images was likely to be the conflict between Baofengyingyin and Windows Media Player, which could be resolved by downloading a complete DVIX decoder.
In early 1992, Microsoft launched the AVI technology and its application software VFW (Video for Windows). In AVI files, moving image and audio data are interleaved and stored independently of hardware devices. This way of organizing audio and video data in an alternating manner can make it possible to obtain continuous information from the storage medium more efficiently when reading the video data stream. The main parameters that constitute an AVI file include video parameters, audio parameters and compression parameters, etc.:
AVI is not as complicated as MPEG, and it has been around since the Windows 3.1 era. Its most direct advantages are good compatibility, convenient calling and good image quality, so it is often matched with DVD. But its shortcoming is also very obvious: bulky. It is also because of this that we have seen the birth of MPEG-1 and MPEG-4. The size of the AVI file of 2-hour video is almost the same as that of MPEG-2, but this is only for the standard resolution: according to different application requirements, the resolution of AVI can be adjusted at will. The larger the window, the larger the data volume of the file. Reducing the resolution can greatly reduce its size, but the image quality will inevitably suffer. When the size of the MPEG-2 format file is similar, the video quality of the AVI format is relatively inferior, but the requirements for computer configuration are not high when making it. People often record the video in the AVI format first, and then convert it to other formats.

1.2 MPEG and MPEG4 (*.mp4 files)

MPEG (Moving Picture Experts Group) is an organization established in 1988 by ISO (International Standardization Organization) and IEC (International Electrotechnical Commission) to formulate international standards for moving image and voice compression. organize.

There are five main MPEG standards: MPEG-1, MPEG-2, MPEG-4, MPEG-7 and MPEG-21. Founded in 1988, the expert is responsible for establishing video and audio standards for CDs, and its members are technical experts in the fields of video, audio and systems. Later, they successfully separated the recording of sound and video from the traditional analog method, established the ISO/IEC11172 compression coding standard, and formulated the MPEG-format, which brought the audio-visual communication into the digital age. Therefore, the MPEG-X version that everyone currently refers to is a video, audio, and data compression standard formulated and released by the ISO (International Organization for Standardization).
The video compression coding technology of the MPEG standard mainly uses the inter-frame compression coding technology with motion compensation to reduce the temporal redundancy, uses the DCT technology to reduce the spatial redundancy of the image, and uses the entropy coding to reduce the information representation. Statistical redundancy. The comprehensive application of these several technologies greatly enhances the compression performance.

1.2.1 MPEG-4

MPEG-4 began research in July 1995, and was approved by ISO/IEC as an official standard in November 1998. The official standard number is ISO/IEC14496. It not only targets video and audio coding at a certain bit rate, but also pays more attention to the multimedia system. Interactivity and flexibility. This standard is mainly used in video telephony, video e-mail, etc., and has lower requirements on the transmission rate, between 4800-6400bits/s, and the resolution is 176*144. MPEG-4 uses a very narrow bandwidth, through frame reconstruction technology, data compression, in order to obtain the best image quality with the least data. Utilize the high compression rate and high image quality of MPEG-4 to convert the MPEG-2 video files in DVD into smaller video files. After such processing, the video quality of the image does not drop much, but the volume can be reduced several times, and it is convenient to use CD-ROM to save the programs on DVD. In addition, MPEG-4 is also very useful in home video recording and network real-time video playback.
Experts in the MPEG Expert Group are working hard on the formulation of MPEG-4. The MPEG-4 standard is mainly used in videophone (videophone), video email (VideoEmail) and electronic news (Electronicnews), etc. Its transmission rate requirements are low, between 4800-64000bits/sec, and the resolution is 176X144. MPEG-4 uses a very narrow bandwidth to compress and transmit data through frame reconstruction technology in order to obtain the best image quality with the least amount of data.
Compared with MPEG-1 and MPEG-2, the feature of MPEG-4 is that it is more suitable for interactive AV service and remote monitoring. MPEG-4 is the first dynamic image standard that makes you change from passive to active (no longer just viewing, allowing you to join in, that is, interactive); another feature of it is its comprehensiveness; from the root , MPEG-4 attempts to blend natural objects with man-made objects (in the sense of visual effects). The design goal of MPEG-4 also has wider adaptability and scalability.

1.2.2 MPEG-7


MPEG-7 (its origin is 1+2+4=7, because there is no MPEG-3, MPEG-5, MPEG-6) started research in October 1996. To be precise, MPEG-7 is not a compression coding method, its formal name is called "Multimedia Content Description Interface", its purpose is to generate a standard for describing multimedia content, this standard will provide a certain level of interpretation for the meaning of information The degrees of freedom of , can be transmitted to, or retrieved by, devices and computer programs. MPEG-7 is not aimed at a specific application, but for the image elements standardized by MPEG-7, and these elements will support as many various applications as possible. The starting point of establishing the MPEG-7 standard is to rely on numerous parameters to classify images and sounds, and to query their databases, just like we query text databases. Can be applied to digital libraries, such as image catalogs, music dictionaries, etc.; multimedia query services, such as telephone directories, etc.; broadcast media selection, such as radio and TV channel selection; multimedia editing, such as personalized electronic news services, media creation wait.
 

1.2.3 MPEG-21


MPEG proposed the concept of "Multimedia Framework" at the MPEG meeting in October 1999. The MPEG meeting in December of the same year confirmed that the official name of MPEG-21 is "Multimedia Framework" or "Digital Audiovisual Framework". The technology integrated to support coordination aims to manage multimedia business, the purpose is to understand how to combine different technologies and standards, what new standards are needed and to complete the combination of different standards.

1.3 RM and RMVB (*.rmbv files)

RealMedia Variable Bit Rate (RMVB) is an extended version of the Variable Bit Rate (VBR) of the RealMedia multimedia digital container format developed by RealNetworks. Compared with the more common streaming media RealMedia container encoded by constant bit rate (CBR), RMVB is typically applied to multimedia content stored locally. File extensions using this format are ".rmvb".
RMVB is a video file format, where VB refers to Variable Bit Rate (variable bit rate). Compared with the previous generation of RM format, the picture is much clearer, because the bit rate in the static picture is reduced.

1.3.1 RM and RMVB

The common RM format is Real 8.0 format, which adopts fixed bit rate encoding. It is more common in VCD-RM and has been popular for a while.
RMVB has one more VB than RM. VB refers to Variable Bitrate, dynamic code rate or variable bit rate, which is version 9.0 of the encoding format of RealNetworks. The compression method used by RealMedia is similar to MPEG-4 Part 10 encoding, such as x264. The file header of RMVB format contains four bytes of ".RMF", which corresponds to 2E 52 4D 46 in hexadecimal. This file header is the same as the standard RealMedia format. 
RMVB (Real 9.0) still adopts the RM (Real 8.0) format for audio coding, at least 64Kbps stereo music is used when compressing, usually 96K, MTV is useful up to 128K, no higher compression is necessary.
RMVB and format conversion
RMVB is actually a media container of the Real Helix series, which has nothing to do with its own encoding format, similar to AVI, MKV and other formats. The encoder itself adds the 9.0 version of VBR dynamic bit rate technology, and adopts some H263/H264 algorithm features to greatly improve the image quality and workflow. Regarding VCD, DVD, and DVDRIP transcoding, many people will misunderstand that low-quality RMVB is meaningless, but it is actually wrong.
First of all, VCD uses MPEG-1 PS stream. Although there is a mosaic problem, the effect will not be particularly bad if it is converted from a genuine disc or DV. If the real old generation RM generation encoder is used, the mosaic effect is more obvious and Because the fluency will be affected when the bit rate is low; on the contrary, the encoding technology after Real Helix 9.0 has added a strong ability to decode and eliminate mosaics, so the effect of the same bit rate will be greatly improved, and there is also an option to ultimately improve the image quality 2-pass. Using the technology of one-time query and two-pass encoding takes advantage of the characteristics of VBR to greatly improve the degree of restoration of the program while ensuring fluency.
DVD uses MPEG-2 technology (many DVD compression also uses VBR technology and 2-pass), on the one hand there will be field sequence (the effect of image drawing, need to do reverse field processing) and the color area also has YUV, YV2, In addition, the resolution is double that of VCD (720x480 or 720x576), so the 2-pass encoding quality of RMVB will be much better at low bit rates.
DVDRIP generally uses Xvid/DivX as encoding, and has already eliminated the field sequence and color problems through some tools, so the picture has been optimized a lot, and most of them are encoded by VBR, so the effect after converting to RMVB will be far greater Better than the old RM format.
RMVB is not an open source technology and its copyright issues have also caused serious controversy. For sharing advocates, two encoding algorithms, XVID and H.264, are recommended.

1.3.2 History of RMVB

The predecessor of RMVB is the RM format. They are audio and video compression specifications formulated by Real Networks. According to different network transmission rates, different compression ratios are formulated, so as to realize real-time transmission and playback of image data on low-speed networks. It has the advantages of small size and good picture quality.
The early RM format was developed to enable online video playback with limited bandwidth, and was once popular throughout the Internet. In order to achieve a more optimized volume and picture quality, Real Networks soon launched the RMVB format of variable bit rate encoding on the basis of RM. The birth of RMVB broke the average compression sampling method of the original RM format. On the basis of ensuring the average compression ratio, a floating bit rate coding method was adopted, and a higher bit rate was used for complex dynamic pictures (such as singing and dancing, Speeding cars, wars, etc.), while in static pictures, it flexibly switches to a lower sampling rate, thus making reasonable use of bit rate resources, making RMVB compress the size of the movie to the greatest extent, and finally has a near-perfect near-perfect DVD-quality audiovisual effects. We can make a simple comparison. Generally speaking, a 120-minute DVD has a volume of 4GB, but compressed in RMVB format, it is only about 400MB, and the definition and fluency are not far worse than the original DVD.
In order to shorten the download time for video files to spread on the Internet, and to save the precious space capacity of the user's computer hard disk, more and more videos have been compressed into RMVB format and widely circulated. In the booming period of RMVB format, more than 80% of the video files in every computer user's computer will be in RMVB format. But until now, the RMVB format has been replaced by mp4, MKV and other formats.

1.3.3 DVDRIP VS rmvb

There are more and more comparisons about DVDRIP and rmvb. Strictly speaking, the two have their own advantages and disadvantages, and are largely incomparable. I just want to mention here: Can the 400M data volume (rmvb) compare with the 1.4G data volume (2CDDVDRIP) in terms of picture quality? However, the loss of 400M data volume is only details and unnecessary high audio bit rate, and the overall picture quality and audio are basically satisfactory. What is the concept of 400M/1.4G for downloading and saving? The AC3 effect and 44k stereo sound are indistinguishable to ordinary people. In addition, those who emphasize audio effects can basically say that they do not understand the concept of multimedia compression (I offended some people here).
DVDRIP brings us high-definition movie quality enjoyment, and also provides high-quality film sources for rmvb compressors. DVDRIP has an advantage in providing new movies because it can choose subtitles flexibly. However, because rmvb is integrated into the subtitles, it cannot be compressed blindly. The rmvb directly compressed with uncorrected subtitles will fail even if the settings are reasonable and 2pass compression is used. Therefore, rmvb is valuable in preserving classic movies and large movies with subtitles adjusted several times. Although rmvb can also plug in subtitles, the effect is not very good! But it is a good way of thinking, we should wait and see how it changes. For a long time, the DVDRIP production team, the subtitle team, and the rmvb production team may have interdependent relationships, but now the DVD vob file-rmvb can also be realized, and according to my experience, the effect is very good. In this way, rmvb and DVDRIP are even better. Many forums now offer rmvb versions when they provide DVDRIP, such as Niu Guo, New World, Paradise Forum, etc. More forums basically provide DVDRIP or rmvb separately, such as Haihao, Yongfei, Quick, New Dynamic, etc.
Now the size of DVDRIP production can also be controlled, such as using xdiv format encoding, audio encoding with mp3, etc., the final file of a 120min movie can be controlled in 1CD, so DVDRIP is comparable to rmvb. Of course, press it into rmvb, and the size of 120min can be controlled at about 350M, so you can choose it according to your network conditions and hard disk size. I still like the DVDRIP of 1CD very much, after all, the clarity in details is better than rmvb.
 

1.4 MKV (*.mkv file)

Matroska Multimedia Container (Multimedia Container) is an open standard free container and file format. It is a multimedia packaging format that can accommodate an unlimited number of video, audio, picture or subtitle tracks in a file. So it is not a compressed format, but a multimedia container file defined by Matroska. Its goal is to save common multimedia content such as movies and TV shows as a unified format. Conceptually, Matroska is similar to other containers, such as AVI, MP4 or ASF (Advanced Streaming Format, that is, Advanced Streaming Format), but it is completely open in terms of technical regulations and includes many open source software in its implementation. It can encapsulate a variety of different encoded videos, more than 16 audios in different formats and subtitle streams in different languages ​​into one Matroska media file. The biggest feature is that it can accommodate a variety of different types of encoded video, audio and subtitle streams.
mkv is different from video encoding formats such as DivX and XviD, and also different from audio encoding formats such as MP3 and Ogg. MKV is a "combination" and "package" format that provides a shell for these audio and video. In other words, it is a container format, and the common DAT (a coding format of VCD) AVl, VOB, MPEG, and RM formats actually all belong to this type. But they are either outdated or not open enough, which led to the birth of new multimedia packaging formats such as MKV.
The Matroska file extension is .MKV for video files with audio and subtitles; .MK3D for 3D stereoscopic video; .MKA for a single pure audio file; .MKS for a single pure subtitle file.
The appearance of avi has been more than 10 years, and it gradually shows its old state. Except that it can have 2 audio tracks through VD in recent years, there is no other improvement.
The emergence of ogm marks the emergence of multi-track format, which can synthesize more than 8 audio tracks. Naturally, the format of ogg is added to the audio. The important thing is that subtitles can be "embedded", which is called "soft subtitles" by foreigners. It can be switched on and off at will, and more than 8 subtitles can be "built-in". The fly in the ointment is that it only supports srt format, and does not support Unicode, and the support for Asian characters is seriously insufficient.
Another is the Chapter function, you can customize the paragraphs, and you can choose them during playback. Is it more and more like DVD? However, the source code of ogm at that time was not public, and only a few people were developing it. Naturally, the progress was slow, and it almost fell into "death" a while ago. Recently announced the open source code, joined the ranks of Open Source, and restarted development.
mkv appeared during the period when ogm was stagnant. It was developed by Russian programmers. It was Open Source from the beginning, so it got the help of many other programmers, and the development speed was quite fast.
Both ogm and mkv have it, and there are many unique functions. The most exciting one is the Plugin developed by Gabest (the company that develops vobsub). Not only has it developed a special player, Media Player Classic (commonly known as MPC), but I believe everyone who has used it has experienced the power of this thing. Also developed a lot of Mux (synthesizer) for MKV, especially Mux in Real format. Real's rmvb is a closed format, and the official Helix doesn't support multi-channel at all, so although the algorithm is excellent, it can't do anything to reproduce the sound effects of blockbuster movies, so it can only obediently give way to avi and ogm, which can synthesize AC3 and DTS .
But the Realmedia Splitter and mkv Mux developed by Gabest can make rmvb format video and AC3, DTS synthesize mkv, fundamentally overcome the weakness of rmvb audio. Not only that, but also developed two Plugins, VSFilter.dll and SubtitleSource.ax, and announced support for soft subtitles in ssa and ass formats.
The summary is the following:
1. Support multiple formats of video and audio, especially Real;
2. Support multiple audio tracks, up to 16 or more;
3. Support ssa, ass soft subtitles, up to 16 or more;
4 .Support paragraph selection (determined by the producer).

1.5 FLV (*.flv file)

FLV is the abbreviation of FLASH VIDEO, and the FLV streaming media format is a video format developed with the introduction of Flash MX. Because the files it forms are extremely small and the loading speed is extremely fast, it is possible to watch video files on the Internet. Its appearance effectively solves the problem that after the video files are imported into Flash, the exported SWF files are bulky and cannot be used well on the Internet. And other issues.

As an emerging network video format, FLV is not accidental to be supported by many websites. In addition to the low market share, good video quality, and small size of the FLV video format, which is suitable for network development, rich and diverse resources are also an important factor for the unified online playback of FLV video formats. From the latest Transformers to jailbreak to various sports programs, and even selfie videos made by netizens, you can easily find them on the Internet.
There are two types of websites that provide FLV videos on the Internet, one is a special video sharing website such as YouTube in the United States, Liujianfang and Tudou in China. The other is that the portal provides a video podcast section and provides its own video channels, such as Sina Video Podcast, which also use FLV format videos. In addition, Baidu has also launched a video search function, and the videos searched in it are basically in the popular FLV format.

2. FFMPEG open source components

2.1 Introduction to FFmpeg

FFmpeg is a set of open source computer programs that can be used to record, convert digital audio and video, and convert them into streams. Adopt LGPL or GPL license. It provides a complete solution for recording, converting and streaming audio and video. It contains a very advanced audio/video codec library libavcodec. In order to ensure high portability and codec quality, many codes in libavcodec are developed from scratch.
FFmpeg is developed under the Linux platform, but it can also be compiled and run in other operating system environments, including Windows, Mac OS X, etc. This project was first initiated by Fabrice Bellard and maintained by Michael Niedermayer from 2004 to 2015. Many FFmpeg developers come from the MPlayer project, and currently FFmpeg is also placed on the server of the MPlayer project team. The name of the project comes from the MPEG Video Coding Standard, where the preceding "FF" stands for "Fast Forward". The FFmpeg encoding library can use GPU acceleration.

2.2 FFmpeg download

Official website:

FFmpeg official website

2.3 Extract the summary information of the video file

This article provides the summary information of the C# source program used to extract video files in various formats.

2.3.1 Ideas

Call and execute ffprobe.exe of the ffmpeg package to generate data in json format, and use Newtonsoft.json to deserialize to get relevant information.

C:\\Downloads\\Softwares\\ffmpeg\\bin\\ffprobe.exe -v quiet -show_format -show_streams -print_format json 视频文件名

Notice:

(1) Please modify the directory of ffprobe.exe to your installation folder;

(2) The video file name should be enclosed in double quotes: "c:/a/a.mkv"

2.3.2 C# calls the source program of ffprobe.exe

The vf in the following code is the video file.

using System.Diagnostics;

var proc = new Process
{
    StartInfo = new ProcessStartInfo
    {
        FileName = "C:\\Downloads\\Softwares\\ffmpeg\\bin\\ffprobe.exe",
        Arguments = "-v quiet -show_format -show_streams -print_format json \"" + vf + "\"",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    }
};

proc.StartInfo.StandardOutputEncoding = Encoding.UTF8;
proc.Start();

StringBuilder sb = new StringBuilder();
while (!proc.StandardOutput.EndOfStream)
{
    string line = proc.StandardOutput.ReadLine();
    sb.AppendLine(line);
}

string json = sb.ToString();

2.3.3 Example of json file

The above code will get a json data describing the video information.

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "High",
            "codec_type": "video",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1920,
            "height": 1080,
            "coded_width": 1920,
            "coded_height": 1080,
            "closed_captions": 0,
            "film_grain": 0,
            "has_b_frames": 2,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 50,
            "chroma_location": "left",
            "field_order": "progressive",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "id": "0x1",
            "r_frame_rate": "25/1",
            "avg_frame_rate": "25/1",
            "time_base": "1/12800",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 66805248,
            "duration": "5219.160000",
            "bit_rate": "3005557",
            "bits_per_raw_sample": "8",
            "nb_frames": "130479",
            "extradata_size": 43,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "language": "und",
                "handler_name": "VideoHandler",
                "vendor_id": "[0][0][0][0]"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "initial_padding": 0,
            "id": "0x2",
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 250517472,
            "duration": "5219.114000",
            "bit_rate": "259574",
            "nb_frames": "244647",
            "extradata_size": 5,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "language": "und",
                "handler_name": "SoundHandler",
                "vendor_id": "[0][0][0][0]"
            }
        }
    ],
    "format": {
        "filename": "D:\\迅雷下载\\绝杀.Jue.sha.1993.HD1080P.国语无字.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "5219.160000",
        "size": "2134124579",
        "bit_rate": "3271215",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "encoder": "Lavf56.18.101"
        }
    }
}

The meaning of each parameter, please Baidu.

2.3.4 Necessary base class (class)

MovieInfo.cs

public class MovieInfo
{
    public MovieStream[] streams { get; set; }
    public MovieFormat format { get; set; } = new MovieFormat();
}

MovieStream.cs

public class MovieStream
{
    public int index { get; set; } = 0;
    public string codec_name { get; set; } = "h264";
    public string codec_long_name { get; set; } = "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10";
    public string profile { get; set; } = "High";
    public string codec_type { get; set; } = "video";
    public string codec_tag_string { get; set; } = "avc1";
    public string codec_tag { get; set; } = "0x31637661";
    public int width { get; set; } = 1920;
    public int height { get; set; } = 1080;
    public int coded_width { get; set; } = 1920;
    public int coded_height { get; set; } = 1080;
    public int closed_captions { get; set; } = 0;
    public int film_grain { get; set; } = 0;
    public int has_b_frames { get; set; } = 2;
    public string sample_aspect_ratio { get; set; } = "1:1";
    public string display_aspect_ratio { get; set; } = "16:9";
    public string pix_fmt { get; set; } = "yuv420p";
    public int level { get; set; } = 50;
    public string chroma_location { get; set; } = "left";
    public string field_order { get; set; } = "progressive";
    public int refs { get; set; } = 1;
    public bool is_avc { get; set; } = true;
    public int nal_length_size { get; set; } = 4;
    public string id { get; set; } = "0x1";
    public string r_frame_rate { get; set; } = "25/1";
    public string avg_frame_rate { get; set; } = "25/1";
    public string time_base { get; set; } = "1/12800";
    public int start_pts { get; set; } = 0;
    public string start_time { get; set; } = "0.000000";
    public long duration_ts { get; set; } = 66805248;
    public string duration { get; set; } = "5219.160000";
    public string bit_rate { get; set; } = "3005557";
    public string bits_per_raw_sample { get; set; } = "8";
    public string nb_frames { get; set; } = "130479";
    public int extradata_size { get; set; } = 43;
    public MovieDisposition disposition { get; set; }
    public MovieTag tags { get; set; }

    public MovieStream() { }
}

MovieDisposition.cs

public class MovieDisposition
{
    [JsonProperty("default")]
    public int _default { get; set; } = 1;
    public int dub { get; set; } = 0;
    public int original { get; set; } = 0;
    public int comment { get; set; } = 0;
    public int lyrics { get; set; } = 0;
    public int karaoke { get; set; } = 0;
    public int forced { get; set; } = 0;
    public int hearing_impaired { get; set; } = 0;
    public int visual_impaired { get; set; } = 0;
    public int clean_effects { get; set; } = 0;
    public int attached_pic { get; set; } = 0;
    public int timed_thumbnails { get; set; } = 0;
    public int captions { get; set; } = 0;
    public int descriptions { get; set; } = 0;
    public int metadata { get; set; } = 0;
    public int dependent { get; set; } = 0;
    public int still_image { get; set; } = 0;
    public MovieDisposition() { }
}

MovieTag.cs

public class MovieTag
{
    public string language { get; set; } = "und";
    public string handler_name { get; set; } = "VideoHandler";
    public string vendor_id { get; set; } = "[0][0][0][0]";
    public MovieTag() { }
}

MovieFormat.cs

public class MovieFormat
{
    public string filename { get; set; } = "D:\\迅雷下载\\绝杀.Jue.sha.1993.HD1080P.国语无字.mp4";
    public int nb_streams { get; set; } = 2;
    public int nb_programs { get; set; } = 0;
    public string format_name { get; set; } = "mov,mp4,m4a,3gp,3g2,mj2";
    public string format_long_name { get; set; } = "QuickTime / MOV";
    public string start_time { get; set; } = "0.000000";
    public string duration { get; set; } = "5219.160000";
    public string size { get; set; } = "2134124579";
    public string bit_rate { get; set; } = "3271215";
    public int probe_score { get; set; } = 100;
    public MovieFormatTag tags { get; set; }
    public MovieFormat() { }
}

MovieFormatTag.cs

public class MovieFormatTag
{
    public string major_brand { get; set; } = "isom";
    public string minor_version { get; set; } = "512";
    public string compatible_brands { get; set; } = "isomiso2avc1mp41";
    public string encoder { get; set; } = "Lavf56.18.101";
    public MovieFormatTag() { }
}

2.3.5 Deserialize json into class information and use it (reference code)

string json = sb.ToString();
try
{
    MovieInfo mi = JsonConvert.DeserializeObject<MovieInfo>(json);

    foreach (MovieStream ms in mi.streams)
    {
        if (ms.codec_type != "video") continue;
        FileInfo fx = new FileInfo(vf);
        sb.Append(ChineseName(fx.Name) + "_");
        sb.Append(ms.coded_width + "x" + ms.coded_height + "_");
        sb.Append((ms.duration));
        sb.Append(fx.Extension.ToLower());
        string nf = sb.ToString();
        return nf;
    }
    return vf;
}
catch (Exception ex)
{
    return vf;
}

For excellent software, please refer to  the video file preview and management system

Various video gadget software can be written on this basis.

рекомендация

отblog.csdn.net/beijinghorn/article/details/127169136