Showing posts with label Spring Boot. Show all posts
Showing posts with label Spring Boot. Show all posts

Friday, 11 August 2017

Create Thumbnail in Video in Spring and ffmpeg

import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.jcodec.api.FrameGrab; import org.jcodec.api.JCodecException; import org.jcodec.common.model.Picture; import org.jcodec.scale.AWTUtil; public class VideoThumbTaker { private String VIDEO_THUMBNAIL_FOLDER_NAME = "thumbnail"; private String UPLOAD_DIRECTORY = "D:/images/" protected String ffmpegApp; public VideoThumbTaker(String ffmpegApp) { this.ffmpegApp = ffmpegApp; } public static String captureImage(String inputFile, int organizationId) throws Exception, IOException, JCodecException { String filename = Constants.VIDEO_THUMBNAIL_FILE_PREFIX+System.currentTimeMillis()+".png"; int frameNumber = 1; Picture picture = FrameGrab.getFrameFromFile(new File(inputFile), frameNumber); BufferedImage bufferedImage = AWTUtil.toBufferedImage(picture); ImageIO.write(bufferedImage, "png", new File(UPLOAD_DIRECTORY+"/"+VIDEO_THUMBNAIL_FOLDER_NAME+"/" + filename)); return "o"+organizationId+"/"+VIDEO_THUMBNAIL_FOLDER_NAME+"/" + filename; } }

Send Google FCM Push Notification Using Spring Boot

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.esense.touch.dbconstants.NOTIFICATION; import com.esense.touch.dbconstants.STORY; import com.esense.touch.dbconstants.USER_NOTIFICATION; import com.esense.touch.dbconstants.USER_ROLE; import com.esense.touch.dbconstants.USER_ROLE_DETAIL; import com.esense.touch.service.NotificationService; @Service public class PushNotificationService { private String AUTH_KEY_FCM="your server auth key"; @Autowired NotificationService notificationService; public String sendPushNotification(Rows row) throws IOException { String result = ""; URL url = new URL(Constants.API_URL_FCM); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "key=" + AUTH_KEY_FCM); conn.setRequestProperty("Content-Type", "application/json"); try { JSONObject json = new JSONObject(); json.put("to", "device Id"); JSONObject info = new JSONObject(); String notificationTitle = "Notification"; info.put("title", notificationTitle); info.put("body", "Content"); info.put("image","abc/abc.jpg"); json.put("data", info); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(json.toString()); wr.flush(); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder sb = new StringBuilder(); String output; while ((output = br.readLine()) != null) { sb.append(output); } JSONObject outputobj = new JSONObject(sb.toString()); if(outputobj.get("success").equals(1)){ // success you can write your success code here } result = "success"; } catch (Exception e) { e.printStackTrace(); result = "failure"; } return result; } }

Create Thumbnail in Video in Spring and ffmpeg

import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.jcodec.api.Fr...