Log in

View Full Version : Problem with MPEG2 "system start codes"


artak
16th April 2008, 06:57
Hello all. I have a problem when trying to decode MPEG2 stream encoded with ffmpeg. I noticed that problem is caused by the "system start codes" occurrences during decoding the subsequent dct coefficients (i.e. after decoding dct coefficients of 3-4 blocks of macroblock without marking the EOB it comes the "system start code" while I'm waiting for other variable length coded dct coefficients), and I don't know how to deal with it. I can't find something useful via searching the Internet. Can anybody help me with this?

Guest
16th April 2008, 12:28
You're claiming that ffmpeg creates illegal MPEG2? Post a short sample stream that we can use to investigate your claim.

artak
17th April 2008, 06:52
The example of file is attached. I created it using command
ffmpeg -i <input_file_name>.mpeg -ss 22 -an -vcodec mpeg2video -vframes 10 bee.mpeg.
My problem is in the first picture, 6th slice, within macroblock N118.
When I analyse the bitstream using hexdecimal editor, I noticed that within the sixth slice there is a "system start code" (00 00 01 E0).
If you know tools which analyse MPEG2 bitstream, please give a reference so I can use it to determine the problem.

Guest
17th April 2008, 14:41
That's normal. You have a program stream containing PES packets. The start code 00 00 01 E0 is the stream ID that starts a new PES packet. The video elementary stream continues in the payload of the packet. You can look at the source code for DGIndex, for example, to see how to parse the elementary stream from the program stream. The specification for the packetizing can be found here:

http://neuron2.net/library/mpeg2/iso13818-1.pdf

If you just need to look at the elementary stream, you can demux it using DGIndex (Save Project and Demux Video).

artak
18th April 2008, 07:09
Thanks for now. But now I have no time to read the ISO/IEC 13818-1 standard (to understand the source code is much worse). Can you just say an option that I can use with ffmpeg to encode a mpeg2 stream without any "system start codes".

45tripp
18th April 2008, 07:28
ffmpeg -i <input_file_name>.mpeg -f rawvideo -ss 22 -an -vcodec mpeg2video -vframes 10 bee.m2v


?

artak
18th April 2008, 10:07
I tried it. All 10 pictures were in separate sequences. Is it OK???
It means that if program stream is not packetized, each picture will be in separate sequence, am I right?

Guest
18th April 2008, 13:14
It means that if program stream is not packetized, each picture will be in separate sequence, am I right? I don't know what ffmpeg is doing, but in general, that is not correct.

artak
18th April 2008, 13:42
At least it specifies to standard (but I also think that there is something wrong). The worse is that in the end of file there is no sequence_end_code (which is needed by standard).

Guest
18th April 2008, 13:57
Maybe it happened because you encoded only 10 frames. What happens if you do a longer one?

Also, you can set the GOP size with -g. For example:

-g 10

The sequence end code is not strictly required. In broadcasting you hardly ever see them, as the stream is continuous. Even in files, it causes problems for joining.

artak
18th April 2008, 15:28
It missed even if I encode the whole video.
I though that if specification written for example

video_sequence() {
.............
.............
sequence_end_code | 32 | bslbf
},

then it should always be in stream(subclause 6.2.2). If not, I must also every time after reading picture check for EOF.:(
Also I didn't understand -g option should help to avoid packetizing or connected with sequence_end_code, but it didn't help both of them.

45tripp
18th April 2008, 15:36
ffmpeg -i dagg.m2v -f rawvideo -vcodec mpeg2video
-qscale 2 -an -ss 20 -vframes 10 outpes.m2v

http://www.mediafire.com/?28bcde0ywmu

there's something wrong with this?
i don't see it

i don;t think you can have sequence end code with current ffmpeg revisions.
you could probably track back to the revision it was removed though.

Guest
18th April 2008, 19:01
there's something wrong with this?
Looks fine to me. It has one sequence header, one sequence extension, one GOP header, then an I frame followed by 9 P frames.

@artak

Post a link to your M2V that you think is using a new sequence for each picture. Also post the ffmpeg line used to create it. Also the ffmpeg version.

then it should always be in stream(subclause 6.2.2). If not, I must also every time after reading picture check for EOF.
Also I didn't understand -g option should help to avoid packetizing or connected with sequence_end_code, but it didn't help both of them. Yes, of course you have to check for EOF! You don't know what GOPs are? The -g option determines how many pictures are included in a GOP. If you have 10 pictures in a GOP, it must be part of a single sequence, per MPEG2 syntax.

artak
21st April 2008, 05:52
There is the command line execution of ffmpeg what I used:
ffmpeg -i input.mpeg -an -vcodec mpeg2video -vframes 10 -ss 26 -f rawvideo -intra -g 10 output.m2v

And this is the output of ffmpeg -version:
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration:
libavutil version: 49.4.0
libavcodec version: 51.40.4
libavformat version: 51.12.1
built on Mar 24 2008 11:45:25, gcc: 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
ffmpeg SVN-rUNKNOWN
libavutil 3212288
libavcodec 3352580
libavformat 3345409

Guest
21st April 2008, 12:57
I confirm that there is one picture per sequence.

Maybe it is due to using the -intra option. What if you omit that just for testing?

Also, what is the reason for the -f rawvideo option. Try deleting that also.

If all else fails, there is always the HCEnc encoder.

45tripp
21st April 2008, 16:05
I confirm that there is one picture per sequence.

Maybe it is due to using the -intra option.

well yeah!
when did that creep in?

fmpeg -i input.mpeg -an -vcodec mpeg2video -vframes 10
-ss 26 -f rawvideo -qscale 2 -i_qfactor 1 output.m2v

what exactly are you trying to do?

ffmpeg i believe will define a gop as i-frame to i-frame,
despite any -g setting.
just like most encoders.
don't know if you can override that someway with ffmpeg.

maybe you should look into using the libs directly.



If all else fails, there is always the HCEnc encoder.

HC can't do i-frames only.
(you will be able to add seq_endcode though)

In fact the only thing i can think of to output i-frames only,
and set a gop enclosing a string of i-frames is CCE.


Also, what is the reason for the -f rawvideo option. Try deleting that also.

well one can, with ffmpeg as long as the output extension is .m2v,
but i find it good practice to leave it in.


gl