stereoplay

diff src/vid.c @ 6:8fc045d33d62

updated the code to work with more recent ffmpeg versions
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 26 Sep 2020 14:26:39 +0300
parents acf3d25f23cb
children
line diff
     1.1 --- a/src/vid.c	Thu Nov 03 22:01:01 2011 +0200
     1.2 +++ b/src/vid.c	Sat Sep 26 14:26:39 2020 +0300
     1.3 @@ -1,6 +1,6 @@
     1.4  /*
     1.5  Stereoplay - an OpenGL stereoscopic video player.
     1.6 -Copyright (C) 2011  John Tsiombikas <nuclear@member.fsf.org>
     1.7 +Copyright (C) 2011-2020  John Tsiombikas <nuclear@member.fsf.org>
     1.8  
     1.9  This program is free software: you can redistribute it and/or modify
    1.10  it under the terms of the GNU General Public License as published by
    1.11 @@ -15,11 +15,11 @@
    1.12  You should have received a copy of the GNU General Public License
    1.13  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.14  */
    1.15 -
    1.16  #include <stdio.h>
    1.17  #include <libavcodec/avcodec.h>
    1.18  #include <libavformat/avformat.h>
    1.19  #include <libswscale/swscale.h>
    1.20 +#include <libavutil/imgutils.h>
    1.21  #include "vid.h"
    1.22  
    1.23  struct video_file {
    1.24 @@ -49,13 +49,13 @@
    1.25  	}
    1.26  	memset(vf, 0, sizeof *vf);
    1.27  
    1.28 -	if(av_open_input_file(&vf->avctx, fname, 0, 0, 0) != 0) {
    1.29 +	if(avformat_open_input(&vf->avctx, fname, 0, 0) != 0) {
    1.30  		fprintf(stderr, "open_video(%s): failed to open file\n", fname);
    1.31  		vid_close(vf);
    1.32  		return 0;
    1.33  	}
    1.34  
    1.35 -	if(av_find_stream_info(vf->avctx) < 0) {
    1.36 +	if(avformat_find_stream_info(vf->avctx, 0) < 0) {
    1.37  		fprintf(stderr, "open_video(%s): failed to find stream info\n", fname);
    1.38  		vid_close(vf);
    1.39  		return 0;
    1.40 @@ -81,20 +81,20 @@
    1.41  		return 0;
    1.42  	}
    1.43  
    1.44 -	if(avcodec_open(vf->cctx, vf->codec) < 0) {
    1.45 +	if(avcodec_open2(vf->cctx, vf->codec, 0) < 0) {
    1.46  		fprintf(stderr, "open_video(%s): failed to open codec\n", fname);
    1.47  		vid_close(vf);
    1.48  		return 0;
    1.49  	}
    1.50  
    1.51 -	if(!(vf->frm = avcodec_alloc_frame()) || !(vf->rgbfrm = avcodec_alloc_frame())) {
    1.52 +	if(!(vf->frm = av_frame_alloc()) || !(vf->rgbfrm = av_frame_alloc())) {
    1.53  		fprintf(stderr, "open_video(%s): failed to allocate frame\n", fname);
    1.54  		vid_close(vf);
    1.55  		return 0;
    1.56  	}
    1.57  
    1.58  	vf->sws = sws_getContext(vf->cctx->width, vf->cctx->height, vf->cctx->pix_fmt,
    1.59 -			vf->cctx->width, vf->cctx->height, PIX_FMT_RGB32, SWS_POINT, 0, 0, 0);
    1.60 +			vf->cctx->width, vf->cctx->height, AV_PIX_FMT_RGB32, SWS_POINT, 0, 0, 0);
    1.61  	if(!vf->sws) {
    1.62  		fprintf(stderr, "open_video(%s): failed to allocate sws context\n", fname);
    1.63  		vid_close(vf);
    1.64 @@ -117,7 +117,7 @@
    1.65  	if(vf->rgbfrm) av_free(vf->rgbfrm);
    1.66  	if(vf->frm) av_free(vf->frm);
    1.67  	if(vf->cctx) avcodec_close(vf->cctx);
    1.68 -	if(vf->avctx) av_close_input_file(vf->avctx);
    1.69 +	if(vf->avctx) avformat_close_input(&vf->avctx);
    1.70  	free(vf);
    1.71  }
    1.72  
    1.73 @@ -153,22 +153,22 @@
    1.74  {
    1.75  	AVPacket packet;
    1.76  	int frame_done = 0;
    1.77 -	AVPicture *rgbfrm = (AVPicture*)vf->rgbfrm;
    1.78 -	AVPicture *frm = (AVPicture*)vf->frm;
    1.79  
    1.80 -	avpicture_fill((AVPicture*)vf->rgbfrm, (uint8_t*)img, PIX_FMT_RGB32, vf->cctx->width, vf->cctx->height);
    1.81 +	av_image_fill_arrays(vf->rgbfrm->data, vf->rgbfrm->linesize, (unsigned char*)img,
    1.82 +			AV_PIX_FMT_RGB32, vf->cctx->width, vf->cctx->height, 1);
    1.83  
    1.84  	while(av_read_frame(vf->avctx, &packet) >= 0) {
    1.85  		if(packet.stream_index == vf->vstream) {
    1.86  			avcodec_decode_video2(vf->cctx, vf->frm, &frame_done, &packet);
    1.87  
    1.88  			if(frame_done) {
    1.89 -				sws_scale(vf->sws, frm->data, frm->linesize, 0, vf->cctx->height, rgbfrm->data, rgbfrm->linesize);
    1.90 -				av_free_packet(&packet);
    1.91 +				sws_scale(vf->sws, vf->frm->data, vf->frm->linesize, 0, vf->cctx->height,
    1.92 +						vf->rgbfrm->data, vf->rgbfrm->linesize);
    1.93 +				av_packet_unref(&packet);
    1.94  				return 0;
    1.95  			}
    1.96  		}
    1.97 -		av_free_packet(&packet);
    1.98 +		av_packet_unref(&packet);
    1.99  	}
   1.100  
   1.101  	return -1;