Discussion:
[Pyparsing] Problem parsing block
Robin Siebler
2015-04-22 03:39:45 UTC
Permalink
I have grammar that works for almost all of my file now. However, there
is still one block I am having trouble with. There are 3 blocks that
are similar: audio track, video track and subtitle track. For some
reason, I can't get the correct grammar for the subtitle block. What am
I doing wrong?


Sample Text

Track ID 1 soun (Audio) Enabled Not self-contained
Format soun/aac 48000 Hz aac FormatFlags: 0x00000000 Bytes/Pkt: 0
Frames/Pkt: 1024 Bytes/Frame: 0 Chan/Frame: 2 Bits/Chan: 0 Reserved:
0x00000000
ChannelLayout: Stereo (L R)
Media Timescale: 48000 Duration: 240640/48000 00:00:05.013
MinSampleDuration: 1024/48000 AdvanceDecodeDelta: 0/48000 00:00:00.000
Num data bytes: 80213 Est. data rate: 127.999 kbps Nominal
framerate: 46.875 fps 235 samples
Track volume: 1
Included in auto selection. Language code <und>
Dimensions: 0 x 0 Track Matrix: 1.0 0.0 0.0 / 0.0 1.0 0.0 / 0.0 0.0 1.0
1 edit: Media start 0/48000 00:00:00.000 dur 3000/600
00:00:05.000 Track start 0/600 00:00:00.000 dur 3000/600
00:00:05.000

Track ID 2 vide (Video) Enabled Not self-contained
Format vide/avc1 dimensions: video 1920 x 1080, presentation: 1920
x 1080 (pixelAspect+clean), cleanAperture: 1920 x 1080 @ 0,0 (originTopLeft)
Media Timescale: 600 Duration: 3003/600 00:00:05.005
MinSampleDuration: 20/600 AdvanceDecodeDelta: 21/600 00:00:00.035
Num data bytes: 6555892 Est. data rate: 10.479 Mbps Nominal
framerate: 29.970 fps 150 samples
Frame Reordering Required
Included in auto selection. Language code <und>
Dimensions: 1920 x 1080 CleanAperture: 1920 x 1080
ProductionAperture: 1920 x 1080 EncodedPixels: 1920 x 1080 Track Matrix:
1.0 0.0 0.0 / 0.0 1.0 0.0 / 0.0 0.0 1.0
1 edit: Media start 0/600 00:00:00.000 dur 3000/600
00:00:05.000 Track start 0/600 00:00:00.000 dur 3000/600
00:00:05.000

Track ID 8 sbtl (Subtitles) Enabled Not self-contained
Format sbtl/tx3g DisplayFlags: 0x00000000 Just: 0 H 0 V Default
Text Box: 0 x 0 @ 0, 0 Default Style: Local fontID 1 Size -1 Color
(RGBA): 1 1 1 1 Font Name: Arial
Media Timescale: 600 Duration: 4800/600 00:00:08.000
MinSampleDuration: 1200/600 AdvanceDecodeDelta: 0/600 00:00:00.000
Num data bytes: 226 Est. data rate: 0.226 kbps Nominal framerate:
0.375 fps 3 samples
Included in auto selection. Language code <und>
Dimensions: 0 x 0 Track Matrix: 1.0 0.0 0.0 / 0.0 1.0 0.0 / 0.0 0.0 1.0
2 edits:
Media start INVALID TIME dur 6000/600 00:00:10.000
Track start 0/600 00:00:00.000 dur 6000/600 00:00:10.000
(EMPTY EDIT)
Media start 1002/600 00:00:01.670 dur 3000/600
00:00:05.000 Track start 6000/600 00:00:10.000 dur 3000/600
00:00:05.000

The full code is in my dropbox -
https://www.dropbox.com/s/s4chl173yi4xyj8/foo.py?dl=0
Here is the relevant code:


# Define Track Info Block
# Audio Block
self.audio_track_info = Group(self.crap + self.track_id +
self.audio_track_format + self.channel_layout +
self.media_timescale +
self.track_data + self.audio_track_volume +
self.included +
self.audio_track_dimensions + OneOrMore(self.edits))

# Subtitle Block
self.subtitle_track_info = Group(self.crap + self.track_id +
self.subtitle_track_format) + \
self.media_timescale +
self.track_data + self.included + \
self.subtitle_track_dimensions +
OneOrMore(self.edits)

# Video Block
self.video_track_info = Group(self.crap + self.track_id +
self.video_track_format + self.media_timescale +
self.track_data + self.frame +
self.included + self.video_track_dimensions +
OneOrMore(self.edits))

self.tracks = OneOrMore(self.audio_track_info |
self.video_track_info | self.subtitle_track_info).setResultsName('tracks')
--
Sent with Postbox <http://www.getpostbox.com>
Loading...