UPDATE: amide - FFmpeg API

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

UPDATE: amide - FFmpeg API

Brad Smith-14
Update API usage to deal with current vs new FFmpeg API.


Index: Makefile
===================================================================
RCS file: /home/cvs/ports/graphics/amide/Makefile,v
retrieving revision 1.52
diff -u -p -u -p -r1.52 Makefile
--- Makefile 24 Oct 2018 14:28:05 -0000 1.52
+++ Makefile 17 Feb 2019 21:33:49 -0000
@@ -4,7 +4,7 @@ COMMENT = Amide a Medical Imaging Data E
 
 DISTNAME = amide-1.0.5
 CATEGORIES = graphics
-REVISION = 9
+REVISION = 10
 
 HOMEPAGE = http://amide.sourceforge.net/
 
Index: patches/patch-src_mpeg_encode_c
===================================================================
RCS file: patches/patch-src_mpeg_encode_c
diff -N patches/patch-src_mpeg_encode_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_mpeg_encode_c 17 Feb 2019 21:40:52 -0000
@@ -0,0 +1,89 @@
+$OpenBSD$
+
+Update for newer FFmpeg API.
+
+Index: src/mpeg_encode.c
+--- src/mpeg_encode.c.orig
++++ src/mpeg_encode.c
+@@ -142,6 +142,7 @@ static void convert_rgb_pixbuf_to_yuv(yuv_t * yuv, Gdk
+ #ifdef AMIDE_FFMPEG_SUPPORT
+
+ #include <libavcodec/avcodec.h>
++#include <libavutil/frame.h>
+
+
+ typedef struct {
+@@ -234,11 +235,11 @@ gpointer mpeg_encode_setup(gchar * output_filename, mp
+
+   switch(type) {
+   case ENCODE_MPEG4:
+-    codec_type = CODEC_ID_MPEG4;
++    codec_type = AV_CODEC_ID_MPEG4;
+     break;
+   case ENCODE_MPEG1:
+   default:
+-    codec_type=CODEC_ID_MPEG1VIDEO;
++    codec_type = AV_CODEC_ID_MPEG1VIDEO;
+     break;
+   }
+
+@@ -268,7 +269,7 @@ gpointer mpeg_encode_setup(gchar * output_filename, mp
+     return NULL;
+   }
+
+-  encode->picture= avcodec_alloc_frame();
++  encode->picture= av_frame_alloc();
+   if (!encode->picture) {
+     g_warning("couldn't allocate memory for encode->picture");
+     encode_free(encode);
+@@ -293,11 +294,10 @@ gpointer mpeg_encode_setup(gchar * output_filename, mp
+   encode->context->time_base= (AVRational){1,FRAMES_PER_SECOND};
+   encode->context->gop_size = 10; /* emit one intra frame every ten frames */
+   encode->context->max_b_frames=10;
+-  encode->context->pix_fmt = PIX_FMT_YUV420P;
++  encode->context->pix_fmt = AV_PIX_FMT_YUV420P;
+
+   /* encoding parameters */
+   encode->context->sample_aspect_ratio= (AVRational){1,1}; /* our pixels are square */
+-  encode->context->me_method=5; /* 5 is epzs */
+   encode->context->trellis=2; /* turn trellis quantization on */
+
+   /* open it */
+@@ -355,6 +355,10 @@ gpointer mpeg_encode_setup(gchar * output_filename, mp
+   encode->picture->linesize[1] = encode->context->width/2;
+   encode->picture->linesize[2] = encode->context->width/2;
+
++  encode->picture->width = xsize;
++  encode->picture->height = ysize;
++  encode->picture->format = AV_PIX_FMT_YUV420P;
++
+   return (gpointer) encode;
+ }
+
+@@ -362,14 +366,23 @@ gpointer mpeg_encode_setup(gchar * output_filename, mp
+ gboolean mpeg_encode_frame(gpointer data, GdkPixbuf * pixbuf) {
+   encode_t * encode = data;
+   gint out_size;
++  AVPacket pkt = { 0 };
++  int ret, got_packet = 0;
+
+   convert_rgb_pixbuf_to_yuv(encode->yuv, pixbuf);
+
+   /* encode the image */
+-  out_size = avcodec_encode_video(encode->context, encode->output_buffer, encode->output_buffer_size, encode->picture);
+-  fwrite(encode->output_buffer, 1, out_size, encode->output_file);
++  av_init_packet(&pkt);
++  pkt.data = encode->output_buffer;
++  pkt.size = encode->output_buffer_size;
+
+-  return TRUE;
++  ret = avcodec_encode_video2(encode->context, &pkt,
++                              encode->picture, &got_packet);
++  if (ret >= 0 && got_packet) {
++      fwrite(pkt.data, 1, pkt.size, encode->output_file);
++      av_free_packet(&pkt);
++  }
++  return (ret >= 0) ? TRUE : FALSE;
+ };
+
+ /* close everything up */