Callback,. mpeg,. mov,. ram,. rm,. rmvb,. ts,. vob,. w
Success ,. mpeg ,. mov ,. ram ,. rm ,. rmvb ,. ts ,. vob ,. wmv ,. upload files in 3gp and other formats, and automatically convert them to files in flv, 3gp, and wmv formats. here we will share this experience.
(1) first,Upload progressFor ease of use, a progress bar is required, because after all, the video file is too large and there is no progress, making it inconvenient for users. Here, the interface looks like sina. of course, the implementation has nothing to do with it. sina uses flash to get the upload progress. This article uses php features. Here we will first describe the uploaded files, with an overall impression:
(2) the upload implementation method is roughly as follows:
1. configure the environment
????? A) configure the php environment to enable the display progress when uploading. the method is php5.2 or later, and then enable the php_apc extension, so that php can obtain the size of the uploaded file during the upload process.
B) add the configuration information to php. ini: apc. rfc1867 = on ???? Apc. max_file_size = 200 M. Modify the configuration of max_execution_time = 120 in php. ini ?? Post_max_size = 1024 M ???? Upload_max_filesize = 200 M
C) restart the web server
2. add the uploaded Form
3. write a page to get the progressFor example, getProgress. php: apc_fetch ('upload _'. $ _ GET ['SS SS _ key']); in this way, if you input the corresponding ID, you can GET the progress, file name, and other information of the file.
4. in order to display the progress, Ajax technology is also required,Access the getProgress. php page to get the progress through Ajax every 1 s or 0.5 s to get the size of the currently uploaded file. Then the result is displayed.
5. move the file to the target Directory: In the uploaded Form, there is a page to be submitted, such as specifying action = "target. php ". In target. php, you need to use the move_uploaded_file function to move the file to the specified directory. Otherwise, the uploaded file exists in the tmp directory and will be automatically deleted after submission.
6. others: For example, to control the format of the uploaded file, it can only be video files and other details.
In this way, the upload page is complete. -It is suitable for flash users who are not familiar with flash. if you are familiar with flash, you can also use the sina method to directly use swf Upload.
(3) automatic conversion:
In order to achieve a good conversion speed and avoid the impact on the ease of use of website users. Instead of putting the conversion into the webpage code, we can create an exe program separately. in this way, we have two considerations: On the one hand, the independent exe will not affect the running of website services, the website is only a simple upload function, so the system is more stable and reliable, and the performance will be good;
On the other hand, it is not affected by the website. websites such as asp, php, asp.net, and jsp can all use automatic conversion programs to convert videos.
In fact, even this conversion program can also be used as an independent conversion program to help users convert mobile phone files. although there are a lot of such software, they can implement their own programs through code, it is still cool, not to mention, self-implementation can fully control the functions of the program in line with their own requirements. A mobile phone manufacturer can use similar code to implement a random gift conversion program. Well, let's talk less about it. here we will discuss its implementation:
First, in this system, the program needs to monitor the folder uploaded by the website. once a new file is found, the conversion is automatically started. After the conversion is complete, you can directly access the database to report the conversion results of the file. of course, you can also access a page through http to report the results. These auxiliary functions are not described in detail, mainly about the implementation of the conversion function:
(4) implementation of the automatic conversion function:
?????????Basically, most video websites and video conversion software are inseparable.MencoderAndFfmpegTwo open-source software, of course, must be used to achieve automatic conversion. For details about the two software, google and Baidu can give you the answer.
First, if you need to support files in rm and rmvb formats, or you need to add your title information (such as a promotional clip from your company in a few seconds), then, you need to use mencoder. Here we will list the mencoder parameters I use:
1) convert the file to the avi format in a unified manner (to facilitate adding titles later). mencoder.exe % input %-srate 32000-vf-add scale = 320: 240-ofps 24-oac mp3lame-lameopts cbr: br = 32: mode = 0-ovc xvid-xvidencopts bitrate = 400-o % output % ?????? Here, % input % is the original video path % output % is the output video path. The two keywords in my program are used to change the path to the actual path during running. here, the configuration information is used to modify other parameters.
2) if a title file is specified, merge the title. the command line is as follows: mencoder.exe-srate 32000-vf-add scale = 320: 240-ofps 24-oac mp3lame-lameopts cbr: br = 32: mode = 0-ovc xvid-xvidencopts bitrate = 400-o % output % title % input % ?? % Title % indicates the title file. when the program is running, the program reads the title path based on the configuration information. if the title is specified, % title % is replaced by the title path.
In this way, the video is first converted to the avi format, and if there is a titles, the titles are automatically added. Next, convert it to a flv file or a 3gp file. in this case, use ffmpeg:
1) convert to flv: ffmpeg.exe-y-I % input %-AB 24-ar 22050-B 300-s % filesize % output %
2) to 3gp: ffmpeg.exe-y-I % input %-vcodec h263-B 260-s % filesize %-acodec aac-ac 1-ar 8000-AB 20-f 3gp-r 15% output %
This basically completes the conversion. Of course, a lot of websites still have a very important time, because, for example, if you need to review the uploaded content, a video lasts for 100 minutes and you want to take 10 images, of course, this combination may be better: capture a pair in the first minute, 10th minutes ...... 100th minutes. In this case, you need to obtain the duration of the program video content:
This can be obtained through mediaInfo.exe (an outstanding open-source software). the command line is roughly as follows: mediaInfo.exe-Inform = Video; % Duration % here % Duration % is written in this way, it is not a keyword of mine, so the video length will be output. Based on the total duration and the required quantity, you can calculate the reasonable interval. The next step is to capture the image:
Ffmpeg.exe-I % input %-y-f image2-ss % time %-t 0.001-s 130 × 110% i0000.jpg ?? Here, % time % is the number of seconds. % I % is the image name
Of course, if you are a website that provides 3 GP mobile video downloads, you can also take video clips of any length, such as 20 seconds, then, you can use the Flash Player for online preview. you only need to modify the settings according to the preceding parameters.
In this way, a complete conversion process is completed.