[Libav-user] Transcoding Decoding_Encoding to MP4/h264 - asynchron tracks

Silver marco_sie at web.de
Tue Feb 11 14:11:05 CET 2014


Hello,

i'm new to AvCodec Libs and .. to this Mailist System, pls be gentle :)

Where to start... first i have a lot of Questions .... and i could fill a
Book with it (with no answers of course).
But anyway.. 

I developed a transcoder with libav... for Mac/Windows, lets Focus for Mac
for now.
It works and i'm happy i got so far already... but i faceing a Problem with
async Video and Audio Tracks... 
If the Clip is really long then it gets really bad, People who Speaking
(Mouth movement) doesn't match with the words. (I saw Drangers tutorial...
but it was for video playing?)

I think it has to do something with the time_base,pts,dts,....   and because
i'm new i don't get it at all.
And i read a lot about dropped Frames... in ffmpeg.c there get frames
duplicated.. 
Is there some A-Z or Step by Step Guide out there.. if i would understand
this fully i would create one... because i'm really good in forgetting...

Because the whole transcoding Code is long... i just write pseudo code, that
you can get a glimpse...

Transcoding Target: xxx Format to mp4 - h264/AAC ( for iPad,Web) 

-----
*Pseudecode My Transcoding*

open_prepare_streams_in();
open_prepare_streams_out();
settings_for_encoder_h264();

while(1)
{
   if (av_read_frame() == ok)
   {

       if (audio_stream == ok)
           if (decode_audio == ok)
              encode_audio
       else if (video_stream == ok)
           if (decode_video == ok)
             encode_video
   }
}
catch_delayed_video_frames
catch_delayed_audio_frames

----
Before Encoding i set the pts to my frame counter(i saw it some examples)

*for video:*
newScaledFrame->pts = decodedVFrameCounter; //decodedVideoFrame, which get
scaled
decodedVFrameCounter++;

*for audio:*
newSampledFrame->pts = decodedAFrameCounter; //decodedAudioFrame, which get
sampled
decodedAFrameCounter++;


The Code for PTS/DTS after Encoding (for both audio and video):

if (encoderPacketV.pts != AV_NOPTS_VALUE)
    encoderPacketV.pts = av_rescale_q(encoderPacketV.pts,
codecCtxOut->time_base,video_st->time_base);
if (encoderPacketV.dts != AV_NOPTS_VALUE)
    encoderPacketV.dts = av_rescale_q(encoderPacketV.dts,
codecCtxOut->time_base,video_st->time_base);
if (encoderPacketV.duration > 0)
   encoderPacketV.duration = av_rescale_q(encoderPacketV.duration,
codecCtxOut->time_base, video_st->time_base);

---------

I already watched in ffmpeg.c and handbrake Code... and what i see that they
do a lot more about pts/dts and i confused me :(

--

There are still some other things.. like 2 frames missing at the start
(bytes but no got_picts/finishedFrame from video_decode2). 
But let this aside.. the major thing is the async tracks of the video file.

If you require more information let see how i can provide it.
I hope somebody can help me.



--
View this message in context: http://libav-users.943685.n4.nabble.com/Transcoding-Decoding-Encoding-to-MP4-h264-asynchron-tracks-tp4659230.html
Sent from the libav-users mailing list archive at Nabble.com.


More information about the Libav-user mailing list