Need help extracting selected frames into PNG files
Hi. Does anyone know how to do just two more things?
Write the extracted frames as PNG files and only grab 3 or 4 selected frames instead of the whole clip.
Thanks in advance.
I have gone through the forum and haven't found any ideas on PNG formats. Found some threads to grab frames using FrameGrabbingControl but ran into problems when i try to grab more than one.
[392 byte] By [
Zeratu_la] at [2007-11-26 12:22:21]

# 1
> Hi. Does anyone know how to do just two more things?
Huh? Note: this question seems closely related
to the thread seen here..
http://forum.java.sun.com/thread.jspa?threadID=5114645&messageID=9392736#9392736
(in which shady posted FrameAccess code for awkash
- hope I got those names right!)
> Write the extracted frames as PNG files ..
Look at the posted source closely, and you
might notice that the strings "jpg" and ".jpg"
are prominent. Try changing those strings
to "png" and ".png".
> ..and only grab 3 or 4 selected frames instead of the whole clip.
That would be implemented in simple loop logic.
Something like, keeping a counter, and ending
the loop at the desired number of frames.
(Such basic looping questions are best answered
on a more general forum, and long before attempting
GUI'd applications, let alone apps. based on the JMF!)
# 2
Hi andrew. thanks for responding. You are right a simple change of the extension successfully coded the image properly.However the loop is a no go.
I had previously implemented the loop but my client was not happy with it since it gave many images that were not neccessary.
I need to pull like 1 frame every 10 seconds. Approximately. Since this requires precise grabbbing rather than cycling through the entire file with the pass through codec. I had minimal success using the FrameGrabbingControl.
The problem is I managed to grab only one frame.I can't get it to grab a few frames at precise timebase intervals.
Any assistance is appreciated.Thanks
# 3
Hi, if I understand properly what you are looking for, then go to http://www.exactfutures.com/index02.htm and download vid2jpg.zip which includes some source that reads every frame and notes its timestamp etc. This may be helpful.
# 4
Hi andy, I have already explored vid2jpg to exhaustion. The whole coding process in it completely messes up any attempt to write as a png file.The output image is corrupted. And still there is the problem of selecting certain frames.
the vid2jpg form also implements the loop to grab the first 1000 frames. As i have mentioned before my client was not happy with the loop because the client specifically wants to see a shot of the frame every 10 secs.approximately.
Any attempt to grab frames fails if attempt to grab more than one.
# 5
> ...As i have mentioned before my client was not happy
> with the loop because the client specifically wants to
> see a shot of the frame every 10 secs.approximately.
How many frames per second is the video?
Lets guess and say 15. How many seconds between
each shot does the client want? 10?
// we have gained numFrames
// into temp.
int fps = 15;
int sec = 10;
for (int ii=0; ii<numFrames; ii+=(fps*sec) ) {
// copy wanted frames to user browsable location
}
// delete any remaining temporary images..
>
# 6
I agree with AndrewThompson64, and effectively tried it with the source below amending vid2jpg, and I got png files saved every 10 seconds for the full movie.
/**
* Called on each new frame buffer
*/
int nextframetime = 0;
private void useFrameData(Buffer inBuffer)
{
// stop limitation of 1000 frames
//countFr++;
//if(countFr<startFr || countFr>endFr)return;
try
{
printDataInfo(inBuffer);
if(inBuffer.getData()!=null)// vfw://0 can deliver nulls
{
if(outvid==null)outvid = new int[imgWidth*imgHeight];
outdataBuffer(outvid,(byte[])inBuffer.getData());
setImage(outvid);
if(sunjava)// and with import javax.imageio.*;
{
int frametimesecs = (int)(inBuffer.getTimeStamp()/1000000000);
if(frametimesecs%10 == 0 && frametimesecs==nextframetime)
{
nextframetime+=10;
BufferedImage bi = new BufferedImage(outputImage.getWidth(null), outputImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = bi.getGraphics();
g.drawImage(outputImage, 0, 0, this);
ImageIO.write(bi, "png", new File("images"+sep+"image_"+(inBuffer.getTimeStamp()/1000000000)+".png"));
}
}
}
}
catch(Exception e){System.out.println(e);}
}
# 7
Andrew and andy. thanks a million. You have solved the predicament i was in, in one fell swoop.Much appreciated.