[C #] Add subtitles to Microsoft's official ASP video tutorial

Source: Internet
Author: User

Preface

Microsoft Virtual Academy provides a wide range of video materials for learning ASP. (Note 1)

Because the video server is located overseas, the domestic browsing speed is not ideal, fortunately, the official provide video and English subtitle files.

However, it provides the downloaded subtitle file as a text document without a timestamp, and the time-stamped subtitle file provided on the page is not a standard format subtitle file, so a simple subtitle maker is produced in C #.

Demand

1. Extract the caption start and end timestamp in the provided text. Since the official subtitle document only has a start time, you need to intercept the next subtitle start time as the end time and fine-tune it;

2. Extend the extracted timestamp to the SRT standard timestamp format. The time format of official subtitles does not conform to the format of SRT subtitle demand;

3. Output the standard format of the SRT subtitle file.

The output is as follows, followed by the original subtitle document, the exact SRT file, and the effect of adding subtitles to the video (note 2).

00:00:04we is Back.00:00:04and we is almost to the MVC partof ASP Introduction,00:00:09not quite, but almost.00 : 00:11what we ' re gonna do here are we ' Regonna give you a little bit ...

  

100:00:03.00--00:00:04.50we is back.200:00:04.55--00:00:09.50and We are almost to the MVC partof ASP  introduction,300:00:09.55-to 00:00:11.50not quite, but almost.400:00:11.55-to 00:00:13.50what we ' re gonna do here Is the we ' Regonna give you a little bit ...

  

  

  

Realize
usingSystem.IO;namespacetxttosrtforvideoonasp.net{classProgram {Static voidMain (string[] args) {            //read and output files            stringPath =@"D:\transcript.txt"; stringSubpath =@"D:\SUB.SRT"; using(StreamWriter sw=NewStreamWriter (subpath)) {                string[] Allline =file.readalllines (path); stringStarttime=""; stringEndTime ="";  for(inti =0; I < Allline.count (); i++)                {                    //read the first 8 characters per line as the start time of each captionStartTime = Adjusttime (Allline[i]. Substring (0,8),true); //reads the first 8 characters of the next line as the end time of each caption                    if(i = = (Allline.count ()-1))                        //Video End TimeEndTime ="00:19:24,00"; ElseEndTime= Adjusttime (allline[i+1]. Substring (0,8),false); //output Standard SRT format subtitlesSw. WriteLine ((i +1) +"\ r \ n"+ StartTime +" -"+ EndTime +"\ r \ n"+ Allline[i]. Substring (9)); }} Console.WriteLine ("Output Complete");        Console.readkey (); }        /// <summary>        ///provides a full timestamp format for SRT files, adding a small amount of delay to make the subtitle time more accurate/// </summary>        /// <param name= "Time" >Timestamp read from Transcript.txt</param>        /// <param name= "Start" >time is start</param>        /// <returns></returns>         Public Static stringAdjusttime (stringTime,BOOLstart) {            if(start)return(Timespan.parse (time) + timespan.fromseconds (0.55)). ToString (). Substring (0, One); Else                return(Timespan.parse (time) + timespan.fromseconds (0.5)). ToString (). Substring (0, One); }    }}

Note:

1.https://mva.microsoft.com/en-us/training-courses/introduction-to-asp-net-core-1-0-16841?l=yiobvee6c_3506218965

2. The first title due to the short time and the official time stamp incomplete with the second subtitle start time, need to be manually fine-tuned. Logic can be added for processing, but only one subtitle is not implemented in this example.

[C #] Add subtitles to Microsoft's official ASP video tutorial

Related Article

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.