[FFmpeg-devel] Coding question about mpeg-ts

sumu27 at sina.com sumu27
Sun Apr 5 03:55:13 CEST 2009


Hi all,

I am trying to write a piece of code that can input a
mpeg (program stream) file and stream out a mpeg-ts (transport stream)
over udp. There is no transcoding involved but just reformat from
program stream to transport stream.
What I am doing is like a simple
version of ffmpeg.c code with 'copy-stream' enabled. I use vlc player
to receive the stream and replay.
But my code has some problems:
(1)
The original code will read the mpeg file and send all packets out very
fast. For example, the mpeg file is 2 minutes, the code will read/send
it in 15 seconds. Definitely, this is not expected and the vlc player
runs out of its recv buffer.
(2) So, I add a delay between sending
packets. Something like the "rate_emu" enabled in ffmepg.c. But I did
this with some changes. I only delay on audio stream, instead of both
audio and video. This is because, when I delay on both streams, this
would make a 2 minutes file to be streamed in 4 minutes. This "double
time effect" is not correct and unwanted. Thus, my delay code is like
the following:

    if(ist->st->codec->codec_type == CODEC_TYPE_AUDIO){
        int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE);
        int64_t now = av_gettime() - ist->start;
        int64_t diff = (pts - now)/1000;
        if (diff>0){
            Sleep(diff); //sleep in mini-seconds
        }
    }

(3)
This time, the stream is finished in the expected time (e.g. 120
seconds mpeg file will finish in 120 seconds). But the problem is that
on the vlc player I can hear/see not so fluent voice/video. There is
jitterred replay. But when I enable "allow time-shifting" on vlc
player, it becomes perfect.

I believe my streaming code is not
writing in perfect ways, so that the vlc player cannot work well
without "time shifting". Could you give me some suggestions on the
possible reasons? Thank you.

Regards,

sumu 


-------------------------------------------------------------------
???????????????????(http://space.sina.com.cn/ )



More information about the ffmpeg-devel mailing list