FFmpegFrameRecorder在录制时添加文本/图像

时间:2016-12-01 03:51:26

标签: android ffmpeg javacv android-ffmpeg

有没有人知道如何使用JavaCV中的FFmpegFrameRecorder录制视频时添加文本,图像?我到处搜索但什么都没有

1 个答案:

答案 0 :(得分:3)

阅读JAVCV example,以便在IplImage

中添加文字
FFmpegFrameRecorder recorder = null;

opencv_core.CvFont font = new opencv_core.CvFont(); 
opencv_core.cvInitFont(font, opencv_core.CV_FONT_HERSHEY_SCRIPT_SIMPLEX, 2.0, 2.0, 2, 2, opencv_core.CV_AA);
opencv_core.IplImage bgrImage = opencv_core.IplImage.create(width, height, IPL_DEPTH_8U, 3);;
//...
//init something(eg init recorder,init iplimage...)

opencv_core.cvPutText(bgrImage/*IplImage*/, "Text here", cvPoint(10,10), font, opencv_core.CvScalar.RED);
recorder.record(bgrImage);

或者您可以使用FFmpegFrameRecorder

在位图上绘制文本
      Bitmap newImage = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        Canvas c = new Canvas(newImage);
        c.drawBitmap(your_image_bitmap, 0, 0, null);
        Paint paint = new Paint();
        paint.setColor(Color.RED); 
        paint.setStyle(Style.FILL);                
        paint.setTextSize(20);
        c.drawText("Some Text", 0, 25, paint);
org.bytedeco.javacv.AndroidFrameConverter converter2 = new AndroidFrameConverter();
        Frame frames = converter2.convert(newImage );
        recorder.record(frames);