Exemple #1
0
int main (int argc, char** argv)
{
    flvtag_t tag;
    FILE* flv = flv_open_read (argv[1]);
    FILE* out = flv_open_write (argv[3]);

    int has_audio, has_video;
    flvtag_init (&tag);

    if (!flv_read_header (flv,&has_audio,&has_video)) {
        fprintf (stderr,"%s is not an flv file\n", argv[1]);
        return EXIT_FAILURE;
    }

    srt_t* head = srt_from_file (argv[2]);
    srt_t* srt = head;

    if (! head) {
        fprintf (stderr,"%s is not an srt file\n", argv[2]);
        return EXIT_FAILURE;
    }

    flv_write_header (out,has_audio,has_video);

    while (flv_read_tag (flv,&tag)) {
        // TODO handle B freame!
        if (srt && flvtag_pts_seconds (&tag) >= srt->timestamp && flvtag_avcpackettype_nalu == flvtag_avcpackettype (&tag)) {
            fprintf (stderr,"%f: %s\n", srt->timestamp, srt_data (srt));
            flvtag_addcaption (&tag, srt_data (srt));
            srt = srt->next;
        }

        flv_write_tag (out,&tag);
        // Write tag out here
    }

    srt_free (head);
    return EXIT_SUCCESS;
}
Exemple #2
0
int main(int argc, char** argv)
{
    flvtag_t tag;
    srt_t* old_srt = NULL;
    srt_cue_t* next_cue = NULL;
    double timestamp, offset = 0, clear_timestamp = 0;
    int has_audio, has_video;
    FILE* flv = flv_open_read(argv[1]);
    int fd = open(argv[2], O_RDWR);
    FILE* out = flv_open_write(argv[3]);

    flvtag_init(&tag);

    if (!flv_read_header(flv, &has_audio, &has_video)) {
        fprintf(stderr, "%s is not an flv file\n", argv[1]);
        return EXIT_FAILURE;
    }

    flv_write_header(out, has_audio, has_video);

    fprintf(stderr, "Reading flv from %s\n", argv[1]);
    fprintf(stderr, "Reading captons from %s\n", argv[2]);
    fprintf(stderr, "Writing flv to %s\n", argv[3]);

    while (flv_read_tag(flv, &tag)) {

        srt_t* cur_srt = srt_from_fd(fd);
        timestamp = flvtag_pts_seconds(&tag);

        if (cur_srt) {
            fprintf(stderr, "Loaded new SRT at time %f\n", timestamp);
            if (old_srt != NULL) {
                srt_free(old_srt);
            }
            old_srt = cur_srt;
            offset = timestamp;
            clear_timestamp = timestamp;
            next_cue = cur_srt->cue_head;
        }

        if (flvtag_avcpackettype_nalu == flvtag_avcpackettype(&tag)) {
            if (next_cue && (offset + next_cue->timestamp) <= timestamp) {
                fprintf(stderr, "T: %0.02f (%0.02fs):\n%s\n", (offset + next_cue->timestamp), next_cue->duration, srt_cue_data(next_cue));
                clear_timestamp = (offset + next_cue->timestamp) + next_cue->duration;
                flvtag_addcaption_text(&tag, srt_cue_data(next_cue));
                next_cue = next_cue->next;
            } else if (0 <= clear_timestamp && clear_timestamp <= timestamp) {
                fprintf(stderr, "T: %0.02f: [CAPTIONS CLEARED]\n", timestamp);
                flvtag_addcaption_text(&tag, NULL);
                clear_timestamp = -1;
            }
        }

        flv_write_tag(out, &tag);
    }

    srt_free(old_srt);
    flvtag_free(&tag);
    flv_close(flv);
    flv_close(out);
    return EXIT_SUCCESS;
}