Welcome Guest ( Log In | Register )


Important

The forums will be closing permanently the weekend of March 15th. Please see the notice in the announcements forum for details.

Pages: (4) « First ... 2 3 [4]  ( Go to first unread post )
Problems With Mpeg-1 Files, Layer 1 audio and VBR-audio problems
« Next Oldest | Next Newest » Track this topic | Email this topic | Print this topic
fccHandler
Posted: Dec 12 2002, 07:22 PM


Administrator n00b


Group: Moderators
Posts: 3961
Member No.: 280
Joined: 13-September 02



@S_O:

MPEG_check_audio_header_validity() tests whether a DWORD can represent a valid MPEG audio header, given what is known to be required of the bits in a header. The bitmask that phaeron speaks of (which I changed) tests whether each new header is consistent with the first header of the stream. Fields like the layer and sampling rate are not supposed to change from one header to the next. VirtualDub's original bitmask also assumed that the copyright bit would not change (oops). The bitmask which phaeron suggested assumes that the bitrate won't change (and breaks my support for VBR).

If the header is real (the validity() function returns "true") and is consistent with the first header, the parser can calculate the exact size of the frame data and skip over it to where the next header should be. (It's now "in sync" with the stream.)

If any test fails (the header is invalid or inconsistent), the parser discards it and immediately falls out of sync. It blazes through the data bytes searching for a DWORD that might be a header. In this case, it may test hundreds or thousands of DWORDs before finding the next real header and getting itself back in sync.



--------------------
May the FOURCC be with you...
 
     Top
S_O
Posted: Dec 12 2002, 08:19 PM


Vdubmod Alpha Testing Team


Group: Vdubmod Alpha Testing Team
Posts: 102
Member No.: 57
Joined: 25-July 02



Ok, you also changed the mask, now I understand why my code didnīt worked correctly and only found 7 frames.
But, why does the parser didnīt resync itself, also it test thousands of frames ? Maybe there is a corrupt header like an invalid emphasis, because of errors during transfers or encoding/muxing you will also only get the audio up to that frame. Also VirtualDub shouldnīt grow in space while doing that up to 500MB.
Updated, tested with flag-changes in private, copyright, original and emphasis: vdub_mpegfix.zip
 
     Top
phaeron
Posted: Dec 12 2002, 10:28 PM


Virtualdub Developer


Group: Administrator
Posts: 7773
Member No.: 61
Joined: 30-July 02



One of the problems with MPEG audio is that, unlike MPEG video start codes, audio syncwords are not unique in the stream. Once the parser desynchronizes, it very easily picks up parts of the subband sample data as headers. To some extent this can be alleviated by verifying that a valid header exists after the frame size indicated in the first header, but that is still not bulletproof.

 
    Top
fccHandler
Posted: Dec 13 2002, 05:59 AM


Administrator n00b


Group: Moderators
Posts: 3961
Member No.: 280
Joined: 13-September 02



QUOTE (S_O @ Dec 12 2002, 04:19 PM)
But, why does the parser didnīt resync itself, also it test thousands of frames ? Maybe there is a corrupt header like an invalid emphasis, because of errors during transfers or encoding/muxing you will also only get the audio up to that frame. Also VirtualDub shouldnīt grow in space while doing that up to 500MB.

1) To resync, the parser must test every single byte to determine if it might represent the beginning of a frame header.

2) Technically, the value 2 for emphasis is "reserved," but I've never encountered an MPEG audio stream that used this value. (The test can easily be removed if necessary.)

3) I don't know why VirtualDub stalled and "grew in space," but I guess it's fixed now and I'm not going to concern myself about why it failed before.

Not to change the subject, but I remembered that NekoAmp has limited support for MPEG-2 audio, but the Mpeg.cpp parser generally assumes MPEG-1 audio. I was about to try to correct this, when it struck me that MPEG-2 audio is probably illegal in an MPEG-1 system stream.

Also, it seems that TMPGEnc won't mux MPEG-2 audio, period. dry.gif

--------------------
May the FOURCC be with you...
 
     Top
phaeron
Posted: Dec 13 2002, 08:24 AM


Virtualdub Developer


Group: Administrator
Posts: 7773
Member No.: 61
Joined: 30-July 02



I think XingMPEG Encoder might be able to create an MPEG-1 file with MPEG-2 audio -- it can certainly create them with layer III audio streams. It also had some VBR option that I never tried. Except for a bug in writing GOP timestamps and some quality issues in audio encoding, XingMPEG Encoder wasn't that bad for its time, and inspired VirtualDub's job system. (Their player sucked royally, but that's a different story.) NekoAmp doesn't really support MPEG-2 audio because I only have the MPEG-1 spec; anything in there that claims to work is there because it came from FreeAmp, which was written by people who actually knew what they were doing. tongue.gif
 
    Top
S_O
Posted: Dec 13 2002, 03:53 PM


Vdubmod Alpha Testing Team


Group: Vdubmod Alpha Testing Team
Posts: 102
Member No.: 57
Joined: 25-July 02



QUOTE
One of the problems with MPEG audio is that, unlike MPEG video start codes, audio syncwords are not unique in the stream.
You mean that anywhere else in a mpeg-audio 12 bits set? Whe seraching for the next frame manually to cut the the mp2 in a hexeditor, I search for "FFF", and I never find anything else than frame-headers. It could be possible in not corrupt streams that I doesnīt find an header with that?
QUOTE
1) To resync, the parser must test every single byte to determine if it might represent the beginning of a frame header.
Yes, where is the problem? The next frame probaly wonīt start 10MBs away, maybe 4 or 5KB, it may take some time, but not that much. Does it try to search the next frame or does VDub automatically end the stream then?
QUOTE
2) Technically, the value 2 for emphasis is "reserved," but I've never encountered an MPEG audio stream that used this value. (The test can easily be removed if necessary.)
Of course, for me and you thatīs no problem, but for somebody else? If it wouldnīt benn posted that the copyright-flag changes in the audio, it would maybe have taken hours for me to find that out, I would never came to the idea to check that.
QUOTE
3) I don't know why VirtualDub stalled and "grew in space," but I guess it's fixed now and I'm not going to concern myself about why it failed before.
Because it found audio-frames that werenīt audio-frames. This is definetly fixed know with the better header check.
QUOTE
I was about to try to correct this, when it struck me that MPEG-2 audio is probably illegal in an MPEG-1 system stream.
MPEG-2 Audio in MPEG-1 Stream? Iī donīt thing thatīs allowed.
QUOTE
I think XingMPEG Encoder might be able to create an MPEG-1 file with MPEG-2 audio -- it can certainly create them with layer III audio streams. It also had some VBR option that I never tried. Except for a bug in writing GOP timestamps and some quality issues in audio encoding, XingMPEG Encoder wasn't that bad for its time, and inspired VirtualDub's job system.
I installed the encoder I was able to encode that kind of mpegs, but itīs called "mpx" and neither VDub nor WMP finds the audio, while video is played correctly (the quality of the video is similar to xing-mp3, tmpgenc will make it better at the half bitrate..)
But I thought, there are other mpeg-encoders and I rembered one with not the best quality, but with mayn features: ffmpeg
And yes! It can craete MPEG-1 streams with MPEG-2 Layer 2 audio, which is even playable in WMP. I used this commandline:
ffmpeg -i -b 1000 -f mpeg -ab 128 -ar 22050 -vcodec mpeg1video -acodec mp2
VirtualDub can open the file without any problems, also decode the video, but when trying to play: "MPEG-1 audio decode error: not enough data to decode frame". In the info-box it tells me the audio is 44100Hz and 256Kbit/s, which would be true from the header if the file is MPEG-1.
 
     Top
fccHandler
Posted: Dec 13 2002, 07:52 PM


Administrator n00b


Group: Moderators
Posts: 3961
Member No.: 280
Joined: 13-September 02



@S_O: Great work! However, I don't think the MPEG stream you've made is compliant with the spec, and I don't think Avery (or anyone) should bother trying to add support for such oddities. I only brought up the subject of MPEG-2 audio because it seemed like NekoAmp might support it, and I wondered if Mpeg.cpp should also.

@phaeron: You are lucky to have the MPEG-1 spec (way too expensive for me!) You might also be interested to know that large portions of the MPEG-2 spec are available at Wotsit's site.

(Warning to newbies: those specs are way heavy!) wacko.gif

--------------------
May the FOURCC be with you...
 
     Top
S_O
Posted: Dec 13 2002, 08:52 PM


Vdubmod Alpha Testing Team


Group: Vdubmod Alpha Testing Team
Posts: 102
Member No.: 57
Joined: 25-July 02



QUOTE
@S_O: Great work! However, I don't think the MPEG stream you've made is compliant with the spec, and I don't think Avery (or anyone) should bother trying to add support for such oddities. I only brought up the subject of MPEG-2 audio because it seemed like NekoAmp might support it, and I wondered if Mpeg.cpp should also.
VDub also supports AVI with VBR-MP3 (only reading) and thatīs in my opinion even worse than MPEG-1 stream containing MPEG-2 audio, so if itīs not that difficult to implement, why not? reading is always good.
QUOTE
(Warning to newbies: those specs are way heavy!)
The ATSC A/52 (AC-3) specs are easy to read compared to that. I could easily understand the design of an ac3-header. And the specs are free! I donīt know if they are complete, at least there are 140 pages in the pdf and on the official site.

While writing of ac3 I thought, mpeg-2 with ac3, no prob, but mpeg-1:
ffmpeg -i (infile) -b 1000 -f mpeg -ab 192 -ar 44100 -vcodec mpeg1video -acodec ac3 (outfile)
WMP wonīt play this file, but VirtualDub reads it without any problems! It doesnīt detect audio, but video works perfect!
Thatīs all audio-codecs ffmpeg supports, but whatīs with uncompressed audio? PCM?
ffmpeg -i (infile) -b 1000 -f mpeg -ar 44100 -vcodec mpeg1video -acodec pcm (outfile)
WMP crashes after a half second. VirtualDub reads mpeg, video ok, but sound is detected as "32kHz mixed stereo, 250kbps layer 1" 250KBit/s???
I donīt if itīs allowed to have pcm in mpeg-1 and if ffmpeg mux it correctly, but 250kBit/s is bit strange, because nowhere there is 250kBit/s.
 
     Top
fccHandler
Posted: Dec 13 2002, 10:36 PM


Administrator n00b


Group: Moderators
Posts: 3961
Member No.: 280
Joined: 13-September 02



AC3 and PCM are covered by DVD spec, not MPEG. Unless you're making actual DVD VOBs your MPEGs are still oddities.

QUOTE
VDub also supports AVI with VBR-MP3 (only reading)
No, not really. (Look how many people in these forums are having sync problems because of this!) The AVI format doesn't allow VBR audio, so again you're dealing with oddities.

QUOTE
... if itīs not that difficult to implement, why not?
As phaeron said, NekoAmp may not fully support MPEG-2, so any time spent fixing Mpeg.cpp may be wasted. Certainly I have no intention of rewriting NekoAmp (as if I could!), and I've got better things to do with my time than trying to add support for oddball MPEG streams.

--------------------
May the FOURCC be with you...
 
     Top
S_O
Posted: Dec 13 2002, 11:07 PM


Vdubmod Alpha Testing Team


Group: Vdubmod Alpha Testing Team
Posts: 102
Member No.: 57
Joined: 25-July 02



QUOTE
AC3 and PCM are covered by DVD spec, not MPEG. Unless you're making actual DVD VOBs your MPEGs are still oddities.
So, VOBs on DVDs are not within the mpeg-2 specs?
QUOTE
No, not really. (Look how many people in these forums are having sync problems because of this!) The AVI format doesn't allow VBR audio, so again you're dealing with oddities.
I never used VBR-Audio in avi, I tested it once, it was completly out of sync and so I only used cbr. But Iīve read that VDub has support to read this avis. maybe it was wrong.
QUOTE
As phaeron said, NekoAmp may not fully support MPEG-2, so any time spent fixing Mpeg.cpp may be wasted. Certainly I have no intention of rewriting NekoAmp (as if I could!), and I've got better things to do with my time than trying to add support for oddball MPEG streams.

There is no other application using nekoamp? So nobody knows if it supports or not?
anyway, Iīm trying to learn programming and thatīs a real challenge, a bit more than hello world.
I may take years until I finaly press randomly the right key, but Iīm going to try it. Could someone explain me what that means?
layer = 4 - ((parentPtr->audio_first_header>>9)&3);
audio_first_header is the audio header (32Bit), and because of little endian it looks now:
"IIJJKLMM EEEEFFGH AAAABCCD AAAAAAAA"
instead of
"AAAAAAAA AAAABCCD EEEEFFGH IIJJKLMM" right?
what does ">> 9" mean?
 
     Top
fccHandler
Posted: Dec 13 2002, 11:33 PM


Administrator n00b


Group: Moderators
Posts: 3961
Member No.: 280
Joined: 13-September 02



QUOTE (S_O @ Dec 13 2002, 07:07 PM)
So, VOBs on DVDs are not within the mpeg-2 specs?
No, but they are compliant with the MPEG-2 specs. What that means is that a compliant MPEG-2 decoder will be able to parse the VOB and show you the video stream (and MPEG-compliant audio if present), but it won't have any clue about AC3, PCM, DTS, languages, subtitles, chapters, angles, etc., because the way these are handled in VOBs isn't covered by the MPEG-2 spec, but the DVD spec.

(The MPEGs you were describing earlier aren't compliant with anything!) tongue.gif

QUOTE
what does ">> 9" mean?
"Shift right 9 bits." It's great that you want to learn C++, but honestly, RTFM! rolleyes.gif

--------------------
May the FOURCC be with you...
 
     Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
55 replies since Nov 30 2002, 01:06 PM Track this topic | Email this topic | Print this topic
Pages: (4) « First ... 2 3 [4] 
<< Back to Testing / Bug Reports