Design Of Video Bitrate Analyzer Based On Swift

. Network video is very popular, users often upload video, Video site allows specific coded video to maintain the original specification at a certain peak rate, and then to add lower-level specifications to the code. At present, many analysis tools can only get the maximum rate of the whole video, and cannot get the rate map, nor support the new video format. This design proposes using the Swift language to display the video bitrate analysis data in different forms, FFmpeg/ffprobe applications is called to analyze video stream. The experimental results show that the design can get the information of all frames of the video to depict the column chart, and can display the corresponding time point of the frame, so that users can modify the area exceeding the rate limit, so as to achieve the goal of no forced transcoding. In addition, this design supports HEVC format video.


Introduction
The network video is very popular, users shoot what have been seen and heard, record game video, and upload the video to share. At the beginning, because of bandwidth, hardware and other reasons, the video sites will force transcoding to users' uploaded videos, compress into different specifications to choose for users. The resulting problem is not smooth (60 fps to 24 fps) and indistinct (1080p to 720p). With the progress of technology, video sites relax the terms and no longer force transcoding, allow specific coded video to maintain its original specifications at a certain rate of peak value, and then transcode new low-level specifications. Video bitrate analysis is particularly important before uploading video.
Many scholars have made research on video rate analysis, Dongyan Zhang and Hui He proposed a serverside-based rate allocation algorithm for content delivery networks [1]. Hyoungseok Kim and Joonseok Park proposed new video quality assessment metric using intensity variation analysis [2]. Jie Wang and Linge Li proposed algorithm to speed up the transcoding procedure, which mainly utilizes information from the input video stream such as Code Unit depths, Prediction Unit partitions [3]. Selvaraj Kesavan and J. Jayakumar proposed client-driven three-level optimized rate adaptation algorithm for adaptive HTTP media streaming, the algorithm controlled and minimized the effects of buffer stalls and overflow resulting from the brief network variations occurring between consecutive segments [4]. NK Karn，H Zhang and F Jiang presented a comprehensive analysis of a dynamic network environment for streaming of 3D MVD over Internet [5]. Jian Chen and Shuai Zheng proposed a frame-level distributed video coding system based on encoder rate control [6]. YSDL Fuente ， R Skupin and T Schierl proposed the technique which generated a single video bit stream out of the selected tiles so that a single hardware decoder can be used [7]. Jacob Søgaard and Muhammad Shahid presented insights into a study that investigates perceptual preferences of various adaptive video streaming scenarios through crowdsourcing based and laboratory based subjective assessment [8].
These studies mainly improved the efficiency of analysis from algorithm, the specific application was less. In addition, ordinary tools such as Mediainfo can only get the maximum of the entire video, but not the rate distribution map. Under the Windows system, there is a very powerful video rate analysis tool Bitrate Viewer, it can analyze a variety of video coding, and display the results according to three different methods of data processing: Frame, GOP and Second [9]. Under the macOS system, Udo Gerber has been transplanted. But both have not been updated for years and unable to support new video coding, such as HEVC. And the price of both is too expensive, which is prohibitive.

Brief introduction of Swift
Swift is a powerful and intuitive programming language, which is created by Apple and can be used to develop APP for iOS, Mac, Apple TV and Apple Watch. Swift can provide real-time feedback, and can be seamlessly integrated into existing Objective-C code. Swift code guarantees security from design, developers can write secure and reliable code, have a very rich APP experience while saving time. Swift is free and open source, it provides binary files for the OS X and the Linux platform，these files can compile code in iOS, OS X, watchOS, tvOS and Linux. Writing Swift code is a fun interactive process, because Swift syntax is concise, but expressive enough to develop software that runs as fast as lightning [10].

Procedure Design
Ffmpeg is uses to analyze video streams, it is an open source computer program which can be used to record and convert digital audio and video, and transform them into into streams [11]. The analysis process has seven steps, including calling FFmpeg/ffprobe applications to analyze the first video stream, extracting information from each frame, extracting information from the video stream, calculating the video stream, parsing the JSON data, displaying the details of each data, and dragging the video file to the program window. The details are shown below.
( 1 ) Analyze the information of the first video stream by calling FFmpeg/ffprobe applications.
(2)Extract information from each frame, including timestamp , duration, size and type, the data are displayed in three formats: Frame, GOP and Second.
( 3 ) Extract information of the video stream, including width, height, average frame rate , time base, length of time, average bitrate.
(4)Calculate the minimum frame rate, maximum frame rate and total number of frames.
(5)Use Codable protocol of Swift 4 to analyze JSON data directly.
( 6 ) Click the column chart data to display the details of each item data.
(7)Drag video files to the program window.

Module Design
(1) Frame module design The module calls FFmpeg/ffprobe applications to analyze the first video stream, each frame is a statistic, Ffprobe extracte information by default.
(2) GOP module design Using one frame as segmentation, All frames before the first frame to the second frame are combined into a statistical item, and so on. The program is as follows.

4.Test Results and Future Work
The video bitrate analyzer displays the results according to the three methods of data processing: Frame, GOP and Second. The test results are shown below.

Test results
The bitrate analysis results are shown in figure 1, figure  2 and figure 3.

Future Work
The analysis of video stream uses ffprobe directly, because ffprobe is a CLI program, Swift needs to take over cout and store it in memory temporarily when it calls, after waiting for the program to quit completely, saves the cout result to the JSON file, finally, through the parsing tool JSON in Swift 4, parses the JSON into the variables of the program running. These steps are obviously superfluous. The C++ hybrid programming should be used, analyze the video file directly and save the result to the variable. If it is needed to be saved, it is saved to disk in JSON form.
Because in the AutoLayout layout, DragView is on the top level, thus covering BarChartView, column chart data can be clicked sometimes and not clicked sometimes. In addition, only MP4 and flv containers are supported, and flv is not fully supported.