Skip to content
Permalink
Browse files

[muxer/ffmpeg] Try to fill in the missing timestamps, AAC/HE will not…

… work well
  • Loading branch information...
mean authored and eumagga0x2a committed Apr 11, 2017
1 parent 726a624 commit 41564514d90d08e8ab94ee3d9fd936215eb8557e
Showing with 21 additions and 1 deletion.
  1. +21 −1 avidemux_core/ADM_coreMuxer/src/ADM_coreMuxerFfmpeg.cpp
@@ -25,6 +25,7 @@


extern "C" { extern "C" {
#include "libavformat/url.h" #include "libavformat/url.h"
#include "ADM_audioClock.h"
} }


#if 1 #if 1
@@ -391,16 +392,28 @@ bool muxerFFmpeg::initAudio(uint32_t nbAudioTrack,ADM_audioStream **audio)
return true; return true;
} }
#define AUDIO_BUFFER_SIZE 48000*6*sizeof(float) #define AUDIO_BUFFER_SIZE 48000*6*sizeof(float)
/**
* \class MuxAudioPacket
*/
class MuxAudioPacket class MuxAudioPacket
{ {
public: public:
MuxAudioPacket() {eof=false;dts=ADM_NO_PTS;present=false;size=0;} MuxAudioPacket() {eof=false;dts=ADM_NO_PTS;present=false;size=0;clock=NULL;}
~MuxAudioPacket()
{
if(clock)
{
delete clock;
clock=NULL;
}
}
uint8_t buffer[AUDIO_BUFFER_SIZE]; uint8_t buffer[AUDIO_BUFFER_SIZE];
uint32_t size; uint32_t size;
bool eof; bool eof;
bool present; bool present;
uint64_t dts; uint64_t dts;
uint32_t samples; uint32_t samples;
audioClock *clock;
}; };


/** /**
@@ -434,6 +447,8 @@ bool muxerFFmpeg::saveLoop(const char *title)
initUI(QT_TRANSLATE_NOOP("adm","Saving")); initUI(QT_TRANSLATE_NOOP("adm","Saving"));
encoding->setContainer(getContainerName()); encoding->setContainer(getContainerName());
MuxAudioPacket *audioPackets=new MuxAudioPacket[nbAStreams]; MuxAudioPacket *audioPackets=new MuxAudioPacket[nbAStreams];
for(int i=0;i<nbAStreams;i++) // ugly...
audioPackets[i].clock=new audioClock(aStreams[i]->getInfo()->frequency);
ADMBitstream out(bufSize); ADMBitstream out(bufSize);
out.data=buffer; out.data=buffer;


@@ -535,6 +550,11 @@ bool muxerFFmpeg::saveLoop(const char *title)
AVPacket pkt; AVPacket pkt;
uint64_t rescaledDts; uint64_t rescaledDts;
rescaledDts=audioTrack->dts; rescaledDts=audioTrack->dts;
if(rescaledDts==ADM_NO_PTS)
rescaledDts=audioTrack->clock->getTimeUs(); // we assume the 1st one has a PTS/DTS..., can we ?
else
audioTrack->clock->setTimeUs(rescaledDts);
audioTrack->clock->advanceBySample(audioTrack->samples);
encoding->pushAudioFrame(audioTrack->size); encoding->pushAudioFrame(audioTrack->size);
muxerRescaleAudioTime(audio,&rescaledDts,a->getInfo()->frequency); muxerRescaleAudioTime(audio,&rescaledDts,a->getInfo()->frequency);
//printf("[FF] A: Video frame %d, audio Dts :%"PRIu64" size :%"PRIu32" nbSample : %"PRIu32" rescaled:%"PRIu64"\n", //printf("[FF] A: Video frame %d, audio Dts :%"PRIu64" size :%"PRIu32" nbSample : %"PRIu32" rescaled:%"PRIu64"\n",

0 comments on commit 4156451

Please sign in to comment.
You can’t perform that action at this time.