示例#1
0
int main(int argc, char *argv[])
{
    /* notes.
     * looking for total time I'm sure .... it in splt_struct: long total_time
     * that's found as split in _splt_state
     * note underscore.
     * where is it normalised?
     * found in include/libmp3splt.h
     * typedef struct _splt_state splt_state;
     * However this is a very OO type c code
     * claim to have private var and funcs.
     * maybe that total timeis not allowed. 
     * Need to "get" it
     */




  if (argc != 2) {
    fprintf(stderr, "Please provide the input file to be split as the first argument.\n");
    fflush(stderr);
    return EXIT_FAILURE;
  }

  splt_code error = SPLT_OK;

  //initialisation of the main state, the main activity container, so to speak.
  splt_state *state = mp3splt_new_state(NULL);

  //register callback functions
  mp3splt_set_message_function(state, print_message_from_library, NULL);
  mp3splt_set_split_filename_function(state, print_split_filename, NULL);

  //look for the available plugins
  error = mp3splt_find_plugins(state);
  print_confirmation_and_exit_if_error(state, error);

  //set the input filename to be split
  mp3splt_set_filename_to_split(state, argv[1]);

  splt_struct *m=state->split;
  // printf("tt: %li\n", state->split->total_time); 
  //append two splitpoints
  splt_point *first_point = mp3splt_point_new(0, NULL);
  mp3splt_append_splitpoint(state, first_point);
  splt_point *second_point = mp3splt_point_new(100 * 60 * 1, NULL);
  mp3splt_append_splitpoint(state, second_point);

  //do the effective split
  error = mp3splt_split(state);
  print_confirmation_and_exit_if_error(state, error);

  //free the memory of the main state
  mp3splt_free_state(state);

  return EXIT_SUCCESS;
}
示例#2
0
//Main program
//Please note that not all errors are handled in this example.
//Compile with:
//    $ gcc minimal.c -o minimal -lmp3splt
static void print_confirmation_and_exit_if_error(splt_state *state, splt_code error) //Callback function that handles error code from libmp3splt.
{
  char *message = mp3splt_get_strerror(state, error);
  if (!message)
    return;

  if (error < 0) {
    fprintf(stderr, "%s\n", message);
    fflush(stderr);
    mp3splt_free_state(state);
    exit(1);
  } else {
    fprintf(stdout, "%s\n", message);
    fflush(stdout);
  }
  free(message);
}
示例#3
0
int main(int argc, char *argv[])
{
    if(argc != 3) {
        printf("Usage: argument 1) mp3 file 2) associated EDL file.\n");
        exit(EXIT_FAILURE);
    }
    int i, j, nr, nc;
    int *mat=processinpf(argv[2], &nr, &nc);
    int divby3=(nr*nc)%3;
    if(divby3) { // EDL files have 3 columns ... bail out if there are not three columns.
        printf("Error: the EDL file is not a multiple of 3. Bailing out.\n");
        exit(EXIT_FAILURE);
    }
#ifdef DBG
    printf("nr: %d nc: %d\n", nr, nc); 
#endif
    int *newmat=malloc((2*nr*nc/3)*sizeof(int)); // we'll create a new matrix without the third column.
    int k=0;
    for(i=0;i<nr;++i)
        for(j=0;j<2;++j)
            newmat[k++]=mat[nc*i+j] -PBACK;
    free(mat);
    /* OK, time for the mp3splt code */
    splt_code error = SPLT_OK; /* a start section I expect */
    //initialisation of the main state, always necessary.
    splt_state *state = mp3splt_new_state(NULL);
    //register callback functions, necessary cos that's the way this library is built. Note references to above defined function.
    mp3splt_set_message_function(state, print_message_from_library, NULL);
    mp3splt_set_split_filename_function(state, print_split_filename, NULL);
    //look for the available plugins .. maybe not necessary, but go with it for time being.
    error = mp3splt_find_plugins(state);
    print_confirmation_and_exit_if_error(state, error);
    //set the input filename to be split
    mp3splt_set_filename_to_split(state, argv[1]);
    // OK, let's declare the points
//    splt_point *p1 = NULL, *p2=NULL;
    mp3splt_append_splitpoint(state, mp3splt_point_new(0, NULL));
#ifdef DBG
    printf("EDL timings printed now\n"); 
#endif
    for(i=0;i<nr;++i) {
#ifdef DBG
        printf("%dm%ds%dh -> ", newmat[2*i]/6000, (newmat[2*i] - 6000*(newmat[2*i]/6000))/100, (newmat[2*i] - 6000*(newmat[2*i]/6000)) - 100*((newmat[2*i] - 6000*(newmat[2*i]/6000))/100)); // yes, these minute second conversions are hellish, no way around it.
#endif
        mp3splt_append_splitpoint(state, mp3splt_point_new(newmat[2*i], NULL));
#ifdef DBG
        printf("%dm%ds%dh\n", newmat[2*i+1]/6000, (newmat[2*i+1] - 6000*(newmat[2*i+1]/6000))/100, (newmat[2*i+1] - 6000*(newmat[2*i+1]/6000)) - 100*((newmat[2*i+1] - 6000*(newmat[2*i+1]/6000))/100)); // note these conversion exactly reflect what libmp3splt things it's doing. See auto output filename.
#endif
        mp3splt_append_splitpoint(state, mp3splt_point_new(newmat[2*i+1], NULL));
    }
    mp3splt_append_splitpoint(state, mp3splt_point_new(1999*6000, NULL)); // split point for end of file
#ifdef DBG
    printf("\n"); 
#endif
    error = mp3splt_split(state);
    print_confirmation_and_exit_if_error(state, error);
    mp3splt_free_state(state);

    free(newmat); /* we've rendered the edl matrix into a integers now, as in sampa */
    return EXIT_SUCCESS;
}
示例#4
0
static int mp3splt(segmenter_t * S)
{
  char *ext = getExt(S->segment.filename);

  //log_debug("mp3splt_split: entered");

  mc_free(S->memory_block);
  S->size = -1;
  S->memory_block = NULL;
#ifndef SEGMENT_USING_FILE
  FILE *f = open_memstream((char **)&S->memory_block, &S->size);
#endif

  int begin_offset_in_hs = S->segment.begin_offset_in_ms / 10;
  int end_offset_in_hs = -1;
  if (S->segment.end_offset_in_ms >= 0) {
    end_offset_in_hs = S->segment.end_offset_in_ms / 10;
  }
  // Creating state
  splt_state *state = mp3splt_new_state(NULL);
  //log_debug("new state");
  mp3splt_find_plugins(state);
  //log_debug("plugins found");

  // Set split path and custom name
  mp3splt_set_path_of_split(state, "/tmp");
  //log_debug("split path set");
  mp3splt_set_int_option(state, SPLT_OPT_OUTPUT_FILENAMES, SPLT_OUTPUT_CUSTOM);
  //log_debug("custom split set");

  // Set filename to split and pretend mode, for memory based splitting
  mp3splt_set_filename_to_split(state, S->segment.filename);
  //log_debug("filename to split set");
#ifndef SEGMENT_USING_FILE
  mp3splt_set_int_option(state, SPLT_OPT_PRETEND_TO_SPLIT, SPLT_TRUE);
  mp3splt_set_pretend_to_split_write_function(state, mp3splt_writer, (void *)f);
  //log_debug("pretend split and write function set");
#endif

  // Create splitpoints
  splt_point *point = mp3splt_point_new(begin_offset_in_hs, NULL);
  mp3splt_point_set_type(point, SPLT_SPLITPOINT);
#ifdef SEGMENT_USING_FILE
  char buf[20];
  sprintf(buf, "mp3cue%09d", ++splitnr);
  mp3splt_point_set_name(point, buf);
#endif
  mp3splt_append_splitpoint(state, point);

  splt_point *skip = mp3splt_point_new(end_offset_in_hs, NULL);
  mp3splt_point_set_type(skip, SPLT_SKIPPOINT);
  mp3splt_append_splitpoint(state, skip);
  //log_debug("split points set");

  // Append cuesheet tags and merge with existing
  {
    splt_tags *tags = mp3splt_tags_new(NULL);

    char *title = S->segment.title;
    char *artist = S->segment.artist;
    char *album = S->segment.album;
    char *performer = S->segment.album_artist;
    char year[20];
    sprintf(year, "%d", S->segment.year);
    char *comment = S->segment.comment;
    char *genre = S->segment.genre;
    char track[20];
    sprintf(track, "%d", S->segment.track);

    mp3splt_read_original_tags(state);
    //log_debug("original tags read");

    mp3splt_tags_set(tags, SPLT_TAGS_ORIGINAL, "true", NULL);
    //log_debug("SPLT_TAGS_ORIGINAL set");
    mp3splt_tags_set(tags,
         SPLT_TAGS_TITLE, title,
         SPLT_TAGS_ARTIST, artist,
         SPLT_TAGS_ALBUM, album,
         SPLT_TAGS_PERFORMER, performer,
         SPLT_TAGS_YEAR, year,
         SPLT_TAGS_COMMENT, comment, SPLT_TAGS_GENRE, genre, SPLT_TAGS_TRACK, track, NULL);
    //log_debug("tags set");
    mp3splt_append_tags(state, tags);
    //log_debug("tag appended");
  }

  // split the stuff
  int error = SPLT_OK;
  error = mp3splt_split(state);
  //log_debug("split done");
  mp3splt_free_state(state);
  //log_debug("state freeed");
  log_debug2("mp3splt_split: result=%d", error);

#ifndef SEGMENT_USING_FILE
  fclose(f);
  mc_take_control(S->memory_block, S->size);
  //log_debug("memory file closed");
#endif

  if (error == SPLT_OK_SPLIT || error == SPLT_OK_SPLIT_EOF) {
#ifdef SEGMENT_USING_FILE
    char fn[250];
    sprintf(fn, "/tmp/%s.%s", buf, ext);
    FILE *f = fopen(fn, "rb");
    FILE *g = open_memstream((char **)&S->memory_block, &S->size);
    int size;
    char fbuf[10240];
    while ((size = fread(fbuf, 1, 10240, f)) > 0) {
      fwrite(fbuf, size, 1, g);
    }
    fclose(f);
    fclose(g);
    unlink(fn);
#endif
    mc_free(ext);
    return SEGMENTER_OK;
  } else {
    mc_free(ext);
    return SEGMENTER_ERR_CREATE;
  }
}