Ejemplo n.º 1
0
static gboolean
parse_options (int *argc, char *argv[])
{
  GOptionContext *ctx;
  gboolean success;
  GError *error = NULL;

  ctx = g_option_context_new (" - encoder test options");
  if (!ctx)
    return FALSE;

  g_option_context_add_group (ctx, gst_init_get_option_group ());
  g_option_context_add_main_entries (ctx, g_options, NULL);
  g_option_context_set_help_enabled (ctx, TRUE);
  success = g_option_context_parse (ctx, argc, &argv, &error);
  if (!success) {
    g_printerr ("Option parsing failed: %s\n", error->message);
    g_error_free (error);
    goto bail;
  }

  if (!g_codec_str)
    g_codec_str = g_strdup ("h264");
  if (!g_output_file_name)
    g_output_file_name = generate_output_filename (g_codec_str);

bail:
  g_option_context_free (ctx);
  return success;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
    int rv = 0;
    GError* err = NULL;
    GOptionContext* octx = g_option_context_new("- MIME message generator");

    g_option_context_add_main_entries(octx, opts, NULL);
    if ( g_option_context_parse(octx, &argc, &argv, &err) ) {
        gboolean go = FALSE;

        if ( !src_fn ) {
            g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "A source filename is required");
        } else if ( !dst_fn && !display && !tmp ) {
            g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "An output method must be selected");
        } else {
            go = TRUE;
        }

        if ( go ) {
            gchar* ofn = generate_output_filename(dst_fn, display, tmp);

            if ( verbose ) {
                g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "sfn=%s", src_fn);
                g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "ofn=%s", ofn ? ofn : "DISPLAY");
            }

            if ( !run(src_fn, ofn) ) {
                g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Failed to interpret the message spec");
                rv = 1;
            }

            if ( ofn ) {
                fprintf(stdout, "%s\n", ofn);
                g_free(ofn);
            }
        } else {
            rv = 1;
        }
    }

    return rv;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    static m4af_io_callbacks_t m4af_io = {
        read_callback, write_callback, seek_callback, tell_callback
    };
    aacenc_param_ex_t params = { 0 };

    int result = 2;
    char *output_filename = 0;
    pcm_reader_t *reader = 0;
    HANDLE_AACENCODER encoder = 0;
    AACENC_InfoStruct aacinfo = { 0 };
    m4af_ctx_t *m4af = 0;
    const pcm_sample_description_t *sample_format;
    int frame_count = 0;
    int sbr_mode = 0;
    unsigned scale_shift = 0;

    setlocale(LC_CTYPE, "");
    setbuf(stderr, 0);

    if (parse_options(argc, argv, &params) < 0)
        return 1;

    if ((reader = open_input(&params)) == 0)
        goto END;

    sample_format = pcm_get_format(reader);

    sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)&params);
    if (sbr_mode && !aacenc_is_sbr_ratio_available()) {
        fprintf(stderr, "WARNING: Only dual-rate SBR is available "
                        "for this version\n");
        params.sbr_ratio = 2;
    }
    scale_shift = aacenc_is_dual_rate_sbr((aacenc_param_t*)&params);
    params.sbr_signaling =
        (params.transport_format == TT_MP4_LOAS) ? 2 :
        (params.transport_format == TT_MP4_RAW)  ? 1 : 0;
    if (sbr_mode && !scale_shift)
        params.sbr_signaling = 2;

    if (aacenc_init(&encoder, (aacenc_param_t*)&params, sample_format,
                    &aacinfo) < 0)
        goto END;

    if (!params.output_filename) {
        const char *ext = params.transport_format ? ".aac" : ".m4a";
        output_filename = generate_output_filename(params.input_filename, ext);
        params.output_filename = output_filename;
    }

    if ((params.output_fp = aacenc_fopen(params.output_filename, "wb+")) == 0) {
        aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.output_filename,
                       strerror(errno));
        goto END;
    }
    handle_signals();

    if (!params.transport_format) {
        uint32_t scale;
        unsigned framelen = aacinfo.frameLength;
        scale = sample_format->sample_rate >> scale_shift;
        if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
                                params.output_fp)) < 0)
            goto END;
        m4af_set_decoder_specific_info(m4af, 0,
                                       aacinfo.confBuf, aacinfo.confSize);
        m4af_set_fixed_frame_duration(m4af, 0,
                                      framelen >> scale_shift);
        m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
        m4af_set_priming_mode(m4af, params.gapless_mode + 1);
        m4af_begin_write(m4af);
    }
Ejemplo n.º 4
0
int process_input_files(settings_t *settings)
{
    int i = 0;
    int ret = 1;
    int file_type = 0;
    char *current_file = (char *)0;
    char tmpbuf[MAX_BUF_LEN] = {0};
    char output_file[MAX_BUF_LEN] = {0};
    char resampled_wav_file[MAX_BUF_LEN] = {0};
    char input_file_full_path_name[MAX_BUF_LEN] = {0};

    if (settings)
    {
        for(i = 0; i < settings->num_input_files; i++)
        {
            get_full_path_name(settings->input_files[i],
                               input_file_full_path_name,MAX_BUF_LEN);
            current_file = input_file_full_path_name;

            if (settings->verbose)
            {
                printf("Processing file: %s\n",current_file);
            }

            strncpy(tmpbuf,current_file,MAX_BUF_LEN);
            strip_filename_extension(tmpbuf);
            generate_output_filename(settings,tmpbuf,
                                     output_file,MAX_BUF_LEN);

            file_type = get_file_type(current_file);
            switch(file_type)
            {
                case FILE_TYPE_OGG:
                    if (settings->oggdec_enabled &&
                        ogg_decode(settings,current_file,output_file,
                                   oggdec_callback))
                    {
                        fprintf(stderr,"Failed to decode ogg file.\n");
                        return ret;
                    }
                    break;
                case FILE_TYPE_MP3:
                    if (settings->mpgdec_enabled &&
                        mpg_decode(settings,current_file,output_file,
                                   mpgdec_callback))
                    {
                        fprintf(stderr,"Failed to decode mp3 file.\n");
                        return ret;
                    }
                    break;
                case FILE_TYPE_WAV:
                    if (resample_wav_file(settings,current_file,
                                          output_file))
                    {
                        fprintf(stderr,"Failed to resample wav file.\n");
                        return ret;
                    }
                    break;
            }

            /* finally, verify the generated output file */
            if (wav_verify_format(output_file))
            {
                /*
                  if we have sox enabled and we've just generated
                  this wav file, we should try to resample it here
                  to make it a valid format
                */
                if ((file_type != FILE_TYPE_WAV) &&
                    (settings->sox_enabled))
                {
                    strncpy(tmpbuf,current_file,MAX_BUF_LEN);
                    strip_filename_extension(tmpbuf);
                    strncat(tmpbuf,"-resampled",MAX_BUF_LEN-strlen(tmpbuf));
                    generate_output_filename(settings,tmpbuf,
                                             resampled_wav_file,
                                             MAX_BUF_LEN);

                    if (resample_wav_file(settings,output_file,
                                          resampled_wav_file))
                    {
                        fprintf(stderr,"Failed to resample wav file.\n");
                    }
                    else
                    {
                        /* delete the original generated wav file */
                        delete_file(output_file);
                        strncpy(output_file,resampled_wav_file,MAX_BUF_LEN);
                        goto valid_input_wav;
                    }
                }
                fprintf(stderr,"Processed output file %s is "
                        "invalid!  Skipping.\n",output_file);
                continue;
            }
            else
            {
              valid_input_wav:
                /*
                  if all went well up to this point, store the
                  output filename in the settings object
                */
                if (settings_add_output_file(settings,output_file))
                {
                    fprintf(stderr,"Failed to add valid output file "
                            "%s.  Skipping.\n",output_file);
                    continue;
                }
            }
        }
        ret = (settings->num_output_files ? 0 : 1);
    }
    return ret;
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
    wav_io_context_t wav_io = { read_callback, seek_callback, tell_callback };
    m4af_io_callbacks_t
        m4af_io = { read_callback, write_callback, seek_callback, tell_callback };
    aacenc_param_ex_t params = { 0 };

    int result = 2;
    FILE *ifp = 0;
    FILE *ofp = 0;
    char *output_filename = 0;
#ifdef USE_LIBSNDFILE
    SNDFILE* snd = NULL;
    SF_INFO snd_info;
    pcm_sample_description_t snd_desc = { 0 };
#else
    wav_reader_t *wavf = 0;
#endif
    HANDLE_AACENCODER encoder = 0;
    AACENC_InfoStruct aacinfo = { 0 };
    m4af_ctx_t *m4af = 0;
    const pcm_sample_description_t *sample_format;
    int downsampled_timescale = 0;
    int frame_count = 0;
    struct stat stb = { 0 };

    setlocale(LC_CTYPE, "");
    setbuf(stderr, 0);

    if (parse_options(argc, argv, &params) < 0)
        return 1;

#ifdef USE_LIBSNDFILE
    if ((snd = sf_open (params.input_filename, SFM_READ, &snd_info)) == NULL) {
        fprintf(stderr, "ERROR: broken / unsupported input file\n");
        goto END;
    }
#ifdef USE_LIBSAMPLERATE
    if(params.resample) {
        snd_desc.sample_rate = params.resample;
        printf("resampling to %dhz\n", snd_desc.sample_rate);
    } else {
        snd_desc.sample_rate = snd_info.samplerate;
    }
    snd_desc.sample_type = PCM_TYPE_FLOAT; // always -- libsndfile does the conversion for us
    snd_desc.bits_per_channel = sizeof(float)*8;
#else
    snd_desc.sample_rate = snd_info.samplerate;
    snd_desc.sample_type = PCM_TYPE_SINT; // always -- libsndfile does the conversion for us
    snd_desc.bits_per_channel = sizeof(short)*8;
#endif
    snd_desc.channels_per_frame = snd_info.channels;
    snd_desc.bytes_per_frame = snd_info.channels * (snd_desc.bits_per_channel / 8);
    snd_desc.channel_mask = 0;

    sample_format = &snd_desc;
#else
    if ((ifp = aacenc_fopen(params.input_filename, "rb")) == 0) {
        aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.input_filename,
                       strerror(errno));
        goto END;
    }
    
    if (fstat(fileno(ifp), &stb) == 0 && (stb.st_mode & S_IFMT) != S_IFREG) {
        wav_io.seek = 0;
        wav_io.tell = 0;
    }
    
    if (!params.is_raw) {
        if ((wavf = wav_open(&wav_io, ifp, params.ignore_length)) == 0) {
            fprintf(stderr, "ERROR: broken / unsupported input file\n");
            goto END;
        }
    } else {
        int bytes_per_channel;
        pcm_sample_description_t desc = { 0 };
        if (parse_raw_spec(params.raw_format, &desc) < 0) {
            fprintf(stderr, "ERROR: invalid raw-format spec\n");
            goto END;
        }
        desc.sample_rate = params.raw_rate;
        desc.channels_per_frame = params.raw_channels;
        bytes_per_channel = (desc.bits_per_channel + 7) / 8;
        desc.bytes_per_frame = params.raw_channels * bytes_per_channel;
        if ((wavf = raw_open(&wav_io, ifp, &desc)) == 0) {
            fprintf(stderr, "ERROR: failed to open raw input\n");
            goto END;
        }
    }

    sample_format = wav_get_format(wavf);
#endif

    if (aacenc_init(&encoder, (aacenc_param_t*)&params, sample_format,
                    &aacinfo) < 0)
        goto END;

    if (!params.output_filename) {
        const char *ext = params.transport_format ? ".aac" : ".m4a";
        output_filename = generate_output_filename(params.input_filename, ext);
        params.output_filename = output_filename;
    }

    if ((ofp = aacenc_fopen(params.output_filename, "wb+")) == 0) {
        aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.output_filename,
                       strerror(errno));
        goto END;
    }
    handle_signals();
    if (!params.transport_format) {
        uint32_t scale;
        unsigned framelen = aacinfo.frameLength;
        int sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)&params);
        int sig_mode = aacEncoder_GetParam(encoder, AACENC_SIGNALING_MODE);
        if (sbr_mode && !sig_mode)
            downsampled_timescale = 1;
        scale = sample_format->sample_rate >> downsampled_timescale;
        if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io, ofp)) < 0)
            goto END;
        m4af_set_decoder_specific_info(m4af, 0, aacinfo.confBuf,
                                       aacinfo.confSize);
        m4af_set_fixed_frame_duration(m4af, 0,
                                      framelen >> downsampled_timescale);
        m4af_set_priming_mode(m4af, params.gapless_mode + 1);
        m4af_begin_write(m4af);
    }