C # play an MP4 video in ckplayer. js format while loading and playing,

Source: Internet
Author: User

C # play an MP4 video in ckplayer. js format while loading and playing,

Use ckplayer in the View page in the MVC design mode. loading videos in js. After uploading MP4 videos, I found that some videos can be played while loading, the reason is that the video metadata does not work at the first frame. The solution is to download a tool to process the video.

The download page address is: http://ffmpeg.zeranoe.com/builds/

Click Download FFmpeg git-738ebb4 64-bit Static (I am a 64-bit) on the page, if you are a 32-bit click Download FFmpeg git-738ebb4 32-bit Static

After downloading and decompressing the package, I changed the folder to ffmpeg and put it under drive D.
Run three files:
D: ffmpeg/bin/ffmpeg.exe
D: ffmpeg/bin/ffplay.exe
D: ffmpeg/bin/ffprobe.exe
The installation is successful.


Here are two simple examples:
First, put a video file in the root directory of drive D to save time. For example, I put D:/1.flv
Enter cmd in Start> run to bring up the command window.
Perform the following operations:
Enter d: Press ENTER
Enter cd ffmpeg/bin and press Enter.
In this way, the ffmpeg directory is entered,
1. Test the video function.
Copy the following command, right-click in the command line, and select Paste
Ffmpeg-I d:/1.flv-y-f image2-t 0.001-s 720x576 d:/1.jpg
Check whether a 1.jpg image is generated under the dashboard. If yes, check whether the path is correct.
2: Test d:/1. Convert flv to d:/1.mp4
Similarly, copy the following command, right-click the command window, and choose Paste

Ffmpeg.exe-I "d: 1.flv"-y-metadata title =" this is the video title "-metadata comment =" this is the video information! "-C: v libx264-preset superfast-xforwaropts keyint = 25-r 15-B: v 500 k-c: a aac-strict experimental-ar 44100-ac 2-B: a 64 k-vf "movie20.a.png [watermark]; scale = 1364x768 [scale]; [scale] [watermark] overlay = 30: 30 [out] "-f mp4" d: 2.mp4"

After the command is executed, check whether there is an mp4 in disk D.

Parameter description:

Movie = watermark
-B: The 500k after v is the bit rate.
Scale = resolution
Keyint = 25 indicates that a key frame exists at every 25 frames.

 

If the metadata information of your video is not in the first frame, the following introduces another mp4 method that transfers the metadata information to the first frame of the video.

First download a qt-faststart
: Http://www.ckplayer.com/down/qt-faststart.rar
Download to decompress qt-faststart.exe and put it under d: ffmpeg/bin /.
Run the command: qt-faststart.exe d:/1.mp4 d:/2.mp4
The final 2.mp4 is successful. You can download and play videos.

 

The whole solution is feasible after testing, so I run the CMD command in C #.

Public string Test (string plain text) {Stopwatch w = new Stopwatch (); w. start (); StringBuilder sb = new StringBuilder (); string str = runningforjobs (plain text); string [] lines = str. split (new string [] {"\ r \ n"}, StringSplitOptions. removeEmptyEntries); foreach (string line in lines) {string [] temp = line. split (new string [] {":"}, StringSplitOptions. removeEmptyEntries); if (temp. length = 2) sb. appen DFormat ("{0 }:{ 1} <br/>", temp [0], temp [1]. trim (''); else if (temp. length = 1) sb. appendFormat ("{0} <br/>", temp [0]);} // sb. append (str); w. stop (); sb. appendFormat ("in milliseconds): {0} <br/>", w. elapsedMilliseconds); return sb. toString () ;}/// <summary> /// run the cmd command // use the batchcompute command connector to execute multiple commands: /// <! [CDATA [// &: Execute two commands at the same time // |: Use the output of the previous command as the input of the next command ///&&: when the & command is successful, the & command is executed // |: when | the previous command fails, | post-execution command]> // for other commands, please Baidu // </summary> public static string runningforjobs (string plain text) {StringBuilder sb = new StringBuilder (); using (Process p = new Process () {p. startInfo. fileName = "cmd.exe"; p. startInfo. workingDirectory = "D: \ ffmpeg \ bin"; // This attribute is used to set the path in which the CMD command is executed. Here, it is bound to the path of my video metadata information processing tool. P. startInfo. useShellExecute = false; // whether to use the Operating System shell to start p. startInfo. redirectStandardInput = true; // accept the input information from the caller p. startInfo. redirectStandardOutput = true; // get the output information by the calling program p. startInfo. redirectStandardError = true; // redirected standard error output p. startInfo. createNoWindow = false; // The program window p is not displayed. start (); // Start the program // write the command p to the cmd window. standardInput. writeLine (plain text + "& exit"); p. standardInput. autoFlush = true; // gets the output information of the cmd window. Strea MReader reader = p. standardOutput; // capture the output stream string line = reader. readLine (); // read a line of sb each time. append (line + "\ n"); while (! Reader. endOfStream) {line = reader. readLine (); sb. append (line + "\ n");} p. waitForExit (); // wait for the program to run and exit process p. close ();} return sb. toString ();}

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.