0

字幕について助けが必要です =)

字幕付きの .srt ファイルが 2 つあります。1 つは英語で、もう 1 つはスロベニア語です。問題は、スロベニア語のファイルに適切なタイム コードがないため、字幕が実際のセリフよりも速いことです。私がやりたいことは、両方のファイルを読み取り、 eng.srt ファイルから字幕の数とタイムコードを取得し、 slo.srtファイルから字幕を取得し、すべてをcomplete.srtに書き込むプログラムを作成することです。それが Java であるか C であるかは気にしません。現在、C でプログラムを作成しようとしています。

次に、私がやりたいことを示します。

eng.srt (right timecode)

1
00:00:01,259 --> 00:00:03,734
<i>Previously on...</i>

2
00:00:03,746 --> 00:00:06,910
<i>Tom and Lynette drifted further apart,</i>

3
00:00:06,911 --> 00:00:09,275
<i>and Jane took advantage.</i>

4
00:00:09,440 --> 00:00:10,670
I'm scared.

5
00:00:10,671 --> 00:00:13,362
<i>Roy helped Karen face her cancer.</i>




slo.srt (right subtitles)

1
00:00:00,009 --> 00:00:02,484
<i>Prejšnič...</i>

2
00:00:02,496 --> 00:00:05,660
<i>Tom and Lynette
sta se še bolj odtujila,</i>

3
00:00:05,661 --> 00:00:08,025
<i>in Jane je to izkoristila.</i>

4
00:00:08,190 --> 00:00:09,420
Strah me je.

5
00:00:09,421 --> 00:00:12,112
<i>Roy se je pomagal Karen
soočiti z rakom.</i>



complete.srt (where i write)

1
00:00:01,259 --> 00:00:03,734
<i>Prejšnič...</i>

2
00:00:03,746 --> 00:00:06,910
<i>Tom and Lynette
sta se še bolj odtujila,</i>
...

これは私がこれまでに持っているものです(私は3つのファイルを開きます、私は行くにつれて私の仕事を更新します):

#include <stdio.h>
#include <stdlib.h>

int main()
{
   char ch, sf1[20], sf2[20], tf[20];
   FILE *source1, *source2, *target;

   //first source file
   printf("Enter name of first source file\n");
   gets(sf1);

   source1 = fopen(sf1, "r");

   //seconds source file
   printf("Enter name of second source file\n");
   gets(sf2);

   source2 = fopen(sf2, "r");

   if( source == NULL )
   {
      printf("Press any key to exit...\n");
      exit(EXIT_FAILURE);
   }

   //target file
   printf("Enter name of target file\n");
   gets(tf);

   target = fopen(tf, "w");

   if( target == NULL )
   {
      fclose(source);
      printf("Press any key to exit...\n");
      exit(EXIT_FAILURE);
   }




   printf("File writen successfully.\n");

   fclose(source1);
   fclose(source2);
   fclose(target);

   return 0;
}

私の問題は、プログラムにeng.srtファイルから数字のみを読み取るように指示する方法がわからないことです。字幕部分をスキップして待つよりも、slo.srt ファイルを読んで字幕を取り出して数字をスキップするよりも.

4

2 に答える 2

0

主なロジックは単純です。これがそのpseudo-codeためのものです。

for each subtitle in file1 and file2:
    extract_time_from_file1;
    extract_subtitle_from_file2;
    write_into_new_file_combining_the_time_and_string

完全に機能するコードは次のとおりです。

#include <iostream>
#include <fstream>
using namespace std;
string read_title_string(ifstream& in)
{
    string ans="";
    string tmp;
    getline(in, tmp);//neglect the subtitle number
    getline(in, tmp);//neglect the time..
    /*sub-title extraction*/
    while(1)//read until the blank line and store all the strings..
    {
     getline(in, tmp);
     if(tmp.length()==0)
        break;
    ans += tmp;
    }
    return ans;
}
string read_title_time(ifstream& in)
{
    string ans="";
    string tmp;
    getline(in, tmp);//ignore subtitle number..
    getline(in, ans);//this is what we want..
    while(1)//read until a blank line and ignore them..
    {
        getline(in, tmp);
        if(tmp.length()==0)
            break;
    }
    return ans;
}
int main()
{
    ifstream ins("slo.srt"),outs("eng.srt");
    ofstream ans("complete.srt");
    int count=1;
    while(!ins.eof() && !outs.eof())
    {
        ans<<count++<<endl;
        ans<<read_title_time(outs)<<endl;
        ans<<read_title_string(ins)<<endl;
        ans<<endl;
    }
    ins.close();outs.close();ans.close();
    return 0;
}

このコードはファイルの構造に依存していることに注意してください。コンテンツが別の方法で編成されている場合、これは機能しない可能性があります。お役に立てれば!!

于 2013-10-20T15:34:59.847 に答える