Ejemplo n.º 1
0
void quicktime_set_jpeg(quicktime_t *file, int quality, int use_float)
{
    int i;

    printf("1\n");
    for(i = 0; i < file->total_vtracks; i++)
    {
        if(quicktime_match_32(quicktime_video_compressor(file, i), QUICKTIME_JPEG) ||
                quicktime_match_32(quicktime_video_compressor(file, i), QUICKTIME_MJPA) ||
                quicktime_match_32(quicktime_video_compressor(file, i), QUICKTIME_RTJ0))
        {
            quicktime_jpeg_codec_t *codec = ((quicktime_codec_t*)file->vtracks[i].codec)->priv;
            codec->quality = quality;
            codec->use_float = use_float;
        }
    }
    printf("10\n");
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	quicktime_t *file;
	FILE *output;
	int result = 0;
	int i, j;
	int64_t length;
	char string[1024], *prefix = 0, *input = 0;
	char *data = 0;
	int bytes = 0, old_bytes = 0;
	float output_rate = 0;
	float input_rate;
	int64_t input_frame;
	int64_t new_length;
	int width, height;
	int rgb_to_ppm = 0;

	if(argc < 3)
	{
		usage();
	}

	for(i = 1, j = 0; i < argc; i++)
	{
		if(!strcmp(argv[i], "-f"))
		{
			if(i + 1 < argc)
			{
				output_rate = atof(argv[++i]);
			}
			else
				usage();
		}
		else
		if(j == 0)
		{
			input = argv[i];
			j++;
		}
		else
		if(j == 1)
		{
			prefix = argv[i];
			j++;
		}
	}

	if(!prefix || !input) usage();

	if(!(file = quicktime_open(input, 1, 0)))
	{
		printf("Open failed\n");
		exit(1);
	}
	
	if(!quicktime_video_tracks(file))
	{
		printf("No video tracks.\n");
		exit(1);
	}
	
	if(quicktime_match_32(quicktime_video_compressor(file, 0), QUICKTIME_RAW))
	{
		printf("Converting to ppm.\n");
		rgb_to_ppm = 1;
	}

	length = quicktime_video_length(file, 0);
	input_rate = quicktime_frame_rate(file, 0);
	if(!output_rate) output_rate = input_rate;
	new_length = output_rate / input_rate * length;
	width = quicktime_video_width(file, 0);
	height = quicktime_video_height(file, 0);

	for(i = 0; i < new_length; i++)
	{
/* Get output file */
		sprintf(string, "%s%06d", prefix, i);
		if(!(output = fopen(string, "wb")))
		{
			perror("Open failed");
			exit(1);
		}

/* Get input frame */
		input_frame = (int64_t)(input_rate / output_rate * i);
		bytes = quicktime_frame_size(file, input_frame, 0);

		if(data)
		{
			if(bytes > old_bytes) { free(data); data = 0; }
		}

		if(!data)
		{
			old_bytes = bytes;
			data = malloc(bytes);
		}

		quicktime_set_video_position(file, input_frame, 0);
		quicktime_read_data(file, data, bytes);
		if(rgb_to_ppm)
		{
			fprintf(output, "P6\n%d %d\n%d\n", width, height, 0xff);
		}

		if(!fwrite(data, bytes, 1, output))
		{
			perror("write failed");
		}
		fclose(output);
	}

	quicktime_close(file);
}
Ejemplo n.º 3
0
void probe_mov(info_t *ipipe)
{

  quicktime_t *qt_file=NULL;
  char *codec=NULL;

  int j, tracks;

  /* open movie for video probe */
  if(qt_file==NULL)
    if(NULL == (qt_file = quicktime_open((char *)ipipe->name,1,0))){
      tc_log_error(__FILE__,"can't open quicktime!");
      ipipe->error=1;
      return;
    }

  // extract audio parameters
  tracks=quicktime_audio_tracks(qt_file);

  if(tracks>TC_MAX_AUD_TRACKS) {
    tc_log_warn(__FILE__, "only %d of %d audio tracks scanned",
                TC_MAX_AUD_TRACKS, tracks);
    tracks=TC_MAX_AUD_TRACKS;
  }

  for(j=0; j<tracks; ++j) {

    ipipe->probe_info->track[j].samplerate = quicktime_sample_rate(qt_file, j);
    ipipe->probe_info->track[j].chan = quicktime_track_channels(qt_file, j);
    ipipe->probe_info->track[j].bits = quicktime_audio_bits(qt_file, j);

    codec  = quicktime_audio_compressor(qt_file, j);

    if(strcasecmp(codec,QUICKTIME_RAW)==0 || strcasecmp(codec,QUICKTIME_TWOS)==0)
      ipipe->probe_info->track[j].format = CODEC_PCM;
    else if(strcasecmp(codec,QUICKTIME_IMA4)==0)
      ipipe->probe_info->track[j].format = CODEC_IMA4;
    else
      /* XXX not right but works */
      ipipe->probe_info->track[j].format = CODEC_PCM;

    if (! binary_dump)
    	tc_log_info(__FILE__, "audio codec=%s", codec);

    if(ipipe->probe_info->track[j].chan>0) ++ipipe->probe_info->num_tracks;
  }


  // read all video parameter from input file
  ipipe->probe_info->width  =  quicktime_video_width(qt_file, 0);
  ipipe->probe_info->height =  quicktime_video_height(qt_file, 0);
  ipipe->probe_info->fps = quicktime_frame_rate(qt_file, 0);

  ipipe->probe_info->frames = quicktime_video_length(qt_file, 0);

  codec  =  quicktime_video_compressor(qt_file, 0);

  //check for supported codecs

  if(codec!=NULL) {

    if(strlen(codec)==0) {
      ipipe->probe_info->codec=TC_CODEC_RGB;
    } else {

      if(strcasecmp(codec,QUICKTIME_DV)==0)
	ipipe->probe_info->codec=TC_CODEC_DV;

      if(strcasecmp(codec,"dvsd")==0)
	ipipe->probe_info->codec=TC_CODEC_DV;

      if(strcasecmp(codec,"DIV3")==0)
	ipipe->probe_info->codec=TC_CODEC_DIVX3;

      if(strcasecmp(codec,"DIVX")==0)
	ipipe->probe_info->codec=TC_CODEC_DIVX4;

      if(strcasecmp(codec,"DX50")==0)
	ipipe->probe_info->codec=TC_CODEC_DIVX5;

      if(strcasecmp(codec,"MJPG")==0 || strcasecmp(codec,"JPEG")==0)
	ipipe->probe_info->codec=TC_CODEC_MJPEG;

      if(strcasecmp(codec,"YUV2")==0)
	ipipe->probe_info->codec=TC_CODEC_YUV2;

      if(strcasecmp(codec,"SVQ1")==0)
	ipipe->probe_info->codec=TC_CODEC_SVQ1;

      if(strcasecmp(codec,"SVQ3")==0)
	ipipe->probe_info->codec=TC_CODEC_SVQ3;
    }
  } else
    ipipe->probe_info->codec=TC_CODEC_UNKNOWN;

  if (! binary_dump)
  	tc_log_info(__FILE__, "video codec=%s", codec);
  ipipe->probe_info->magic=TC_MAGIC_MOV;
  tc_frc_code_from_value(&(ipipe->probe_info->frc),
                         ipipe->probe_info->fps);

  return;
}
Ejemplo n.º 4
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);
}