📜 ⬆️ ⬇️

Processing custom videos

For some time I was engaged (and still do) a web project, where it was necessary to add a feature for uploading custom video clips. Actually, what can be custom videos? Very different quality and diverse formats. Starting from the usual flash files that present the smallest problem to various entries from the phones. There was a task - to make a daemon that would handle the queue of downloaded files and perform the following functions:
- Convert video to flash format (FLV), using VP6 codec
- Update video meta-information
- Create thumbnails from video
- Further database manipulations

Specifically, in this article I will consider the options for processing the video clip already converted to flash. So let's get started.

1. Processing Metainformation
')
After we have received the coveted flash video, we need to update its meta-information, and specifically the key positions. This is necessary to support the view mode - streaming. Ie "jump" along the length of the video without downloading the entire file. Software that deals with this is commonly referred to as Metadata Injector. For Linux I tried:
- FlvTool2 - rubyforge.org/projects/flvtool2
- Yamdi - yamdi.sourceforge.net

FlvTool2 is an application written in Ruby. At first I settled on it. But as shown by the tests, it is not suitable for processing large files, because it loads the file into memory, which is not good. Some files (> 200 mb) were processed for 5 minutes. There are pluses - the result is written to the source file. It also allows you to "trim" files, which is very necessary.

Yamdi is an application written in C. The original name is Yet Another Meta Data Injector. It works very funny. The result of his work is a new file, which is most convenient, because the source can be immediately deleted or transferred to long-term storage. It also allows you to insert the onLastSecond event.

Both applications can generate an XML file with a list of all parameters, which is then used when updating video information in the database.
I chose Yamdi as the fastest one.

2. Creating thumbnails

So, we got the finished FLV file, XML c meta information. Further, for this video, you need to create a pre-320x240 (the picture that is displayed in the player before the user presses the start, an example can be seen on RuTube), several small previews 120x96. In this area, too, some utilities.

1. FFmpeg - ffmpeg.mplayerhq.hu
The basic program for working with video. I only used to convert the video, for the rest - not very suitable, because it does not make it possible to generate all the images (with random time points) at a time. More precisely, there this function is somewhat limited.

2. PHP Extension - ffmpeg-php.sourceforge.net
A module for php that allows you to work directly with the flash file. Able to collect previews in a GIF file, sometimes it is necessary. The only thing that works slowly compared to other utilities. Plus - a handy API, if the project uses PHP.

3. FFMpegThumbnailer - code.google.com/p/ffmpegthumbnailer
Written in C ++ and works very fast. Initially, the author created it for desktop managers. Recently I acquired a bunch of useful features, like video filters. It is possible to use in your C ++ programs. It supports 2 output formats (jpg / png), the selected point can be set using absolute time (hh: mm: ss) or as a percentage. It works with all formats perfectly, but there are failures on specific files (mp4). In general, ideal for the task.

3. Note

The first time we used JWPlayer 4 (without modification), we ran into a problem. The servers worked nginx 0.6.32, which, as it turned out, did not work with this player. The problem was that the new version of the player added other information to the file request line, like this:

myvideo.flv? start = 2659763 & width = 280 & client = FLASH% 20MAC% 209,0,124,0 & version = 4.0% 20 $ Rev:% 2030% 20

It was all decided very simply, patch for the web server: www.ruby-forum.com/attachment/2307/patch.flv

4. Conclusion

I don’t have much experience in custom video processing, but the 2 programs that I listed do a pretty good job. In general, everything seems to do such utilities themselves, depending on the needs. If someone specials in this part - criticism is welcome.

PS I haven't written anything in Russian for a long time, maybe it sounds a little crooked :)

Source: https://habr.com/ru/post/45289/


All Articles