Skip to content

Commit

Permalink
Merge pull request #215 from kaltura/1.0-PLAT-5586-bis
Browse files Browse the repository at this point in the history
1.0 plat 5586 bis
  • Loading branch information
igorshevach authored Jul 7, 2016
2 parents 99d1843 + 3dd84cc commit 8d39226
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
Binary file modified bin/darwin/FormatConverter.node
Binary file not shown.
Binary file modified bin/darwin/FormatConverter.node.debug
Binary file not shown.
Binary file modified bin/linux/FormatConverter.node
Binary file not shown.
Binary file modified bin/linux/FormatConverter.node.debug
Binary file not shown.
31 changes: 19 additions & 12 deletions node_addons/FormatConverter/src/Converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

extern "C"{
#include <libavformat/movenc.h>

#include <bitset>

//invalid suffix on literal C++11 requires...
// thus, some code is replicated
Expand Down Expand Up @@ -136,6 +136,16 @@ namespace converter{
}
}

// surpress av warning on id3 tag stream: start time for stream %d is not set in estimate_timings_from_pts
std::bitset<32> markedStreamsSet;
for( size_t i = 0 ; i < input->nb_streams; i++){
AVStream *in_stream =input->streams[i];
if(in_stream->codec->codec_type == AVMEDIA_TYPE_DATA && in_stream->start_time == AV_NOPTS_VALUE){
in_stream->codec->codec_type = AVMEDIA_TYPE_UNKNOWN;
markedStreamsSet.set(i,true);
}
}

_S(avformat_find_stream_info(*input,NULL));

for( size_t i = 0 ; i < input->nb_streams; i++){
Expand All @@ -144,13 +154,16 @@ namespace converter{
case AVMEDIA_TYPE_VIDEO:
if(in_stream->codec->width == 0 )
return m_bDataPending ? 0 : -1;


break;
case AVMEDIA_TYPE_AUDIO:
if(in_stream->codec->channels == 0 )
return m_bDataPending ? 0 : -1;
break;
case AVMEDIA_TYPE_UNKNOWN:
if(markedStreamsSet[i]){
in_stream->codec->codec_type = AVMEDIA_TYPE_DATA;
}
break;
default:
break;
};
Expand All @@ -171,7 +184,7 @@ namespace converter{

AVStream *in_stream =input->streams[i];

int64_t stmStartTimeMs = av_rescale(getStreamStartTime(in_stream),1000 * in_stream->time_base.num,in_stream->time_base.den);
int64_t stmStartTimeMs = av_rescale(in_stream->start_time,1000 * in_stream->time_base.num,in_stream->time_base.den);

m_minStartDTSMsec = std::min(m_minStartDTSMsec,stmStartTimeMs);

Expand Down Expand Up @@ -207,12 +220,7 @@ namespace converter{
}
}

AVDictionary *opts = nullptr;

_S(av_dict_set(&opts, "use_editlist", "0", 0));
std::unique_ptr<AVDictionary> optsptr(opts);
_S(avformat_write_header(*output, &opts));
optsptr.release();
_S(avformat_write_header(*output, nullptr));

state = PUSHING;

Expand Down Expand Up @@ -408,8 +416,7 @@ namespace converter{
double wrapDTS = ::ceil(dts2msec(1ULL << stream->pts_wrap_bits,stream->time_base));
ExtraTrackInfo &extraInfo = this->m_extraTrackInfo[this->m_streamMapper[i]];
double duration = dts2msec(extraInfo.maxDTS - stream->first_dts,stream->time_base);

mfi.tracks.push_back({ this->m_creationTime + extraInfo.startDTS - m_minStartDTSMsec,
mfi.tracks.push_back({ this->m_creationTime + dts2msec(stream->start_time,stream->time_base) - m_minStartDTSMsec,
extraInfo.startDTS,
wrapDTS,
duration,
Expand Down
5 changes: 3 additions & 2 deletions node_addons/FormatConverter/test/mp4writerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ var fs = require('fs');
var http = require('http');
var Url = require('url');
var _ = require('underscore');
var util = require('util');

var tsFilePath = '/Users/igors/dvr/dvrContentRootPath/1_ceut3fcf/1/media-uf3qmczvm_b1017600_441.ts_saved.ts';//"/Users/igors/dvr/dvrContentRootPath/1_abc123/1/media-ul0o1lom6_w1600782441_670.ts.mp4_saved.ts";//__dirname+'/../resources/media-uixh2a1qh_w1892051821_472.ts';
var tsFilePath = '/Users/igors/Documents/media-uh6rg3op2_8712.ts';//"/Users/igors/dvr/dvrContentRootPath/1_abc123/1/media-ul0o1lom6_w1600782441_670.ts.mp4_saved.ts";//__dirname+'/../resources/media-uixh2a1qh_w1892051821_472.ts';
var httpPath = 'http://localhost/wn/media-uhe4wm3o6_b475136_144354218.ts';
console.log("tsFilePath=",tsFilePath);
var ts2mp4 = new MP4WRITER.MP4WriteStream(tsFilePath + '.mp4', {
Expand Down Expand Up @@ -49,7 +50,7 @@ createPipe( tsFilePath, function(readable) {
console.log("data " + chunk.length);
})
.on('end', function (fileInfo) {
console.log("end");
console.log("end: %j",util.inspect(fileInfo));
})
.on('error', function (err) {
console.log( "%s chunk %s", err, err.chunkName);
Expand Down

0 comments on commit 8d39226

Please sign in to comment.