View Full Version : Getting a single frame from .264 file ? (Dot.Net)
Leon2009
15th June 2009, 16:33
Hi all,
I started a new application under Dot.Net, in that application I have to get one single frame from an asked index, of an .264 video file (usually it will be the first frame, index 0) , and I have to display the frame on the form (for example inside a paintBox).
Is there any ready example showing how to do something like that? what is a good starting point here?
I have found a short example code here -
http://forum.doom9.org/showthread.php?t=109143
(look at the answer)
but when I'm trying to run it on a .H264 video file that I have (which runs without problems under VLC Player) it couldn't find that 0x000001B8 sequence even once.
Also, after I'm locating the first frame, should I translate each 3 bytes into single pixel value? (RGB) or is there another method for doing this?
Thanks.
neuron2
16th June 2009, 00:56
1b8 is an MPEG2 start code and is not applicable to AVC. It is not easy to do what you ask. After you locate the start of the desired frame, you have to decode it. And you have to ensure that the required SPS and PPS are available.
drmpeg
16th June 2009, 01:02
Hi all,
I started a new application under Dot.Net, in that application I have to get one single frame from an asked index, of an .264 video file (usually it will be the first frame, index 0) , and I have to display the frame on the form (for example inside a paintBox).
Is there any ready example showing how to do something like that? what is a good starting point here?
I have found a short example code here -
http://forum.doom9.org/showthread.php?t=109143
(look at the answer)
but when I'm trying to run it on a .H264 video file that I have (which runs without problems under VLC Player) it couldn't find that 0x000001B8 sequence even once.
Also, after I'm locating the first frame, should I translate each 3 bytes into single pixel value? (RGB) or is there another method for doing this?
Thanks.
The 0x000001B8 start code only exists in MPEG-2 video bitstreams. Try changing it to 0x00000127 or 0x00000167.
However, a byte parser isn't the best scheme for H.264, where there are variable bit length codes even in the headers. Take a look at h264_parse located here:
http://www.w6rz.net/h264_parse.zip
I'm afraid your last question is very naive. Actually decoding the bitstream to a viewable picture is way more complex. Source code for a decoder is available here:
http://iphome.hhi.de/suehring/tml/
Ron
Leon2009
18th June 2009, 17:52
Thank very much for the answers, so it's not that simple...
Is there any ready component or DLL that can do that automatic, and I can call from my application? (which will save me the need of writting the code by myself)
Thanks.
LoRd_MuldeR
18th June 2009, 19:59
Ever heard of ffmpeg/libavcodec? :D
(Note: Writing a H.264 decoder yourself from the scratch would be a whole lot of work!)
Leon2009
21st June 2009, 10:07
"Ever heard of ffmpeg/libavcodec?"
Yes, I checked it but it wasn't so clear how to use it for getting a single frame from the file... any idea?
LoRd_MuldeR
21st June 2009, 14:03
Yes, I checked it but it wasn't so clear how to use it for getting a single frame from the file... any idea?
Look at one of the various tools that use libavcodec and see how they do it ;)
MPlayer/MEncoder, ffdshow, FFVideoSource, Avidemux, etc...
Leon2009
22nd June 2009, 10:46
I will give it a try, thanks.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.