开发者

How can I programmatically extract a preview image - like the first frame - from an FLV file in Java?

Updated:

Since my orig开发者_运维技巧inal request appears to be almost impossible, what's the next simplest solution? Invoke the swftools app? Make a JNI call to the ffmpeg lib?

Original:

This is related to "how to extract flash frames programmatically" but I am constrained to Java libraries only (and no JNI calls to C please). This also implies no calls to console apps like swftools. I'm looking for a pure Java (or at least JVM) solution.


Or if you want to do it directly from Java, you can use this code. It uses Xuggler, an open-source library for encoding and decoding video from java. Xuggler does use JNI behind the scenes to FFmpeg, but when using it that's totally invisible to you. Hop that helps.

Art


It is possible... if you can accept the end result being one frame FLV file (and not a proper image, like PNG or JPEG.) What is a single frame video, really? It's an image! This may very well give you the functionality you are looking for although it might seem a bit strange.

What you need to do is parse the FLV file. It's actually a very simple format. First, read up on some basic video compression terms. Second, read up on the FLV File Format specification on Adobe's site.

Roughly, an example FLV file would look like this inside:

'FLV' header
Meta data 
Frame 0 - Audio
Frame 1 - Video I-Frame (all information to create a full image) 
Frame 2 - Video P-Frame (just differential from last frame)
Frame 3 - Video P-Frame (just differential from last frame)
Frame 1 - Video I-Frame (all information to create a full image) 
Frame 2 - Video P-Frame (just differential from last frame)
Frame 3 - Video P-Frame (just differential from last frame)
Frame 0 - Audio
Frame 5 
...
Frame n
EOF

So, you'll search for the video I-frame you want as a picture. That, along with a basic FLV file header, together is all you need. Our ouput (be it a socket or a file) will be just:

'FLV' header
Frame 0 - Video I-Frame (all information to create a full image) 

This all can be done in Java without any special tools. I've done it myself. For real.

Note that this approach applies only to FLV files, and not F4V (or other MP4-based file formats.)


Note that playback in SWF is controlled by ActionScript and declarative transformations, so to view that "first frame" properly in all cases you'd need to emulate the whole player. I'd say -- call external tools. What's the problem with them anyway? Is it something religion-mandated?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜