Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1032239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:03:00+00:00 2026-05-16T14:03:00+00:00

I’m trying to find ways to stream a live video generated in a Java

  • 0

I’m trying to find ways to stream a live video generated in a Java application. The application needs to take screenshots of itself and encode these into a video stream and publish the stream.

So far I have been using Xuggler (a Java library on top of FFMPEG) to encode the screenshots into a video file. This works great. Xuggler claims to be able to transmit live video via RTMP but I have not found any documentation on how to do this programmatically.

  1. Does anyone know how to stream RTMP video programmatically from Xuggler?
  2. Does anyone have a suggestion on other libraries I could use to achieve the same results? I’d prefer to stream the video in MPEG2 over RTP.

I did find someone else asking a very similar question on the Xuggler forums here with no response.

I have looked into JMF and it is not an option for other reasons.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:03:00+00:00Added an answer on May 16, 2026 at 2:03 pm

    Honestly don’t waste your time with JMF, you can consider that offering dead. Here is how you would do screen shotting to an rtmp stream using h.264 (thanks to tyreus@gmail.com for the example). If the code doesn’t show up here’s pastebin for it: http://pastebin.com/sJHwj0nW

    import com.xuggle.xuggler.Configuration;
    import com.xuggle.xuggler.ICodec;
    import com.xuggle.xuggler.IContainer;
    import com.xuggle.xuggler.IContainerFormat;
    import com.xuggle.xuggler.IPacket;
    import com.xuggle.xuggler.IPixelFormat;
    import com.xuggle.xuggler.IRational;
    import com.xuggle.xuggler.IStream;
    import com.xuggle.xuggler.IStreamCoder;
    import com.xuggle.xuggler.IVideoPicture;
    import com.xuggle.xuggler.video.ConverterFactory;
    import com.xuggle.xuggler.video.IConverter;
    import java.awt.AWTException;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;
    
    public class XugglerRtmpReferenceImpl {
    
       private static String url = "rtmp://your.test.server/screen/";
       private static String fileName = "test/teststream";
       private static int framesToEncode = 60;
       private static int x = 0;
       private static int y = 0;
       private static int height = 480;
       private static int width = 640;
    
       public static void main(String[] args) {
           IContainer container = IContainer.make();
           IContainerFormat containerFormat_live = IContainerFormat.make();
           containerFormat_live.setOutputFormat("flv", url + fileName, null);
           container.setInputBufferLength(0);
           int retVal = container.open(url + fileName, IContainer.Type.WRITE, containerFormat_live);
           if (retVal < 0) {
               System.err.println("Could not open output container for live stream");
               System.exit(1);
           }
           IStream stream = container.addNewStream(0);
           IStreamCoder coder = stream.getStreamCoder();
           ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_H264);
           coder.setNumPicturesInGroupOfPictures(5);
           coder.setCodec(codec);
           coder.setBitRate(200000);
           coder.setPixelType(IPixelFormat.Type.YUV420P);
           coder.setHeight(height);
           coder.setWidth(width);
           System.out.println("[ENCODER] video size is " + width + "x" + height);
           coder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
           coder.setGlobalQuality(0);
           IRational frameRate = IRational.make(5, 1);
           coder.setFrameRate(frameRate);
           coder.setTimeBase(IRational.make(frameRate.getDenominator(), frameRate.getNumerator()));
           Properties props = new Properties();
           InputStream is = XugglerRtmpReferenceImpl.class.getResourceAsStream("/libx264-normal.ffpreset");
           try {
               props.load(is);
           } catch (IOException e) {
               System.err.println("You need the libx264-normal.ffpreset file from the Xuggle distribution in your classpath.");
               System.exit(1);
           }
           Configuration.configure(props, coder);
           coder.open();
           container.writeHeader();
           long firstTimeStamp = System.currentTimeMillis();
           long lastTimeStamp = -1;
           int i = 0;
           try {
               Robot robot = new Robot();
               while (i < framesToEncode) {
                   //long iterationStartTime = System.currentTimeMillis();
                   long now = System.currentTimeMillis();
                   //grab the screenshot
                   BufferedImage image = robot.createScreenCapture(new Rectangle(x, y, width, height));
                   //convert it for Xuggler
                   BufferedImage currentScreenshot = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
                   currentScreenshot.getGraphics().drawImage(image, 0, 0, null);
                   //start the encoding process
                   IPacket packet = IPacket.make();
                   IConverter converter = ConverterFactory.createConverter(currentScreenshot, IPixelFormat.Type.YUV420P);
                   long timeStamp = (now - firstTimeStamp) * 1000; 
                   IVideoPicture outFrame = converter.toPicture(currentScreenshot, timeStamp);
                   if (i == 0) {
                       //make first frame keyframe
                       outFrame.setKeyFrame(true);
                   }
                   outFrame.setQuality(0);
                   coder.encodeVideo(packet, outFrame, 0);
                   outFrame.delete();
                   if (packet.isComplete()) {
                       container.writePacket(packet);
                       System.out.println("[ENCODER] writing packet of size " + packet.getSize() + " for elapsed time " + ((timeStamp - lastTimeStamp) / 1000));
                       lastTimeStamp = timeStamp;
                   }
                   System.out.println("[ENCODER] encoded image " + i + " in " + (System.currentTimeMillis() - now));
                   i++;
                   try {
                       Thread.sleep(Math.max((long) (1000 / frameRate.getDouble()) - (System.currentTimeMillis() - now), 0));
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }
               }
           } catch (AWTException e) {
               e.printStackTrace();
           }
           container.writeTrailer();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.