Design of high-definition video editing module based on FFmpeg

Publisher:Meiren520Latest update time:2014-03-09 Source: 21ICKeywords:FFmpeg Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Background

Video analysis is widely used in the field of sports. Coaches and athletes can carefully study the details of the game by controlling the segmentation, playback, and pause of the game video, and analyze and summarize the technical and tactical characteristics of the athletes, which can be used as first-hand information to guide the athletes' daily training and competition. With the continuous development of multimedia technology and video encoding and decoding technology, high-definition video, as an important tool that can provide strong support for the study of athletes' technical and tactical levels, is increasingly valued by coaching teams in various countries.

MTS video format is an emerging high-definition video format. Its video encoding usually adopts H264 format, audio encoding adopts AC-3 format, and the resolution is full HD standard 1920*1080. Due to the complexity of H264 encoding adopted by MTS video format, the decoding of MTS has high requirements for hardware compatibility. HD video sources will pause and lose frames when played on many existing players, so it is necessary to convert them into MPEG format with stronger compatibility. When using the original national fencing team video management system developed based on DrectShow technology for MTS format video encoding, the problem of not being able to recognize the video format will occur, and due to the low efficiency of DrectShow for video encoding, it takes too long to process HD video, affecting the system work efficiency.

To solve this problem, this paper, based on the original video management system, uses the binary library generated by compiling FFmpeg in the Windows environment to improve the original video editing module, realizes the cutting of MTS format high-definition video sources and the compression conversion to MPEG format, and uses the XML Parser component to save the timeline information of the edited video to an XML document, thus realizing the editing, storage and management of high-definition sports videos.

2 FFmpeg encoding

2.1 Introduction to FFmpeg

FFmpeg is a powerful open source free cross-platform audio and video encoder and decoder collection. It is free software and uses GPL or LGPL licenses. It supports more than 40 encodings such as MPEG, MTS, MPEG4, and more than 90 decodings such as MPEG, Matroska, OGG, etc. It is a complete open source solution that integrates recording, conversion, audio/video encoding and decoding functions. FFmpeg is developed based on the Linux operating system and can also be compiled and used in most operating systems. It has high encoding efficiency. Therefore, based on the above advantages, this system chooses FFmpeg as the basis for implementing the video editing module.

2.2 Compiling FFmpeg in Windows

FFmpeg is a cross-platform open source project based on Linux system. It uses gcc compiler. To compile FFmpeg in Windows environment, you cannot use special compilers such as BCB or VC++. You need to download the compilation tool chain mingw installation package first and configure the corresponding environment variables. In addition, you need to install Msys to simulate the Linux environment and install yasm.

exe's 32-bit version (corresponding to your own operating system) to compile the assembly code in FFmpeg.

After the installation is complete, edit the C:\MinGW\msys\1.0\msys.bat file and add the relative path of VS2010 to the last line. After adding this line, when compiling FFmpeg, there will be an additional lib corresponding to the dll called under Windows. There are four commonly used library files: libavcodec, libavformat, libavutil and libswscale. The libavcodec library stores the decode/encode modules for audio and video decoding and encoding, the libavformat library stores the muxer/demuxer modules for merging/separating audio and video streams, and the libavutil library stores auxiliary modules such as memory operations.

2.3 FFmpeg encoding implementation

This video editing module mainly calls the corresponding functions in the audio/video codec library libavcodec to realize format conversion and cutting functions. Before using FFmpeg encoding, you first need to initialize the libavcodec library, register all codecs and file formats, import encoder bit rate, frame rate, encoding pixel format and other parameters, and then find the encoder and open it for encoding. By assigning values ​​to each member parameter in the structure AVCodecContext with preset video parameters, the setting of encoding parameters is realized. The core function of encoding is avcodec_encode_video(). Every time the system collects a frame of data, it is sent to the avcodec_encode_video() function to be encoded into an H.264 video stream. The detailed functions and encoding process during the encoding process are shown in Figure 1.

 

 

3 Implementation of video editing module based on FFmpeg

The structure of the improved HD video editing module is shown in Figure 2.

 

FFmpeg adopts the programming mode of main program + core library. The FFmpeg core library hides the specific format of various functions inside it and provides a unified calling method to the outside. In view of the characteristics of this design mode, this video editing module has the following design features: the video editing operation is realized by directly calling the functions in the FFmpeg core library, and the code of the MPEG file format processing part in the libavformat library is modified to achieve output at a fixed bit rate. The video editing interface of the system adopts a non-linear layout. The information that needs to be recorded on the operation timeline includes the in-point time and out-point time of the video clip (accurate to seconds). Every time the video file is processed, the middle layer will first determine whether the user has changed the timeline. If there is a change, the cutting part of the code will be executed, and the in-point information and out-point information on the timeline will be imported into the structure AVCodecContext as parameters for calling the core library function. The system calls avcodec_encode_video() and other related functions to encode the video. If the user checks the format conversion required, it will be converted to MPEG format, otherwise it will be output in the original format. After the conversion is completed, the handle of the generated new file needs to be replaced into the relevant data structure, and finally the edited detailed information is generated into an XML document through the XML Parser component. The specific process is shown in Figure 3.

 

 

4 High Definition Video Analysis System

The video analysis system of the national fencing team after adding the high-definition video editing module is shown in Figure 4.

 

 

This paper uses a 4-minute and 5-second clip from the standard HD test video of the fencing team to test the video editing module. The image resolution of the source is 1920*1080, the bit rate is 12414kbps, the frame rate is 25 frames/second, and the source file size is 363MB. This system is used to intercept a 2-minute video for format conversion. The encoding system correctly identifies the source file and outputs a 138MB MPEG file. The actual playback effect on the player shows that the video editing module can correctly cut and compress the HD MTS format source file according to user requirements into a smoothly playable MPEG format, which basically meets the design requirements.

5 End

This paper elaborates on the design and implementation of a high-definition video editing module based on FFmpeg. After analyzing the shortcomings of the original editing module developed based on DrectShow technology, it analyzes and proposes an improvement plan based on FFMpeg, and introduces the specific implementation of the plan. This solution maintains FFmpeg's efficient encoding rate and good encoding quality while being compatible with other modules of the original system. The edited video meets the various requirements for training use by the national fencing team.

Keywords:FFmpeg Reference address:Design of high-definition video editing module based on FFmpeg

Previous article:Development of circuit breaker partial discharge test system
Next article:Electronic wallet system for electronic games using smart cards

Latest Power Management Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号