Custom video processing
For some time I was engaged (and still am) in 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 varied formats. Starting from the usual flash files, which are the least problem, to various recordings from phones. The task was to make a daemon that would handle the queue of downloaded files and perform the following functions:
- Convert video to flash format (FLV) using a VP6 codec
- Update meta-information of a video file
- Create thumbnails from a video
- Further manipulations with the database
Specifically in this article, I I will consider processing options for a video clip already converted to flash format. So let's get started.
1. Processing of meta-information
After we received the coveted flash movie, we need to update its meta-information, and specifically key positions. This is necessary to support streaming. That is, to "jump" along the length of the video without downloading the entire file. The software that deals with this is usually called Metadata Injector. For Linux, I tried:
- FlvTool2 - rubyforge.org/projects/flvtool2
- Yamdi - yamdi.sourceforge.net
FlvTool2Is an application written in Ruby. At first I settled on it. But as tests have shown, it is not suitable for processing large files, because it loads the file into memory, which is not a buzz. 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 “crop” files, which is very necessary.
Yamdi is an application written in C. The original name is Yet Another Meta Data Injector. It works very jokingly. The result of its 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 an 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.
2. Creation of thumbnails
So, we got ready FLV file, XML with meta-information. Further for this video you need to create a 320x240 preview (the picture that is displayed on the player before the user presses the start, you can see an example on RuTube), a few small previews of 120x96. There are also a few utilities in this area.
1. FFmpeg - ffmpeg.mplayerhq.hu
The basic program for working with video. I used it only for video conversion, for the rest it is not very suitable, because it does not make it possible to generate all the images (with arbitrary time points) at a time. More precisely, this function is somewhat limited.
2. PHP Extension -ffmpeg-php.sourceforge.net
A module for php that allows you to directly work with flash file. Able to collect previews in GIF file, sometimes it is necessary. The only thing is slow compared to other utilities. Plus - a convenient API if the project uses PHP.
3. FFMpegThumbnailer - code.google.com/p/ffmpegthumbnailer
It is written in C ++ and works very fast. Initially, the author created it for dextop managers. Recently, I got a bunch of useful features, like video filters. It is possible to use in their 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. Works with all formats perfectly, but there are crashes on specific files (mp4). In general, ideal for the task.
3. Note At
first, we used JWPlayer 4 (without modification), then 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 was adding other information to the file’s query string, like this:
myvideo.flv? start = 2659763 & width = 280 & client = FLASH% 20MAC% 209,0,124,0 & version = 4.0% 20 $ Rev:% 2030% 20
Everything was decided very simply, with a patch for the web server: www.ruby-forum.com/attachment /2307/patch.flv
4. Conclusion
I do not have much experience in the field of processing custom videos, but 2 of the programs that I have listed do quite a good job. In general, everyone seems to make such utilities themselves, depending on the needs. If someone is special in this regard, criticism is welcome.
PS I haven’t written anything in Russian for a long time, maybe it sounds a little crooked :)
- Convert video to flash format (FLV) using a VP6 codec
- Update meta-information of a video file
- Create thumbnails from a video
- Further manipulations with the database
Specifically in this article, I I will consider processing options for a video clip already converted to flash format. So let's get started.
1. Processing of meta-information
After we received the coveted flash movie, we need to update its meta-information, and specifically key positions. This is necessary to support streaming. That is, to "jump" along the length of the video without downloading the entire file. The software that deals with this is usually called Metadata Injector. For Linux, I tried:
- FlvTool2 - rubyforge.org/projects/flvtool2
- Yamdi - yamdi.sourceforge.net
FlvTool2Is an application written in Ruby. At first I settled on it. But as tests have shown, it is not suitable for processing large files, because it loads the file into memory, which is not a buzz. 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 “crop” files, which is very necessary.
Yamdi is an application written in C. The original name is Yet Another Meta Data Injector. It works very jokingly. The result of its 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 an 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.
2. Creation of thumbnails
So, we got ready FLV file, XML with meta-information. Further for this video you need to create a 320x240 preview (the picture that is displayed on the player before the user presses the start, you can see an example on RuTube), a few small previews of 120x96. There are also a few utilities in this area.
1. FFmpeg - ffmpeg.mplayerhq.hu
The basic program for working with video. I used it only for video conversion, for the rest it is not very suitable, because it does not make it possible to generate all the images (with arbitrary time points) at a time. More precisely, this function is somewhat limited.
2. PHP Extension -ffmpeg-php.sourceforge.net
A module for php that allows you to directly work with flash file. Able to collect previews in GIF file, sometimes it is necessary. The only thing is slow compared to other utilities. Plus - a convenient API if the project uses PHP.
3. FFMpegThumbnailer - code.google.com/p/ffmpegthumbnailer
It is written in C ++ and works very fast. Initially, the author created it for dextop managers. Recently, I got a bunch of useful features, like video filters. It is possible to use in their 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. Works with all formats perfectly, but there are crashes on specific files (mp4). In general, ideal for the task.
3. Note At
first, we used JWPlayer 4 (without modification), then 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 was adding other information to the file’s query string, like this:
myvideo.flv? start = 2659763 & width = 280 & client = FLASH% 20MAC% 209,0,124,0 & version = 4.0% 20 $ Rev:% 2030% 20
Everything was decided very simply, with a patch for the web server: www.ruby-forum.com/attachment /2307/patch.flv
4. Conclusion
I do not have much experience in the field of processing custom videos, but 2 of the programs that I have listed do quite a good job. In general, everyone seems to make such utilities themselves, depending on the needs. If someone is special in this regard, criticism is welcome.
PS I haven’t written anything in Russian for a long time, maybe it sounds a little crooked :)