Exemplo n.º 1
0
void CQTAudioByteStream::read_frame (uint32_t frame_to_read)
{
#ifdef DEBUG_QTIME_AUDIO_FRAME
  player_debug_message("audio read_frame %d", frame_to_read);
#endif

  if (m_frame_in_buffer == frame_to_read) {
    m_byte_on = 0;
    return;
  }
  m_parent->lock_file_mutex();

  m_frame_in_buffer = frame_to_read;

  unsigned char *buff = (unsigned char *)m_buffer;
  quicktime_set_audio_position(m_parent->get_file(), 
			       frame_to_read, 
			       m_track);
  m_this_frame_size = quicktime_read_audio_frame(m_parent->get_file(),
						 buff,
						 m_max_frame_size,
						 m_track);
  if (m_this_frame_size < 0) {
    m_max_frame_size = -m_this_frame_size;
    m_buffer = (uint8_t *)realloc(m_buffer, m_max_frame_size * sizeof(char));
    // Okay - I could have used a goto, but it really grates...
    m_frame_in_buffer = frame_to_read;
    buff = (unsigned char *)m_buffer;
    quicktime_set_audio_position(m_parent->get_file(), 
				 frame_to_read, 
				 m_track);
    m_this_frame_size = quicktime_read_audio_frame(m_parent->get_file(),
						   buff,
						   m_max_frame_size,
						 m_track);
  }
#if 0
  player_debug_message("qta frame size %u", m_this_frame_size);
#endif
  m_parent->unlock_file_mutex();
  m_byte_on = 0;
}
Exemplo n.º 2
0
/*
 * mp4extract
 * required arg1 should be the MP4 input file
 * required arg2 should be the output file for the extracted track
 */
int main(int argc, char** argv)
{
    /* variables controlable from command line */
    bool extractVideo = TRUE;

    /* internal variables */
    char* mp4FileName = NULL;
    char* outFileName = NULL;
    quicktime_t* mp4File = NULL;
    FILE* outFile = NULL;
    int track = 0;
    int frame, numFrames;
    u_int8_t buf[64*1024];  /* big enough? */
    int bufSize;

    /* begin process command line */
    progName = argv[0];
    while (1) {
        int c = -1;
        int option_index = 0;
        static struct option long_options[] = {
            { "audio", 0, 0, 'a' },
            { "video", 0, 0, 'v' },
            { NULL, 0, 0, 0 }
        };

        c = getopt_long(argc, argv, "av",
            long_options, &option_index);

        if (c == -1)
            break;

        switch (c) {
        case 'a': {
            extractVideo = FALSE;
            break;
        }
        case 'v': {
            extractVideo = TRUE;
            break;
        }
        case '?':
            break;
        default:
            fprintf(stderr, "%s: unknown option specified, ignoring: %c\n",
                progName, c);
        }
    }

    /* check that we have at least two non-option arguments */
    if ((argc - optind) < 2) {
        fprintf(stderr,
            "usage: %s <mpeg-file> <mov-file>\n",
            progName);
        exit(1);
    }

    /* point to the specified file names */
    mp4FileName = argv[optind++];
    outFileName = argv[optind++];

    /* warn about extraneous non-option arguments */
    if (optind < argc) {
        fprintf(stderr, "%s: unknown options specified, ignoring: ", progName);
        while (optind < argc) {
            fprintf(stderr, "%s ", argv[optind++]);
        }
        fprintf(stderr, "\n");
    }

    /* end processing of command line */

    /* open the MP4 file */
    mp4File = quicktime_open(mp4FileName, 1, 0, 0);
    if (mp4File == NULL) {
        fprintf(stderr,
            "%s: error %s: %s\n",
            progName, mp4FileName, strerror(errno));
        exit(2);
    }

    /* open output file for writing */
    outFile = fopen(outFileName, "wb");
    if (outFile == NULL) {
        fprintf(stderr,
            "%s: error opening %s: %s\n",
            progName, outFileName, strerror(errno));
        exit(3);
    }

    /* add MPEG-4 video config info at beginning of output file */
    if (extractVideo) {
        if (!strcasecmp(quicktime_video_compressor(mp4File, track), "mp4v")) {
            u_char* pConfig;
            int configSize;

            quicktime_get_mp4_video_decoder_config(mp4File, track,
                &pConfig, &configSize);

            if (fwrite(pConfig, 1, configSize, outFile) != configSize) {
                fprintf(stderr,
                    "%s: write error: %s\n",
                    progName, strerror(errno));
                exit(4);
            }
            free(pConfig);
        }
    }

    if (extractVideo) {
        numFrames = quicktime_video_length(mp4File, track);
    } else {
        numFrames = quicktime_audio_length(mp4File, track);
    }

    for (frame = 0; frame < numFrames; frame++) {
        if (extractVideo) {
            bufSize = quicktime_read_frame(mp4File,
                &buf[0], track);
        } else { // extract audio
            bufSize = quicktime_read_audio_frame(mp4File,
                &buf[0], sizeof(buf), track);
        }
        if (bufSize <= 0) {
            fprintf(stderr,
                "%s: read error: %s\n",
                progName, strerror(errno));
            exit(5);
        }

        if (fwrite(buf, 1, bufSize, outFile) != bufSize) {
            fprintf(stderr,
                "%s: write error: %s\n",
                progName, strerror(errno));
            exit(4);
        }
    }

    /* cleanup */
    quicktime_close(mp4File);
    fclose(outFile);
    exit(0);
}