Send Packet Over Network

118 views
Skip to first unread message

ravi

unread,
May 2, 2013, 8:05:56 AM5/2/13
to xuggler-users
Hi,

In my project i need to send Video (audio and video packets) from
server to client machine and reconstruct Video at server. I am using
Sockets programming to send packets from server to client. At server,
for each IPacket i will get the byte array and send it to client,
followed by sending IPacket attributes such as timestamp, keyfame,
duration, position and size.
At client i make sure that i received all the bytes and reconstruct
the packet as follows:

byte[] data = .... (byte array received from server)

IPacket packet = IPacket.make(IBuffer.make(null, data, 0,
data.length));
packet.setTimeStamp(timeStamp);
packet.setDuration(dur);
packet.setPts(timeStamp);
packet.setPosition(position);
timeStamp = timeStamp + dur;
packet.setKeyPacket(isKey);
packet.setTimeBase(IRational.make(1, 25));

When I tried to encode this packet into a container, all the
IVideoPicture have complete attribute set to false. I am decoding
IPackets at client side as follows:

IMediaWriter writer = ToolFactory.makeWriter("output.mp4");
ICodec videocodec =
ICodec.findEncodingCodec(strVideoCodec.getCodecID());
writer.addVideoStream(0, 0, videocodec, IRational.make(25, 1),
704, 576);
writer.addAudioStream(1, 1, 2, 32000);
IVideoPicture videoPicture =
IVideoPicture.make(IPixelFormat.Type.YUV420P, 704, 576);
int offset = 0;
while (offset < packet.getSize()) {
int bytesDecoded = strVideoCodec.decodeVideo(videoPicture, packet,
offset);
if (bytesDecoded < 0) {
System.out.println("Error while decoding video in source");
System.exit(0);
}
offset += bytesDecoded;
if (videoPicture.isComplete()) {
//encode videoPicture
}
}

This code works perfectly for RAW video format, however for
compressed MP4 file the videopicture are not complete, even for KEY
Frames. Please correct me if i am doing something wrong or missing
something.



regards,
Ravi.

ravi

unread,
May 2, 2013, 8:08:57 AM5/2/13
to xuggler-users
Hi,

My apologies, i mean ---> RECONSTRUCT VIDEO AT CLIENT.

Nikita Belenkiy

unread,
May 2, 2013, 8:18:23 AM5/2/13
to xuggle...@googlegroups.com
You should use IContainer or IMediaReader (which wraps IConteiner) to read the contents of the file. There are examples in com.xuggle.mediatool.demos and com.xuggle.xuggler.demos packages

Nikita

On 02.05.2013, at 7:08, ravi <rav...@gmail.com> wrote:

> Hi,
>
> My apologies, i mean ---> RECONSTRUCT VIDEO AT CLIENT.
>
> --
> You received this message because you are subscribed to the Google Groups "xuggler-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to xuggler-user...@googlegroups.com.
> To post to this group, send email to xuggle...@googlegroups.com.
> Visit this group at http://groups.google.com/group/xuggler-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

ravi

unread,
May 2, 2013, 8:31:10 AM5/2/13
to xuggle...@googlegroups.com
Hi,
  
    I have successfully read packets at the sever and also send them to client over network in form of byte array. 
    I am not facing any problem there. I facing problem while reconstructing packets from the received byte array 
    and encoding them into the container at client.

Nikita Belenkiy

unread,
May 2, 2013, 8:36:44 AM5/2/13
to xuggle...@googlegroups.com
According to your client code you are constructing packets from bytes... which is wrong. you should pass input stream to IContainer and use it to construct packets.
something like this.. Not sure what you are trying to achieve in general..

 

ravi

unread,
May 2, 2013, 8:58:56 AM5/2/13
to xuggle...@googlegroups.com
So you mean xuggler does not allow re-constructing packet from byte array??

I am able to do it with raw video files and it works perfectly. I am not able to do it with MP4 files.

Nikita Belenkiy

unread,
May 2, 2013, 9:03:08 AM5/2/13
to xuggle...@googlegroups.com

The is probably not what you need. Container is an entry point to media file. So you should start from it.. Packet is just video or audio data, but there it also metadata..

What are you trying to do?

ravi

unread,
May 2, 2013, 9:13:10 AM5/2/13
to xuggle...@googlegroups.com
What i need is how to transfer video from server to client. Do you know how to do this? 

Nikita Belenkiy

unread,
May 2, 2013, 9:37:30 AM5/2/13
to xuggle...@googlegroups.com
1. If you want to transfer just a FILE, then you don't need xuggler for this.
2. If you want to transfer a video file then see #1 because video files are the same array of bytes as other files
3. If you want to stream video then you need something like RTMP(red5, wowza, nginx+rtmp) server

ravi

unread,
May 2, 2013, 10:00:34 AM5/2/13
to xuggler-users
Thanks Nikita for your replies. Streaming is really a good option.
Still wondering why things are working with raw uncompressed videos
and not with MP4.


On May 2, 6:37 pm, Nikita Belenkiy <jkolo...@gmail.com> wrote:
> 1. If you want to transfer just a FILE, then you don't need xuggler for this.
> 2. If you want to transfer a video file then see #1 because video files are the same array of bytes as other files
> 3. If you want to stream video then you need something like RTMP(red5, wowza, nginx+rtmp) server
>
> >>> For more options, visithttps://groups.google.com/groups/opt_out.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups "xuggler-users" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an email to xuggler-user...@googlegroups.com.
> >> To post to this group, send email to xuggle...@googlegroups.com.
> >> Visit this group athttp://groups.google.com/group/xuggler-users?hl=en.
> >> For more options, visithttps://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages