Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MODULE FOR I, P FRAME

13 views
Skip to first unread message

DANNY

unread,
Feb 11, 2010, 2:31:52 PM2/11/10
to
Hello!

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!

Rhodri James

unread,
Feb 11, 2010, 6:32:08 PM2/11/10
to

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

DANNY

unread,
Feb 14, 2010, 5:07:35 AM2/14/10
to
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 was thinking on using the image
iterator in PIL...because I would encode the video in GoP of 10 (one I
and 9P), and then I would manipulate it within the sequence...so I
dont have to have a special decoder, because the VLC would already
decode it.

Rhodri James

unread,
Feb 15, 2010, 5:53:37 PM2/15/10
to
On Sun, 14 Feb 2010 10:07:35 -0000, DANNY <danije...@gmail.com> wrote:

> 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.

DANNY

unread,
Feb 16, 2010, 2:14:32 AM2/16/10
to
On Feb 16, 12:53 am, "Rhodri James" <rho...@wildebst.demon.co.uk>
wrote:


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!

Tim Roberts

unread,
Feb 18, 2010, 3:07:02 AM2/18/10
to
DANNY <danije...@gmail.com> wrote:
>
>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?

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.

DANNY

unread,
Feb 18, 2010, 4:50:14 AM2/18/10
to
If I want to have a MPEG-4/10 coded video and stream it through the
network and than have the same video on the client side, what should I
use and of course I don't want to have raw MPEG data, because than I
couldn't extract the frames to manipulate them.

Rhodri James

unread,
Feb 18, 2010, 8:11:52 PM2/18/10
to

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.

Tim Roberts

unread,
Feb 20, 2010, 6:54:55 PM2/20/10
to

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...

DANNY

unread,
Feb 22, 2010, 5:48:55 AM2/22/10
to
On Feb 21, 1:54 am, Tim Roberts <t...@probo.com> wrote:
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.

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?

Rhodri James

unread,
Feb 22, 2010, 7:20:18 PM2/22/10
to

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.

Tim Roberts

unread,
Feb 23, 2010, 12:10:55 AM2/23/10
to
DANNY <danije...@gmail.com> wrote:
>
>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?

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.

DANNY

unread,
Feb 23, 2010, 5:39:21 AM2/23/10
to
@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.

@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!

Rhodri James

unread,
Feb 23, 2010, 8:11:48 PM2/23/10
to
On Tue, 23 Feb 2010 10:39:21 -0000, DANNY <danije...@gmail.com> wrote:

> @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.

DANNY

unread,
Feb 24, 2010, 3:28:12 AM2/24/10
to
On Feb 24, 3:11 am, "Rhodri James" <rho...@wildebst.demon.co.uk>
wrote:

> On Tue, 23 Feb 2010 10:39:21 -0000, DANNY <danijel.gv...@gmail.com> wrote:
> > @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 Iframe. 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.
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses

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.

0 new messages