I am currently developing a simple video player in python, and my
problem is that i can't find a module which has a function that can
determine if frame(image) is I or P coded (MPEG coding). I have been
using PIL but I couldnt find anything that could help me with that
problem.
Thanks for sugestions!
How are you reading the video? PIL doesn't claim to do more than identify
MPEG files. Also, which MPEG encoding, in which container format?
If you aren't just putting a wrapper around something like ffmpeg, I
rather suspect you'll have to decode the bitstream yourself. That could
be rather painful if you're talking about MPEG-4/10.
--
Rhodri James *-* Wildebeeste Herder to the Masses
> Hy, first thanks for your response!
> Well I am thinkin on coding in MPEG4/10, but I would just encode the
> video in that encoding,
> then stream it with VLC and save the video file on my disc. Then I
> would play it with my player....
I think you're misunderstanding what VLC does here. Saving the video file
should preserve format by default; you may be able save it out in YUV
format (I don't have a copy on this machine to check), but that will take
up ludicrous amounts of disc space and you'd still have to write a byte
reader for it. If you do do that, you have lost any chance of knowing
whether a frame was an I or P frame in the original format, not that it
matters anyway by that point.
MPEG-4/10 is hard to write efficient decoders for, and I have to admit I
wouldn't do it in Python. You'd be better off writing a wrapper for one
of the existing MP4 libraries.
Hm, well I see that and now I am thinking of using reference software
for MPEG4/10 which is written in c++ http://iphome.hhi.de/suehring/tml/
just to use it as a decoder on my client side, save the file in that
format and then play it in my player using pyffmpeg
http://code.google.com/p/pyffmpeg/ and just manipulate frames in that
clip-I think that could be possible....am I right? Thanks for your
help!
After you have passed the video through a decoder, it's no longer in MPEG
format at all. It's just a series of bitmaps, so pyffmpeg wouldn't apply.
If you want to save the raw MPEG data, you can certainly do that, but such
data is often not divided into "frames".
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
By the looks of it, pyffmpeg may have some support for streamed input. If
not, you might be able to put something together from tstools
(http://developer.berlios.de/projects/tstools/) -- it's not what the tools
were intended for, but there are Python bindings to the libraries that
might help depending on exactly how you are streaming your video.
Unfortunately the documentation is sparse to put it mildly, and pyffmpeg
makes tstools look positively informative about how you're supposed to use
it.
If you want to manipulate the frames (as bitmaps), then you have little
choice but to decode the MPEG as you receive it, manipulate the bitmaps,
and re-encode it back to MPEG.
That's going to take a fair amount of time...
Yes, well beside bieng time-consuming, that is also inappropriate for
me,
because I want to have clip that would be streamed across the network
and
have the same GoP on the client side as the original-because I want to
see
what is the effect of errors on different GoP sizes. I would
manipuleta the
received clip just in the way that (if there are too many errors) I
would
stop displaying untill the next I frame.....I cant find a way to do
that....is there a way?
Could you say a bit more about what you mean when you say "the effect of
errors"? It's easy enough to introduce bit errors into a data file (just
flip random bits), but I'm not clear what it is you're trying to measure.
Sure. You can do a partial decode yourself, scan for the start of frame
markers, pull the I/P/B state from that, and periodically "forget" to pass
the buffer through. Your filter could have MPEG in and out.
@Tim Thanks for the advice, now I will try to do that so I have a lot
of work in front of me. I will post any problems if they occure.
Guys thank you again for the help!
> @James I am thinkinhg about effect of errors that are within the
> sequence of P frames. Where the P frames have only the information
> about the changes in previous frames, so that errors are present until
> the next I frame. So I would like to see how is this seen in different
> GoP sized clips.
Ah, I see. What I'd suggest you do is to encode your video clip at
various GOP sizes (you'll want some quite extreme ones for comparison),
then write a little program that reads in the file byte by byte and
randomly corrupts the data as it goes through. "tsplay" from the tstools
suite that I mentioned earlier will do that for you (because it was very
handy for testing the robustness of our decoders). Then watch the results
using VLC or similar.
My recollection is that when the image isn't static, P frames tend to have
enough intra-coded blocks that corrupted video data doesn't have as much
effect as you might think. I've dealt with streams that had ten seconds
or more between I frames, and starting at a random spot (simulating
changing channel on your digital TV) builds up an intelligible (if
obviously wrong) image surprisingly quickly.
PS: my first name is Rhodri, not James. Don't worry, it catches a lot of
people out.
Well for my simulation of errors I am thinking on using the WANem
(Wide Area Netwrok Emulator) which has a function to simulate dellay,
jitter etc.. http://wanem.sourceforge.net/
I have been downloading the clips from youtube and I surprisengly saw
that I frame occures after 300 frames(at 15fps-so that means after 20
seconds)! That was quite unusal for my perception of the purpose of I
frame, but then I figured out that (as you mentioned) P frames include
intra-coded blocks which hide the effect of the errors.
The goal of my project is to make a program which plays the corrupted
video after being out thru error concealment, and in case when errors
overcome some threshold error value the program doesn't paly any more
frames until the I frame occures and then I would figure out the
optimal threshold value for the different GoP sizes as well as
different content of the clip.