Ejemplo n.º 1
0
static int video_gc(lua_State *L) {
    video_t *video = to_video(L, 1);
    fprintf(stderr, INFO("gc'ing video: tex id: %d\n"), video->tex);
    glDeleteTextures(1, &video->tex);
    video_free(video);
    return 0;
}
Ejemplo n.º 2
0
void clean_up( void ) {
	sound_free();
	game_list_free();
	submenu_free();
	platform_free();
	menu_free();
	hint_free();
	font_free();
	bg_free();
	location_free();
	event_free();
	snap_free();
	video_free();
	sdl_free();
}
Ejemplo n.º 3
0
static int
cmd_decode(int argc, char *argv[])
{
	video_t *vp;
	int rv;

	if (argc < 2) {
		warnx("missing input file or output directory");
		return (EXIT_USAGE);
	}

	if ((vp = video_open(argv[0])) == NULL)
		return (EXIT_FAILURE);

	rv = video_iter_frames(vp, write_frame, argv[1]);
	video_free(vp);
	return (rv);
}
Ejemplo n.º 4
0
static int
cmd_starts(int argc, char *argv[])
{
	video_t *vp;
	int rv, last;

	if (kv_init(dirname((char *)kv_arg0)) != 0) {
		warnx("failed to initialize masks");
		return (EXIT_FAILURE);
	}

	if (argc < 1) {
		warnx("missing input file");
		return (EXIT_USAGE);
	}

	if ((vp = video_open(argv[0])) == NULL)
		return (EXIT_FAILURE);

	last = 0;
	rv = video_iter_frames(vp, check_start_frame, &last);
	video_free(vp);
	return (rv);
}
Ejemplo n.º 5
0
static int
cmd_video(int argc, char *argv[])
{
	kv_vidctx_t *kvp;
	video_t *vp;
	int rv;
	char c;
	const char *dbgdir = NULL;
	kv_emit_f emit;

	emit = kv_screen_print;

	while ((c = getopt(argc, argv, "jd:")) != -1) {
		switch (c) {
		case 'j':
			emit = kv_screen_json;
			break;

		case 'd':
			dbgdir = optarg;
			break;

		case '?':
		default:
			return (EXIT_USAGE);
		}
	}

	argc -= optind;
	argv += optind;

	if (argc < 1) {
		warnx("missing input file");
		return (EXIT_USAGE);
	}

	/*
	 * This isn't strictly necessary, but is a useful prereq so that we
	 * don't get partway through the conversion and fail because the user
	 * forgot to create the directory.
	 */
	if (dbgdir != NULL) {
		struct stat st;
		if (stat(dbgdir, &st) != 0) {
			warn("stat %s", dbgdir);
			return (EXIT_USAGE);
		}

		if ((st.st_mode & S_IFDIR) == 0) {
			warnx("not a directory: %s", dbgdir);
			return (EXIT_USAGE);
		}
	}

	if ((vp = video_open(argv[0])) == NULL)
		return (EXIT_FAILURE);

	if (kv_debug > 0)
		(void) fprintf(stderr, "framerate: %lf\n",
		    video_framerate(vp));

	if ((kvp = kv_vidctx_init(dirname((char *)kv_arg0), emit,
	    dbgdir)) == NULL) {
		video_free(vp);
		return (EXIT_FAILURE);
	}

	if (emit == kv_screen_json)
		(void) printf("{ \"nframes\": %d, \"crtime\": \"%s\" }\n",
		    video_nframes(vp), video_crtime(vp));

	rv = video_iter_frames(vp, ident_frame, kvp);
	kv_vidctx_free(kvp);
	video_free(vp);
	return (rv);
}
Ejemplo n.º 6
0
static int video_open(video_t *video, const char *filename) {
    video->format = PIX_FMT_RGB24;
    if (avformat_open_input(&video->format_context, filename, NULL, NULL) ||
            avformat_find_stream_info(video->format_context, NULL) < 0) {
        fprintf(stderr, ERROR("cannot open video stream %s\n"), filename);
        goto failed;
    }

    video->stream_idx = -1;
    for (int i = 0; i < video->format_context->nb_streams; i++) {
        if (video->format_context->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
            video->stream_idx = i;
            break;
        }
    }

    if (video->stream_idx == -1) {
        fprintf(stderr, ERROR("cannot find video stream\n"));
        goto failed;
    }

    AVStream *stream = video->format_context->streams[video->stream_idx];
    video->codec_context = stream->codec;
    video->codec = avcodec_find_decoder(video->codec_context->codec_id);

    /* Save Width/Height */
    video->width = video->codec_context->width;
    video->height = video->codec_context->height;

	
    if (!video->codec || avcodec_open2(video->codec_context, video->codec, NULL) < 0) {
        fprintf(stderr, ERROR("cannot open codec\n"));
        goto failed;
    }

    video->buffer_width = video->codec_context->width;
    video->buffer_height = video->codec_context->height;

    fprintf(stderr, INFO("pixel aspect ratio: %d/%d, size: %dx%d buffer size: %dx%d\n"), 
        video->codec_context->sample_aspect_ratio.num,
        video->codec_context->sample_aspect_ratio.den,
        video->width,
        video->height,
        video->buffer_width,
        video->buffer_height
    );

    video->par = (float)video->codec_context->sample_aspect_ratio.num / video->codec_context->sample_aspect_ratio.den;
    if (video->par == 0)
        video->par = 1;

    /* Frame rate fix for some codecs */
    if (video->codec_context->time_base.num > 1000 && video->codec_context->time_base.den == 1)
        video->codec_context->time_base.den = 1000;

    /* Get FPS */
    // http://libav-users.943685.n4.nabble.com/Retrieving-Frames-Per-Second-FPS-td946533.html
    if ((stream->time_base.den != stream->r_frame_rate.num) ||
            (stream->time_base.num != stream->r_frame_rate.den)) {
        video->fps = 1.0 / stream->r_frame_rate.den * stream->r_frame_rate.num;
    } else {
        video->fps = 1.0 / stream->time_base.num * stream->time_base.den;
    }
    fprintf(stderr, INFO("fps: %lf\n"), video->fps);

    /* Get framebuffers */
    video->raw_frame = avcodec_alloc_frame();
    video->scaled_frame = avcodec_alloc_frame();

    if (!video->raw_frame || !video->scaled_frame) {
        fprintf(stderr, ERROR("cannot preallocate frames\n"));
        goto failed;
    }

    /* Create data buffer */
    video->buffer = av_malloc(avpicture_get_size(
        video->format, 
        video->buffer_width, 
        video->buffer_height
    ));

    /* Init buffers */
    avpicture_fill(
        (AVPicture *) video->scaled_frame, 
        video->buffer, 
        video->format, 
        video->buffer_width, 
        video->buffer_height
    );

    /* Init scale & convert */
    video->scaler = sws_getContext(
        video->buffer_width,
        video->buffer_height,
        video->codec_context->pix_fmt,
        video->buffer_width, 
        video->buffer_height, 
        video->format, 
        SWS_BICUBIC, 
        NULL, 
        NULL, 
        NULL
    );

    if (!video->scaler) {
        fprintf(stderr, ERROR("scale context init failed\n"));
        goto failed;
    }

    /* Give some info on stderr about the file & stream */
    av_dump_format(video->format_context, 0, filename, 0);
    return 1;
failed:
    video_free(video);
    return 0;
}