Changeset 214

Show
Ignore:
Timestamp:
27/11/08 20:31:37 (6 weeks ago)
Author:
duncan
Message:

Updated language settings

Location:
trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/vbi2srt/Makefile

    r213 r214  
    1 VERSION = -0.1.11 
     1VERSION = -0.2.02 
    22 
    33PREFIX = /usr/local 
  • trunk/vbi2srt/args.c

    r212 r214  
    9393    opt->libopt.input_name = "/dev/video0"; 
    9494    opt->input = STDIN_FILENO; 
    95     opt->libopt.output_given = 0; 
    96     opt->libopt.output_name = "/dev/video16"; 
     95    opt->output_given = 0; 
     96    opt->output_name = "/dev/video16"; 
    9797    opt->output = STDOUT_FILENO; 
    9898    opt->time_offset_given = 0; 
     
    103103    opt->vbi_name = "/dev/vbi0"; 
    104104    opt->vbi = 0; 
    105     opt->srt_given = 0; 
    106     opt->srt_name = "/dev/video0.srt"; 
    107     opt->srt = 0; 
     105    opt->libopt.output_given = 0; 
     106    opt->libopt.output_name = "/dev/video0.libopt.output"; 
     107    opt->libopt.output = 0; 
    108108    opt->srt_colour = 0; 
    109109    opt->libopt.pagenum_given = 0; 
     
    124124    fwprintf(stderr, L"input_given=%s\n", opt->libopt.input_given ? "yes" : "no"); 
    125125    fwprintf(stderr, L"input_name=%s\n", opt->libopt.input_name); 
    126     fwprintf(stderr, L"output_given=%s\n", opt->libopt.output_given ? "yes" : "no"); 
    127     fwprintf(stderr, L"output_name=%s\n", opt->libopt.output_name); 
     126    fwprintf(stderr, L"output_given=%s\n", opt->output_given ? "yes" : "no"); 
     127    fwprintf(stderr, L"output_name=%s\n", opt->output_name); 
    128128    fwprintf(stderr, L"duration_given=%s\n", opt->duration_given ? "yes" : "no"); 
    129129    fwprintf(stderr, L"duration=%d\n", opt->duration); 
     
    132132    fwprintf(stderr, L"vbi_given=%s\n", opt->vbi_given ? "yes" : "no"); 
    133133    fwprintf(stderr, L"vbi_name=%s\n", opt->vbi_name); 
    134     fwprintf(stderr, L"srt_given=%s\n", opt->srt_given ? "yes" : "no"); 
    135     fwprintf(stderr, L"srt_name=%s\n", opt->srt_name); 
     134    fwprintf(stderr, L"srt_given=%s\n", opt->libopt.output_given ? "yes" : "no"); 
     135    fwprintf(stderr, L"srt_name=%s\n", opt->libopt.output_name); 
    136136    fwprintf(stderr, L"srt_colour=%s\n", opt->srt_colour ? "yes" : "no"); 
    137137    fwprintf(stderr, L"vps_given=%s\n", opt->vps_given ? "yes" : "no"); 
     
    418418 
    419419        case 's':       /* set srt device.  */ 
    420             if (opt->srt_given) { 
     420            if (opt->libopt.output_given) { 
    421421                fwprintf(stderr, L"%s: `--srt' (`-%c') option given more than once\n", 
    422422                    opt->libopt.program, c); 
    423423                return 1; 
    424424            } 
    425             opt->srt_given = 1; 
    426             opt->srt_name = strdup(optarg); 
     425            opt->libopt.output_given = 1; 
     426            opt->libopt.output_name = strdup(optarg); 
    427427            break; 
    428428 
     
    442442 
    443443        case 'o':       /* set video output device.  */ 
    444             if (opt->libopt.output_given) { 
     444            if (opt->output_given) { 
    445445                fwprintf(stderr, L"%s: `--output' (`-%c') option given more than once\n", 
    446446                    opt->libopt.program, c); 
    447447                return 1; 
    448448            } 
    449             opt->libopt.output_given = 1; 
    450             opt->libopt.output_name = strdup(optarg); 
     449            opt->output_given = 1; 
     450            opt->output_name = strdup(optarg); 
    451451            break; 
    452452 
  • trunk/vbi2srt/args.h

    r202 r214  
    4242    char *vbi_name;          /* vbi device. */ 
    4343    int vbi; 
    44     int srt_given;           /* Whether srt device was given. */ 
    45     char *srt_name;          /* srt filename. */ 
    46     FILE *srt; 
     44    int output_given;        /* Whether output device was given. */ 
     45    char *output_name;       /* output filename. */ 
     46    FILE *output_fh; 
     47    //int srt_given;           /* Whether srt device was given. */ 
     48    //char *srt_name;          /* srt filename. */ 
     49    //FILE *srt; 
    4750    int srt_colour;          /* Whether to add colour codes to srt output. */ 
    4851    int vps_given;           /* Whether VPS was given. */ 
  • trunk/vbi2srt/main.c

    r212 r214  
    8181    if (signum == 15) { 
    8282        if (opt.libopt.printverbose) { 
    83             fwprintf(stderr, L"termination_handler called with %d, ignored.\n", signum); 
     83            vbiprintf(0, stderr, L"termination_handler called with %d, ignored.\n", signum); 
    8484        } 
    8585        return; 
     
    8787    */ 
    8888    if (opt.libopt.printverbose) { 
    89         fwprintf(stderr, L"termination_handler called with %d\n", signum); 
     89        vbiprintf(0, stderr, L"termination_handler called with %d\n", signum); 
    9090    } 
    9191    terminate = 1; 
     
    9797    ssize_t bytes_read; 
    9898    ssize_t bytes_written; 
    99     fwprintf(stderr, L"verbose=%d\n", wd->opt->libopt.printverbose); 
    100     fwprintf(stderr, L"mpeg_worker thread started\n"); 
     99    vbiprintf(0, stderr, L"verbose=%d\n", wd->opt->libopt.printverbose); 
     100    vbiprintf(0, stderr, L"mpeg_worker thread started\n"); 
    101101    // wait for the streaming signal 
    102102    while (!wd->streaming) { 
    103103        if (terminate) { 
    104             fwprintf(stderr, L"mpeg_worker thread terminated not streaming\n"); 
     104            vbiprintf(0, stderr, L"mpeg_worker thread terminated not streaming\n"); 
    105105            goto finished; 
    106106        } 
    107107        usleep(MPEG_DELAY); 
    108108    } 
    109     fwprintf(stderr, L"mpeg_worker started recording\n"); 
     109    vbiprintf(0, stderr, L"mpeg_worker started recording\n"); 
    110110    for (;;) { 
    111111        if (terminate) { 
     
    114114                enum v4l2_buf_type buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 
    115115                if (ioctl(wd->opt->input, VIDIOC_STREAMOFF, &buf_type) < 0) { 
    116                     fwprintf(stderr, L"VIDIOC_STREAMOFF failed: %s\n", strerror(errno)); 
     116                    vbiprintf(0, stderr, L"VIDIOC_STREAMOFF failed: %s\n", strerror(errno)); 
    117117                    break; 
    118118                } 
     
    121121                struct v4l2_encoder_cmd encoder_cmd = { V4L2_ENC_CMD_STOP, V4L2_ENC_CMD_STOP_AT_GOP_END }; 
    122122                if (ioctl(opt.input, VIDIOC_ENCODER_CMD, &encoder_cmd) != 0) { 
    123                     fwprintf(stderr, L"cannot set VIDIOC_ENCODER_CMD for \"%s\": %s\n", 
     123                    vbiprintf(0, stderr, L"cannot set VIDIOC_ENCODER_CMD for \"%s\": %s\n", 
    124124                        opt.libopt.input_name, strerror(errno)); 
    125125                } 
    126126#endif 
    127127                if (wd->opt->libopt.printverbose == 3) { 
    128                     fwprintf(stderr, L"\n"); 
    129                 } 
    130                 fwprintf(stderr, L"mpeg_worker thread streaming off\n"); 
     128                    vbiprintf(0, stderr, L"\n"); 
     129                } 
     130                vbiprintf(0, stderr, L"mpeg_worker thread streaming off\n"); 
    131131                wd->streaming = 0; 
    132132            } 
     
    134134        bytes_read = read(wd->opt->input, wd->video_buffer, wd->video_buffer_size); 
    135135        if (wd->opt->libopt.printverbose >= 4) { 
    136             fwprintf(stderr, L"bytes_read=%d, video_buffer_size=%d\n", bytes_read, wd->video_buffer_size); 
     136            vbiprintf(0, stderr, L"bytes_read=%d, video_buffer_size=%d\n", bytes_read, wd->video_buffer_size); 
    137137        } 
    138138        if (bytes_read == 0) { 
    139             fwprintf(stderr, L"mpeg_worker thread terminated no more data\n"); 
     139            vbiprintf(0, stderr, L"mpeg_worker thread terminated no more data\n"); 
    140140            break; 
    141141        } else if (bytes_read < 0) { 
    142             fwprintf(stderr, L"mpeg_worker thread terminated data read error\n"); 
    143             fwprintf(stderr, L"cannot read from \"%s\" %s\n", wd->opt->libopt.input_name, strerror(errno)); 
     142            vbiprintf(0, stderr, L"mpeg_worker thread terminated data read error\n"); 
     143            vbiprintf(0, stderr, L"cannot read from \"%s\" %s\n", wd->opt->libopt.input_name, strerror(errno)); 
    144144            break; 
    145145        } 
    146146        bytes_written = write(wd->opt->output, wd->video_buffer, bytes_read); 
    147         if (wd->opt->libopt.printverbose >= 4) { 
    148             fwprintf(stderr, L"bytes_written=%d, bytes_read=%d\n", bytes_written, bytes_read); 
    149         } 
    150         if (wd->opt->libopt.printverbose == 3) { 
    151             fwprintf(stderr, L"%c", wd->streaming ? ',' : '.'); 
     147        if (wd->opt->libopt.printverbose >= 5) { 
     148            vbiprintf(0, stderr, L"bytes_written=%d, bytes_read=%d\n", bytes_written, bytes_read); 
     149        } 
     150        if (wd->opt->libopt.printverbose == 4) { 
     151            vbiprintf(0, stderr, L"%c", wd->streaming ? ',' : '.'); 
    152152        } 
    153153        fflush(stderr); 
    154154    } 
    155     fwprintf(stderr, L"mpeg_worker stopped recording\n"); 
     155    vbiprintf(0, stderr, L"mpeg_worker stopped recording\n"); 
    156156finished: 
    157157    if (wd->opt->libopt.printverbose == 3) { 
    158         fwprintf(stderr, L"\n"); 
    159     } 
    160     fwprintf(stderr, L"mpeg_worker thread finished\n"); 
     158        vbiprintf(0, stderr, L"\n"); 
     159    } 
     160    vbiprintf(0, stderr, L"mpeg_worker thread finished\n"); 
    161161    fflush(stderr); 
    162162    return NULL; 
     
    166166{ 
    167167    if (opt.libopt.printverbose) { 
    168         fwprintf(stderr, L"vbi_worker thread started\n"); 
     168        vbiprintf(0, stderr, L"vbi_worker thread started\n"); 
    169169    } 
    170170    for (;;) { 
     
    175175    } 
    176176    if (opt.libopt.printverbose) { 
    177         fwprintf(stderr, L"vbi_worker thread finished\n"); 
     177        vbiprintf(0, stderr, L"vbi_worker thread finished\n"); 
    178178    } 
    179179 
     
    242242                break; 
    243243            } 
    244             fwprintf(stderr, L"%s\n", env[i]); 
     244            vbiprintf(0, stderr, L"%s\n", env[i]); 
    245245        } 
    246246    } 
    247247 
    248248    if (opt.libopt.printverbose) { 
    249         fwprintf(stderr, L"Version is \"%s-%s\"\n", opt.libopt.program, opt.libopt.version); 
    250         fwprintf(stderr, L"locale is \"%s\", codeset is \"%s\"\n", opt.libopt.locale, nl_langinfo(CODESET)); 
    251         fwprintf(stderr, L"\n"); 
     249        vbiprintf(0, stderr, L"Version is \"%s-%s\"\n", opt.libopt.program, opt.libopt.version); 
     250        vbiprintf(0, stderr, L"locale is \"%s\", codeset is \"%s\"\n", opt.libopt.locale, nl_langinfo(CODESET)); 
     251        vbiprintf(0, stderr, L"\n"); 
    252252    } 
    253253 
    254254    // Some signal handlers to terminate cleanly 
    255255    if (signal (SIGINT, termination_handler) == SIG_IGN) { 
    256         fwprintf(stderr, L"cannot set signal handler \"%s\": %s\n", "SIGINT", strerror(errno)); 
     256        vbiprintf(0, stderr, L"cannot set signal handler \"%s\": %s\n", "SIGINT", strerror(errno)); 
    257257        signal (SIGINT, SIG_IGN); 
    258258    } 
    259259    if (signal (SIGHUP, termination_handler) == SIG_IGN) { 
    260         fwprintf(stderr, L"cannot set signal handler \"%s\": %s\n", "SIGHUP", strerror(errno)); 
     260        vbiprintf(0, stderr, L"cannot set signal handler \"%s\": %s\n", "SIGHUP", strerror(errno)); 
    261261        signal (SIGHUP, SIG_IGN); 
    262262    } 
    263263    if (signal (SIGTERM, termination_handler) == SIG_IGN) { 
    264         fwprintf(stderr, L"cannot set signal handler \"%s\": %s\n", "SIGTERM", strerror(errno)); 
     264        vbiprintf(0, stderr, L"cannot set signal handler \"%s\": %s\n", "SIGTERM", strerror(errno)); 
    265265        signal (SIGTERM, SIG_IGN); 
    266266    } 
     
    268268    opt.input = open(opt.libopt.input_name, O_RDONLY|O_LARGEFILE); 
    269269    if (opt.input == -1) { 
    270         fwprintf(stderr, L"cannot open  \"%s\": %s\n", opt.libopt.input_name, strerror(errno)); 
     270        vbiprintf(0, stderr, L"cannot open  \"%s\": %s\n", opt.libopt.input_name, strerror(errno)); 
    271271        return 1; 
    272272    } 
    273273    if (fstat64(opt.input, &status) == -1) { 
    274         fwprintf(stderr, L"cannot stat  \"%s\": %s\n", opt.libopt.input_name, strerror(errno)); 
     274        vbiprintf(0, stderr, L"cannot stat  \"%s\": %s\n", opt.libopt.input_name, strerror(errno)); 
    275275        return 1; 
    276276    } 
     
    280280        int end_gop = 1; 
    281281        if (ioctl(opt.input, IVTV_IOC_S_GOP_END, &end_gop) != 0) { 
    282             fwprintf(stderr, L"cannot set IVTV_IOC_S_GOP_END for \"%s\": %s\n", 
     282            vbiprintf(0, stderr, L"cannot set IVTV_IOC_S_GOP_END for \"%s\": %s\n", 
    283283                opt.libopt.input_name, strerror(errno)); 
    284284        } 
     
    298298        v4l2_format.fmt.sliced.reserved[1] = 0; 
    299299        if (ioctl(opt.input, VIDIOC_S_FMT, &v4l2_format) < 0) { 
    300             //fwprintf(stderr, L"VIDIOC_S_FMT failed: \"%s\" %d\n", strerror(errno), errno); 
    301             fwprintf(stderr, L"ioctl(%d, VIDIOC_S_FMT, v4l2_format): %s\n", opt.input, strerror(errno)); 
     300            //vbiprintf(0, stderr, L"VIDIOC_S_FMT failed: \"%s\" %d\n", strerror(errno), errno); 
     301            vbiprintf(0, stderr, L"ioctl(%d, VIDIOC_S_FMT, v4l2_format): %s\n", opt.input, strerror(errno)); 
    302302        } 
    303303        memset(&v4l2_format, 0, sizeof(v4l2_format)); 
    304304        v4l2_format.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; 
    305305        if (ioctl(opt.input, VIDIOC_G_FMT, &v4l2_format) < 0) { 
    306             fwprintf(stderr, L"ioctl(%d, VIDIOC_G_FMT, v4l2_format): %s\n", opt.input, strerror(errno)); 
    307         } 
    308         fwprintf(stderr, L"v4l2_format: 0x%0X\n", v4l2_format.fmt.sliced.service_set); 
     306            vbiprintf(0, stderr, L"ioctl(%d, VIDIOC_G_FMT, v4l2_format): %s\n", opt.input, strerror(errno)); 
     307        } 
     308        vbiprintf(0, stderr, L"v4l2_format: 0x%0X\n", v4l2_format.fmt.sliced.service_set); 
    309309 
    310310        struct v4l2_queryctrl qctrl; 
    311311        const char *name = "Stream VBI Format"; 
    312312        int ctrl_id = find_control_id(opt.input, name, &qctrl); 
    313         fwprintf(stderr, L"0x%08X is the id for \"%s\"\n", ctrl_id, name); 
     313        vbiprintf(0, stderr, L"0x%08X is the id for \"%s\"\n", ctrl_id, name); 
    314314         
    315315        struct v4l2_ext_controls ext_controls; 
     
    323323 
    324324        if (ioctl(opt.input, VIDIOC_G_EXT_CTRLS, &ext_controls) < 0) { 
    325             fwprintf(stderr, L"ioctl(%d, VIDIOC_G_EXT_CTRLS, ext_controls): %s\n", opt.input, strerror(errno)); 
     325            vbiprintf(0, stderr, L"ioctl(%d, VIDIOC_G_EXT_CTRLS, ext_controls): %s\n", opt.input, strerror(errno)); 
    326326            return 2; 
    327327        } 
     
    329329        switch (qctrl.type) { 
    330330        case V4L2_CTRL_TYPE_INTEGER: 
    331             fwprintf(stderr, L"%s (int): min=%d max=%d step=%d default=%d value=%d", name,  
     331            vbiprintf(0, stderr, L"%s (int): min=%d max=%d step=%d default=%d value=%d", name,  
    332332                qctrl.minimum, qctrl.maximum, qctrl.step, qctrl.default_value, ext_control[0].value); 
    333333            break; 
    334334        case V4L2_CTRL_TYPE_INTEGER64: 
    335             fwprintf(stderr, L"%s (int64): value=%lld", name, ext_control[0].value64); 
     335            vbiprintf(0, stderr, L"%s (int64): value=%lld", name, ext_control[0].value64); 
    336336            break; 
    337337        case V4L2_CTRL_TYPE_BOOLEAN: 
    338             fwprintf(stderr, L"%s (bool): default=%d value=%d", name, qctrl.default_value, ext_control[0].value); 
     338            vbiprintf(0, stderr, L"%s (bool): default=%d value=%d", name, qctrl.default_value, ext_control[0].value); 
    339339            break; 
    340340        case V4L2_CTRL_TYPE_MENU: 
    341             fwprintf(stderr, L"%s (menu): min=%d max=%d default=%d value=%d", name,  
     341            vbiprintf(0, stderr, L"%s (menu): min=%d max=%d default=%d value=%d", name,  
    342342                qctrl.minimum, qctrl.maximum, qctrl.default_value, ext_control[0].value); 
    343343            break; 
    344344        case V4L2_CTRL_TYPE_BUTTON: 
    345             fwprintf(stderr, L"%s (button)\n", name); 
     345            vbiprintf(0, stderr, L"%s (button)\n", name); 
    346346            break; 
    347347        default: 
    348348            break; 
    349349        } 
    350             fwprintf(stderr, L"%s (int): min=%d max=%d step=%d default=%d value=%d", name,  
     350            vbiprintf(0, stderr, L"%s (int): min=%d max=%d step=%d default=%d value=%d", name,  
    351351                qctrl.minimum, qctrl.maximum, qctrl.step, qctrl.default_value, ext_control[0].value); 
    352352        } 
    353353        if (opt.libopt.pagenum) { 
    354             fwprintf(stderr, L"pagenum=%d\n", opt.libopt.pagenum); 
     354            vbiprintf(0, stderr, L"pagenum=%d\n", opt.libopt.pagenum); 
    355355            ext_control[0].value = 1; 
    356356            if (ioctl(opt.input, VIDIOC_S_EXT_CTRLS, &ext_controls) < 0) { 
    357                 fwprintf(stderr, L"ioctl(%d, VIDIOC_S_EXT_CTRLS, ext_controls): %s\n", opt.input, strerror(errno)); 
     357                vbiprintf(0, stderr, L"ioctl(%d, VIDIOC_S_EXT_CTRLS, ext_controls): %s\n", opt.input, strerror(errno)); 
    358358                return 2; 
    359359            } 
     
    373373    } 
    374374 
    375     opt.output = open(opt.libopt.output_name, O_WRONLY|O_CREAT|O_LARGEFILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); 
     375    opt.output = open(opt.output_name, O_WRONLY|O_CREAT|O_LARGEFILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); 
    376376    if (opt.output == -1) { 
    377         fwprintf(stderr, L"cannot open \"%s\": %s\n", opt.libopt.output_name, strerror(errno)); 
     377        vbiprintf(0, stderr, L"cannot open \"%s\": %s\n", opt.output_name, strerror(errno)); 
    378378        return 1; 
    379379    } 
    380380    if (fstat64(opt.output, &status) == -1) { 
    381         fwprintf(stderr, L"cannot stat \"%s\": %s\n", opt.libopt.output_name, strerror(errno)); 
     381        vbiprintf(0, stderr, L"cannot stat \"%s\": %s\n", opt.output_name, strerror(errno)); 
    382382        return 1; 
    383383    } 
     
    385385 
    386386    if (opt.input_isdevice && opt.output_isdevice) { 
    387         fwprintf(stderr, L"WARNING: \"%s\" and \"%s\" are devices.\n", opt.libopt.input_name, opt.libopt.output_name); 
     387        vbiprintf(0, stderr, L"WARNING: \"%s\" and \"%s\" are devices.\n", opt.libopt.input_name, opt.libopt.output_name); 
    388388    } 
    389389 
    390390    opt.vbi = open(opt.vbi_name, O_RDONLY|O_LARGEFILE|O_NONBLOCK); 
    391391    if (opt.vbi == -1) { 
    392         fwprintf(stderr, L"cannot open \"%s\": %s\n", opt.vbi_name, strerror(errno)); 
     392        vbiprintf(0, stderr, L"cannot open \"%s\": %s\n", opt.vbi_name, strerror(errno)); 
    393393        return 1; 
    394394    } 
    395395    if (fstat64(opt.vbi, &status) == -1) { 
    396         fwprintf(stderr, L"cannot stat \"%s\": %s\n", opt.vbi_name, strerror(errno)); 
     396        vbiprintf(0, stderr, L"cannot stat \"%s\": %s\n", opt.vbi_name, strerror(errno)); 
    397397        return 1; 
    398398    } 
    399399    opt.vbi_isdevice = S_ISCHR(status.st_mode); 
    400400    if (! opt.vbi_isdevice) { 
    401         fwprintf(stderr, L"\"%s\" is not a character device\n", opt.vbi_name); 
    402         return 1; 
    403     } 
    404  
    405  
    406     if (! opt.srt_given) { 
     401        vbiprintf(0, stderr, L"\"%s\" is not a character device\n", opt.vbi_name); 
     402        return 1; 
     403    } 
     404 
     405 
     406    if (! opt.libopt.output_given) { 
    407407        if (opt.input_isdevice) { 
    408408            int len = strlen(opt.libopt.output_name); 
    409409            char *p = rindex(basename(opt.libopt.output_name), '.'); 
    410             opt.srt_name = malloc(len+5); 
    411             if (opt.srt_name == 0) { 
     410            opt.libopt.output_name = malloc(len+5); 
     411            if (opt.libopt.output_name == 0) { 
    412412                return 1; 
    413413            } 
     
    415415                len = p - opt.libopt.output_name; 
    416416            } 
    417             strcpy(&opt.srt_name[0], opt.libopt.output_name); 
    418             strcpy(&opt.srt_name[len], ".srt"); 
     417            strcpy(&opt.libopt.output_name[0], opt.output_name); 
     418            strcpy(&opt.libopt.output_name[len], ".srt"); 
    419419        } else { 
    420420            int len = strlen(opt.libopt.input_name); 
    421421            char *p = rindex(basename(opt.libopt.input_name), '.'); 
    422             opt.srt_name = malloc(len+5); 
    423             if (opt.srt_name == 0) { 
     422            opt.libopt.output_name = malloc(len+5); 
     423            if (opt.libopt.output_name == 0) { 
    424424                return 1; 
    425425            } 
     
    427427                len = p - opt.libopt.input_name; 
    428428            } 
    429             strcpy(&opt.srt_name[0], opt.libopt.input_name); 
    430             strcpy(&opt.srt_name[len], ".srt"); 
     429            strcpy(&opt.libopt.output_name[0], opt.libopt.input_name); 
     430            strcpy(&opt.libopt.output_name[len], ".srt"); 
    431431        } 
    432432    } 
    433433 
    434434    if (opt.libopt.pagenum) { 
    435         opt.srt = fopen(opt.srt_name, "w"); 
    436         if (opt.srt_name == NULL) { 
    437             fwprintf(stderr, L"cannot open srt \"%s\": %s\n", opt.srt_name, strerror(errno)); 
     435        opt.libopt.output = fopen(opt.libopt.output_name, "w"); 
     436        if (opt.libopt.output_name == NULL) { 
     437            vbiprintf(0, stderr, L"cannot open srt \"%s\": %s\n", opt.libopt.output_name, strerror(errno)); 
    438438            return 1; 
    439439        } 
    440         if (fstat64(fileno(opt.srt), &status) == -1) { 
    441             fwprintf(stderr, L"cannot stat \"%s\": %s\n", opt.srt_name, strerror(errno)); 
     440        if (fstat64(fileno(opt.libopt.output), &status) == -1) { 
     441            vbiprintf(0, stderr, L"cannot stat \"%s\": %s\n", opt.libopt.output_name, strerror(errno)); 
    442442            return 1; 
    443443        } 
    444444        opt.srt_isdevice = S_ISCHR(status.st_mode); 
    445445        if (opt.srt_isdevice) { 
    446             fwprintf(stderr, L"\"%s\" is a character device\n", opt.srt_name); 
     446            vbiprintf(0, stderr, L"\"%s\" is a character device\n", opt.libopt.output_name); 
    447447            return 1; 
    448448        } 
     
    455455    if (! opt.libopt.utf8) { 
    456456        if (opt.libopt.pagenum) { 
    457             fwprintf(stderr, L"WARNING: Subtitles will contain unicode characters but locale is \"%s\"\n",  
     457            vbiprintf(0, stderr, L"WARNING: Subtitles will contain unicode characters but locale is \"%s\"\n",  
    458458                opt.libopt.locale); 
    459459        } 
     
    470470    vbidata.fmt.fmt.sliced.reserved[1] = 0; 
    471471    if (ioctl(opt.vbi, VIDIOC_S_FMT, &vbidata.fmt) < 0) { 
    472         fwprintf(stderr, L"VIDIOC_S_FMT failed: \"%s\" %d\n", strerror(errno), errno); 
     472        vbiprintf(0, stderr, L"VIDIOC_S_FMT failed: \"%s\" %d\n", strerror(errno), errno); 
    473473        close(opt.vbi); 
    474474        return 1; 
     
    476476 
    477477    if (opt.libopt.printverbose >= 4) { 
    478         fwprintf(stderr, L"service_set=%08x, io_size=%d\n",  
     478        vbiprintf(0, stderr, L"service_set=%08x, io_size=%d\n",  
    479479            vbidata.fmt.fmt.sliced.service_set, vbidata.fmt.fmt.sliced.io_size); 
    480         fwprintf(stderr, L"\n"); 
     480        vbiprintf(0, stderr, L"\n"); 
    481481    } 
    482482 
     
    484484 
    485485    if (clock_gettime (CLOCK_REALTIME, &now) != 0) { 
    486         fwprintf(stderr, L"clock_gettime failed: \"%s\" %d\n", strerror(errno), errno); 
     486        vbiprintf(0, stderr, L"clock_gettime failed: \"%s\" %d\n", strerror(errno), errno); 
    487487    } 
    488488    vps_pat_watchdog(&now); 
     
    494494    if (pthread_create (&mpeg_worker_thread, NULL, mpeg_worker, (void *)&mpegdata) != 0) { 
    495495        perror("mpeg_worker_thread"); 
    496         fwprintf(stderr, L"Failed to create mpeg worker thread \"%s\"\n", strerror(errno)); 
     496        vbiprintf(0, stderr, L"Failed to create mpeg worker thread \"%s\"\n", strerror(errno)); 
    497497        return 1; 
    498498    } 
     
    500500    if (pthread_create (&vbi_worker_thread, NULL, vbi_worker, (void *)&vbidata) != 0) { 
    501501        perror("vbi_worker_thread"); 
    502         fwprintf(stderr, L"Failed to create vbi worker thread \"%s\"\n", strerror(errno)); 
     502        vbiprintf(0, stderr, L"Failed to create vbi worker thread \"%s\"\n", strerror(errno)); 
    503503        return 1; 
    504504    } 
     
    508508        subtitles_init(&opt, &now); 
    509509    } 
     510 
     511    if (clock_gettime (CLOCK_REALTIME, &now) != 0) { 
     512        vbiprintf(0, stderr, L"clock_gettime failed: \"%s\" %d\n", strerror(errno), errno); 
     513    } 
     514    prev_t.now = now; 
     515    prev_t.fno = frames; 
    510516 
    511517    for (;;) { 
     
    517523            pthread_join (vbi_worker_thread, NULL); 
    518524            pthread_join (mpeg_worker_thread, NULL); 
    519             fwprintf(stderr, L"terminated\n"); 
     525            vbiprintf(0, stderr, L"terminated\n"); 
    520526            break; 
    521527        } 
    522528 
    523529        if (clock_gettime (CLOCK_REALTIME, &now) != 0) { 
    524             fwprintf(stderr, L"clock_gettime failed: \"%s\" %d\n", strerror(errno), errno); 
    525         } 
    526  
    527         if (clock_gettime (CLOCK_REALTIME, &now) != 0) { 
    528             fwprintf(stderr, L"clock_gettime failed: \"%s\" %d\n", strerror(errno), errno); 
     530            vbiprintf(0, stderr, L"clock_gettime failed: \"%s\" %d\n", strerror(errno), errno); 
    529531        } 
    530532        this_t.now = now; 
     
    534536        if (opt.libopt.printverbose >= 4) { 
    535537            if (vbi_bytes_read >= 0) { 
    536                 fwprintf(stderr, L"vbi_bytes_read=%d\n", vbi_bytes_read); 
     538                vbiprintf(0, stderr, L"vbi_bytes_read=%d\n", vbi_bytes_read); 
    537539            } 
    538540        } 
     
    559561                if (opt.libopt.printverbose) { 
    560562                    vps_time(&now); 
    561                     fwprintf(stderr, L"vps state %s->%s\n", vps_state_name(laststate), vps_state_name(state)); 
     563                    vbiprintf(0, stderr, L"vps state %s->%s\n", vps_state_name(laststate), vps_state_name(state)); 
    562564