I had the same problem and wrote this little code, which solved my problem:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
FILE *quelle,*ziel;
int i;
long maxsub,count,tmp,sub;
char puffer[10][200], *ptr,line[400];
if(argc != 3)
{
printf("Usage: srtlinejoin Filename CountOfSubtitles\n");
return EXIT_FAILURE;
}
maxsub = strtol( argv[2], &ptr, 10);
if( (quelle=fopen(argv[1],"r")) == NULL) {
fprintf(stderr, "Can't open %s\n", argv[1]);
return EXIT_FAILURE;
}
if( (ziel=fopen("out.srt","w")) == NULL) {
fprintf(stderr, "Can't open out.srt\n");
fclose(quelle);
return EXIT_FAILURE;
}
//read and write first line
fgets(puffer[0], 200, quelle);
fputs(puffer[0], ziel);
for(count=1; count < maxsub;count++)
//for(count=1; count <= 3;count++)
{
//printf("Processing subtitle %d\n",count);
tmp=0;
//Read and write time
fgets(puffer[0], 200, quelle);
fputs(puffer[0], ziel);
do {
fgets(puffer[tmp], 200, quelle);
//Scan for next Subtitle
sub = strtol( puffer[tmp], &ptr, 10);
tmp++;
}
while(sub != (count+1));
//Der Untertitel hat nur eine Zeile
if (strlen(puffer[1]) == 2)
{
fputs(puffer[0], ziel); //New Subtitle
fputs(puffer[1], ziel); //Next empty line
fputs(puffer[2], ziel); //Next number
}
//Der Untertitel hat zwei Zeile
if ((strlen(puffer[1]) > 2) && (strlen(puffer[2]) == 2))
{
for(i=0;i<400;i++)
line[i]=0;
strncpy(line,puffer[0],(strlen(puffer[0])-2));
strcat(line," ");
strcat(line,puffer[1]);
fputs(line, ziel); //New Subtitle
fputs(puffer[2], ziel); //Next empty line
fputs(puffer[3], ziel); //Next number
}
//Der Untertitel hat mehr als zwei Zeile
if ((strlen(puffer[1]) == 2) && (strlen(puffer[2]) == 2))
{
printf("Attention: The subtitles has more than two lines\n");
}
}
printf("Check last subtitle!\n");
fclose(quelle);
fclose(ziel);
return EXIT_SUCCESS;
}