3

I am trying to be able to pick out frames (video and metadata) from MPEG, MPEG-TS and MPEG-PS files and live streams (network / UDP / RTP streams). I was looking into using JCODEC to do this and I started off by trying to use the FrameGrab / FrameGrab8Bit classes, and ran into an error that those formats are "temporarily unsupported". I looked into going back some commits to see if I could just use older code, but it looks like both of those files have had those formats "temporarily unsupported" since 2013 / 2015, respectively.

I then tried to plug things back into the FrameGrab8Bit class by putting in the below code...

public static FrameGrab8Bit createFrameGrab8Bit(SeekableByteChannel in) throws IOException, JCodecException {
...
SeekableDemuxerTrack videoTrack = null;
...
case MPEG_PS:
   MPSDemuxer psd = new MPSDemuxer(in);
   List tracks = psd.getVideoTracks();
   videoTrack = (SeekableDemuxerTrack)tracks.get(0);
   break;
case MPEG_TS:
   in.setPosition(0);
   MTSDemuxer tsd = new MTSDemuxer(in);
   ReadableByteChannel program = tsd.getProgram(481);
   MPSDemuxer ptsd = new MPSDemuxer(program);
   List<MPEGDemuxerTrack> tstracks = ptsd.getVideoTracks();
   MPEGDemuxerTrack muxtrack = tstracks.get(0); 
   videoTrack = (SeekableDemuxerTrack)tstracks.get(0);
   break;
...

but I ran into a packet header assertion failure in the MTSDemuxer.java class in the parsePacket function:

public static MTSPacket parsePacket(ByteBuffer buffer) {
   int marker = buffer.get() & 0xff;
   int marker = by & 0xff;
   Assert.assertEquals(0x47, marker);
...

I found that when I reset the position of the seekable byte channel (i.e.: in.setPosition(0)) the code makes it past the assert, but then fails at videoTrack = (SeekableDemuxerTrack)tstracks.get(0) (tstracks.get(0) cannot be converted to a SeekableDemuxerTrack)

Am I waisting my time? Are these formats supported somewhere in the library and I am just not able to find them?

Also, after going around in the code and making quick test applications, it seems like all you get out of the demuxers are video frames. Is there no way to get the metadata frames associated with the video frames?

For reference, I am using the test files from: http://samples.ffmpeg.org/MPEG2/mpegts-klv/

AeroBuffalo
  • 1,126
  • 1
  • 11
  • 31

1 Answers1

3

In case anyone in the future also has this question. I got a response from a developer on the project's GitHub page to this question. Response:

Yeah, MPEG TS is not supported to the extent MP4 is. You can't really seek in TS streams (unless you index the entire stream before hand).

I also asked about how to implement the feature. I thought that it could be done by reworking the MTSDemuxer class to be built off of the SeekableDemuxerTrack so that things would be compatible with the FrameGrab8Bit class, and got the following response:

So it doesn't look like there's much sense to implement TS demuxer on top of SeekableDemuxerTrack. We haven't given much attention to TS demuxer actually, so any input is very welcome.

I think this (building the MTSDemuxer class off of the SeekableDemuxerTrack interface) would work for files (since you have everything already there). But without fully fleshing out that thought, I could not say for sure (it definitely makes sense that this solution would not work for a live MPEG-TS / PS connection).

AeroBuffalo
  • 1,126
  • 1
  • 11
  • 31