JavaCV capture a frame using FFmpeg - ffmpeg

I create a class that capture frame from a video. When it capture a frame, it's saved as a picture. When the video is .avi, application works ok. When format is .avi.
public static void main(String[] args) {
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("C:/Users/Ioanna/Desktop/video1.avi");
try {
IplImage img;
//Start grabber to capture video
grabber.start();
//grab video frame to IplImage
img = grabber.grab();
if (img != null) {
//save video frame as a picture
cvSaveImage("capture.jpg", img);
}
}catch (Exception e) {
}
}
The error is
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.googlecode.javacv.FFmpegFrameGrabber.<init>(FFmpegFrameGrabber.java:106)
at Video.main(Video.java:75)
Caused by: java.lang.IllegalStateException: Can't overwrite cause with java.lang.UnsatisfiedLinkError: no avcodec in java.library.path
at java.lang.Throwable.initCause(Throwable.java:457)
at com.googlecode.javacpp.Loader.load(Loader.java:581)
at com.googlecode.javacpp.Loader.load(Loader.java:532)
at com.googlecode.javacv.cpp.avcodec.<clinit>(avcodec.java:39)
... 2 more
Caused by: java.lang.UnsatisfiedLinkError: no jniavcodec in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1837)
Do anyone know what is the problem?
Thanks in advance

After searching the web for quite some time, I came to the following solution:
Step 1: Download the .zip file "javacv-0.6-cppjars.zip" from
https://code.google.com/p/javacv/downloads/list and unzip it.
Step 2: Add "ffmpeg-20130915-git-7ac6c63-windows-x86_64.jar" file to your Java project!

Related

Save image in javaFX with applying effects on the image

I am making an application in JavaFX where the user can upload the photo and apply the effects on it, and in the end, save the image with the effects.
When I save the image, the original image is saved without the effects.
I get the image from the ImagView and save it in the file but the image is saved without the effects.
How I can solve this problem and have the picture with the effects that I applied to it?
The methods below the first one is to apply the effects and the second one is to save the image from ImageView
I need any idea to help me to solve this problem please.
\\Method of applying the filter
public void applyFilter(){
SepiaTone sepiaTone = new SepiaTone(cons);
myImgView.setEffect(sepiaTone);
}
public void saveImage() throws IOException {
Image imageToBeSaved = myImgView.getImage();// get the image from ImageView
File file = new File("D:/image.png");
try {
ImageIO.write (SwingFXUtils.fromFXImage(imageToBeSaved,null), "png", file);
}
catch (IOException e) {
e.printStackTrace();
}
}

Flutter try catch to open file

I am trying to load an image and then display it. But it is possible the image is not yet existing because the user has not set it yet (in this case it is an image from assets that is displayed). I use a try/catch to see if the file is existing or not to avoid any error but the exception is never catched. Here the code I use :
void initState() {
super.initState();
widget.storage.readDirectory().then((String value) {
Image localImage;
try {
localImage = Image.file(File('$value/photoProfile.jpg'));
} catch (Exception) {
return localImage =null ;
}
setState(() {
_photoPath = localImage;
});
});
}
And the error :
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following FileSystemException was thrown resolving an image codec:
Cannot open file, path = '/data/user/0/com.example.flutterappdeepfashion/app_flutter/photoProfile.jpg' (OS Error: No such file or directory, errno = 2)
How can I solve my problem and avoid errors ?
Thank you for your help !
Is your image in the assets folder ? Because the path you are trying to access is the app cache.

How to render password-protected PDF

I am using Flying Saucer to generate PDF from XHTML. Rendering works nice, but any attempt to password-protect the PDF document fails with an Exception.
I am using code recommended by Ajit Soman in https://stackoverflow.com/a/46024498/4517737. A copy of code is shown below.
If you un-comment the commented line, Exception is thrown in line "renderer.createPDF(os, false)".
The Exception is
"Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException"
(for JavaFX application).
For plain Java, the Exception is "Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable
at com.itextpdf.text.pdf.PdfEncryption.(PdfEncryption.java:147).....
Caused by: java.lang.ClassNotFoundException:org.bouncycastle.asn1.ASN1Encodable"
final File outputFile = File.createTempFile(fileName, ".pdf");
FileOutputStream os = new FileOutputStream(outputFile);
PDFEncryption pdfEncryption = new PDFEncryption();
String password= "password#123";
pdfEncryption.setUserPassword(password.getBytes());
ITextRenderer renderer = new ITextRenderer();
// the following line causes Exception
// renderer.setPDFEncryption(pdfEncryption);
renderer.setDocumentFromString(htmlContent);
renderer.layout();
renderer.createPDF(os, false);
renderer.finishPDF();
Please help.

JavaFx - Creating animation from Image array

I have array of Image in JavaFx. I want create a clip video (animation) from those images, including sound file.
How Can I achieve this?
NOTE: I want to get a video file at the end of the process (avi, mp4 ...).
This is my array:
Image[] frames
I tried use "keyFrame" class... but without success:
ImageView destImageView = new ImageView();
Group group;
group = new Group();
group.setTranslateX(300);
group.setTranslateY(450);
Image[] frames = m.getFrames();
KeyFrame[] kf = new KeyFrame[frames.length];
for(int i=0;i<frames.length;i++){
kf[0] =new KeyFrame(new Duration(0), new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
// destImageView.setImage();
// group.getChildren().setAll(destImageView);
}
});
}
You can use
javax.imageio.ImageIO.write(javafx.embed.swing.SwingFXUtils.fromFXImage(frame, null), "png", new File(directory, fileName));
to save each image as a png file.
Make sure to give the frames sequentially numbered filenames, e.g. img0000.png, img0001.png etc..
Then use ImageJ/Fiji (https://imagej.net/Fiji/Downloads)
to import the image sequence and save as an avi file. Alternatively, as ImageJ is open-source and written in Java you could import and use directly the ImageJ class
ij.plugin.filter.AVI_Writer
You could then convert it to an mp4 or other format using VLC Player, for example.

itextsharp 5.4.4 - GetDrawingImage decodes this image the wrong way - why?

This pdf is displayed on my Firefox very well but in a C# program I wrote using itextsharp 5.4.4, I used the GetDrawingImage method of the PdfImageObject and I get a grabled image.
I used itextsharp in the following way:
PdfReader reader = new PdfReader(filename);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
ImageRenderListener listener = new ImageRenderListener();
parser.ProcessContent(pageNumber, listener);
Where ImageRenderListener is a IRenderListener, which implements the RenderImage method in the following way:
public void RenderImage(ImageRenderInfo renderInfo)
{
PdfImageObject image = renderInfo.GetImage();
PdfObject obj = image.Get(PdfName.FILTER);
PdfName filter = null;
if (obj is PdfName)
{
filter = (PdfName)obj;
}
else if (obj is PdfArray)
{
foreach(var o in (PdfArray)obj)
{
if (o is PdfName)
{
filter = o as PdfName;
break;
}
}
}
if (filter != null)
{
System.Drawing.Image drawingImage = image.GetDrawingImage();
...
...
...
}
The drawing image is stored in the listener and then drawn to the screen etc...
I tried to understand this, I get that the filter is a /CCITTFaxDecode but the streamContentType is somehow a png, could someone enlighten me on this matter?
The reason for this problem is explained in the following video: Ripping your PDF files apart. If you don't want to sit through the complete video, fast forward to minute 24 and watch everything up onto minute 27. Note the conclusion on minute 27: In general, there are no images in PDF. (That's exaggerated, but if you understand the 3 minutes of explanation, you understand what Mark Stephens means.)
If you want the details about why CCITTFaxDecode is changed into PNG, please read chapter 10 of my book.

Resources