possible to create mediawriter that discards bytes?

27 views
Skip to first unread message

Peter Thomas

unread,
Dec 3, 2009, 6:14:08 AM12/3/09
to xuggle...@googlegroups.com
Hi,

I'm trying to transcode a live video source and publish to a stream on-the-fly.  I did try to encode directly off a MediaReader after manually setting up the target StreamCoder-s for encoding, but I gave up trying to figure out timestamps, when audio re-sampling is involved.

So right now I am using a IMediaWriter set up like this:

IMediaWriter writer = ToolFactory.makeWriter("dummy.flv");

... and then addVideoStream, addAudioStream, which takes care of transcoding.  I am able to get the packet data I need by listening to the writer + onWritePacket().  So far so good.

Question: with things set up this way [ reader --> resampler --> writer --> packet grabber ] is it possible to have the writer NOT write to a file ?  I found NullProtocolHandler [1] and thought maybe makeWriter("xugglernull:dummy.flv") would work but it didn't.  Any suggestions ?

[1] http://build.xuggle.com/view/Stable/job/xuggler_jdk5_stable/javadoc/java/api/com/xuggle/xuggler/io/NullProtocolHandler.html

Thanks,

Peter.

Art Clarke

unread,
Dec 3, 2009, 9:54:12 AM12/3/09
to xuggle...@googlegroups.com
Currently it's not possible to use the writer without having it write to disk.  Some suggestions though (in decreasing order of my recommendations):

  1. I'm curious as to why the xugglernull approach didn't work.  What was the error?
  2. Don't use the MediaWriter and instead use the IStreamCoders directly to encode (not MediaReader); Timestamps shouldn't change with audio resampling... can you give more detail on the problem you had?
  3. Design a solution to make the MediaWriter be separated into a MediaEncoder and MediaMuxer objects, build it, and submit the patch.  This is a refactor we'd love to do some day, but haven't had time to get to.  Free cookie if you do this.
  4. You could copy the internal class com.xuggle.xuggler.mediatool.MediaWriter (the base class that the ToolFactory returns) and and modify it to change onWritePacket(....) to make it do nothing but call listeners.  I'd do this last as the concrete implementations may change over time, and those classes are package-level internal-only for a reason. Plus by copying that code into your program you will make your program LGPL (as opposed to just using the MediaWriter which means your program isn't LGPL).
Hope that helps,

- Art

--

You received this message because you are subscribed to the Google Groups "xuggler-users" group.
To post to this group, send email to xuggle...@googlegroups.com.
To unsubscribe from this group, send email to xuggler-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xuggler-users?hl=en.



--
http://www.xuggle.com/
xu‧ggle (zŭ' gl) v. To freely encode, decode, and experience audio and video.

Use Xuggle to get the power of FFmpeg in Java.

Peter Thomas

unread,
Dec 3, 2009, 12:48:56 PM12/3/09
to xuggle...@googlegroups.com
Thanks Art,

1. here is the error I get [ xuggle-xuggler 3.3.940 ] when I try to open a writer with URL = "xugglernull:dummy.flv"

Exception in thread "main" java.lang.IllegalArgumentException: could not open: xugglernull:dummy.flv
        at com.xuggle.mediatool.MediaWriter.open(MediaWriter.java:1289)
        at com.xuggle.mediatool.MediaWriter.establishStream(MediaWriter.java:627)
        at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:496)
        at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:444)
        at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:430)
        at com.myco.xuggle.TranscoderFlvReader.<init>(TranscoderFlvReader.java:47)
        at com.myco.xuggle.TranscoderFlvReader.main(TranscoderFlvReader.java:159)

2. Ok, actually I'm starting out experimenting with reading from an H.264 file (not a live source as I said in my first message) and hence using a reader.  So in that case are timestamp handling complications to be expected?  Video timestamps were okay after encode, but for Audio the 2 main problems I faced were a) somehow couldn't derive expected timestamps after re-sampling, tried using timebase, IRational math etc. b) still not familiar with how to handle audio samples when encoding, looks like one has to check if you have enough samples to do an enocde, I could see encode generating zero bytes here and there

3. will take a look

4. will take a look

Thanks !

Peter.

Peter Thomas

unread,
Dec 4, 2009, 2:23:14 AM12/4/09
to xuggle...@googlegroups.com
On Thu, Dec 3, 2009 at 11:18 PM, Peter Thomas <ptrt...@gmail.com> wrote:
Thanks Art,

1. here is the error I get [ xuggle-xuggler 3.3.940 ] when I try to open a writer with URL = "xugglernull:dummy.flv"

Exception in thread "main" java.lang.IllegalArgumentException: could not open: xugglernull:dummy.flv
        at com.xuggle.mediatool.MediaWriter.open(MediaWriter.java:1289)
        at com.xuggle.mediatool.MediaWriter.establishStream(MediaWriter.java:627)
        at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:496)
        at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:444)
        at com.xuggle.mediatool.MediaWriter.addVideoStream(MediaWriter.java:430)
        at com.myco.xuggle.TranscoderFlvReader.<init>(TranscoderFlvReader.java:47)
        at com.myco.xuggle.TranscoderFlvReader.main(TranscoderFlvReader.java:159)

2. Ok, actually I'm starting out experimenting with reading from an H.264 file (not a live source as I said in my first message) and hence using a reader.  So in that case are timestamp handling complications to be expected?  Video timestamps were okay after encode, but for Audio the 2 main problems I faced were a) somehow couldn't derive expected timestamps after re-sampling, tried using timebase, IRational math etc. b) still not familiar with how to handle audio samples when encoding, looks like one has to check if you have enough samples to do an enocde, I could see encode generating zero bytes here and there

I tried again to use IStreamCoders directly and made some progress.  What I was missing earlier was the logic to iterate over the input audio samples based on the value returned from the encodeAudio() method, I got the solution looking at the source of MediaWriter.  I am able to transcode on-the-fly without writing to a file now.  Thanks for your help !
 
Reply all
Reply to author
Forward
0 new messages