Esempio n. 1
0
Value x264Encode_AST(argList *a) {
	struct x264EncodeParams *params = malloc(sizeof(struct x264EncodeParams));

	checkArgs(a, 2, typeClip, typeStr);
	MkvsynthOutput *output = MANDCLIP(0);
	params->filename = strdup(MANDSTR(1));
	params->x264params = strdup(OPTSTR("params", ""));
	params->input = createInputBuffer(output);

	if(isMetaDataValid(params->input->metaData) != 1)
		MkvsynthError("invalid colorspace!");

	mkvsynthQueue((void *)params, x264Encode);
    RETURNNULL();
}
Esempio n. 2
0
Value writeRawFile_AST(argList *a) {
	struct writeRawFileParams *params = malloc(sizeof(struct writeRawFileParams));

	checkArgs(a, 2, typeClip, typeStr);
	MkvsynthOutput *output = MANDCLIP(0);
	char *filename = MANDSTR(1);

	////////////////////
	// Error Checking //
	////////////////////
	params->file = fopen(filename, "w");
	if(params->file == NULL)
		MkvsynthError("Could not open the output file!");

	params->input = createInputBuffer(output);

	mkvsynthQueue((void *)params, writeRawFile);
    RETURNNULL();
}
Esempio n. 3
0
void writeRawFile_AST(ASTnode *p, ASTnode *args) {
	struct writeRawFileParams *params = malloc(sizeof(struct writeRawFileParams));

	checkArgs("writeRawFile", args, 2, typeClip, typeStr);
	MkvsynthOutput *output = MANDCLIP();
	char *filename = MANDSTR();

	////////////////////
	// Error Checking //
	////////////////////
	params->file = fopen(filename, "w");
	if(params->file == NULL) {
		printf("Could not open the output file!\n");	
		exit(0);
	}

	params->input = createInputBuffer(output);

	mkvsynthQueue((void *)params, writeRawFile);
}
Esempio n. 4
0
Value ffmpegDecode_AST(argList *a) {

	///////////////////////////
	// Parse Input Arguments //
	///////////////////////////
	struct ffmpegDecode *params = malloc(sizeof(struct ffmpegDecode));
	checkArgs(a, 1, typeStr);
	char *filename = MANDSTR(0);
	params->output = createOutputBuffer();

	//////////////////////////////
	// Initialize Stuff To NULL //
	//////////////////////////////
	params->formatContext = NULL;
	params->codecContext = NULL;
	params->codec = NULL;
	params->frame = NULL;
	params->rgbFrame = NULL;
	params->rgbFramePayload = NULL;
	
	//////////////////////////////////////
	// Error Checking And Initializtion //
	//////////////////////////////////////
	av_register_all();
	
	int avOpen = avformat_open_input(&params->formatContext, filename, NULL, NULL);

	if(avOpen != 0)
		MkvsynthError("Input file could not be opened.");
	
	if(avformat_find_stream_info(params->formatContext, NULL) < 0)
		MkvsynthError("Input file does not seem to be a video.");

	av_dump_format(params->formatContext, 0, filename, 0);
	
	int i;
	for(i = 0; i < params->formatContext->nb_streams; i++) {
		if(params->formatContext->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
			params->videoStream = i;
			break;
		}
	}
	
	if(params->videoStream == -1)
		MkvsynthError("Input file does not seem to have a video stream.");

	params->codecContext = params->formatContext->streams[params->videoStream]->codec;

	params->codec = avcodec_find_decoder(params->codecContext->codec_id);
	if(params->codec == NULL)
		MkvsynthError("Unrecognized video codec.");

	int openCodec = avcodec_open2(params->codecContext, params->codec, &params->dictionary);

	if(openCodec < 0)
		MkvsynthError("Failed to open codec.");

	params->frame = avcodec_alloc_frame();
	params->rgbFrame = avcodec_alloc_frame();

	int bytes = avpicture_get_size(PIX_FMT_RGB48, params->codecContext->width, params->codecContext->height);
	params->rgbFramePayload = (uint8_t *)av_malloc(bytes);
	
	params->resizeContext = sws_getContext (
		params->codecContext->width,
		params->codecContext->height,
		params->codecContext->pix_fmt,
		params->codecContext->width,
		params->codecContext->height,
		PIX_FMT_RGB48,
		SWS_SPLINE,
		NULL,
		NULL,
		NULL);

	avpicture_fill((AVPicture *)params->rgbFrame, params->rgbFramePayload, PIX_FMT_RGB48, params->codecContext->width, params->codecContext->height);

	///////////////
	// Meta Data //
	///////////////
	params->output->metaData->width = params->codecContext->width;
	params->output->metaData->height = params->codecContext->height;
	params->output->metaData->colorspace = MKVS_RGB48;
	params->output->metaData->fpsNumerator = params->formatContext->streams[params->videoStream]->avg_frame_rate.num;
	params->output->metaData->fpsDenominator = params->formatContext->streams[params->videoStream]->avg_frame_rate.den;

	//////////////////////
	// Queue and Return //
	//////////////////////
	mkvsynthQueue((void *)params, ffmpegDecode);
	RETURNCLIP(params->output);
}