/
ADM_videoCopyAudRemover.cpp
123 lines (108 loc) · 3.05 KB
/
ADM_videoCopyAudRemover.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
\file ADM_videoCopy
\brief Wrapper
(c) Mean 2008/GPLv2
*/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "ADM_cpp.h"
using std::string;
#include "ADM_default.h"
#include "ADM_videoCopy.h"
#include "ADM_edit.hxx"
#include "ADM_coreUtils.h"
#include "ADM_vidMisc.h"
#include "prefs.h"
#include "ADM_videoInfoExtractor.h"
#include "ADM_h264_tag.h"
#include "ADM_h265_tag.h"
extern ADM_Composer *video_body; // Fixme!
#if 1
#define aprintf ADM_info
#else
#define aprintf(...) {}
#endif
/**
\fn ADM_videoStreamCopyAudRemover
*/
ADM_videoStreamCopyAudRemover::ADM_videoStreamCopyAudRemover(uint64_t startTime,uint64_t endTime) : ADM_videoStreamCopy(startTime,endTime)
{
ADM_info("AUD Remover created\n");
aviInfo info;
video_body->getVideoInfo(&info);
if(isH264Compatible( info.fcc)) h265=false; //=4;
else if(isH265Compatible( info.fcc)) h265=true; //=5;
else ADM_assert(0);
}
/**
\fn ADM_videoStreamCopyAudRemover
*/
ADM_videoStreamCopyAudRemover::~ADM_videoStreamCopyAudRemover()
{
}
#if 1
#define aprintf ADM_info
#else
#define aprintf(...) {}
#endif
/**
\fn getPacket
*/
bool ADM_videoStreamCopyAudRemover::getPacket(ADMBitstream *out)
{
if(!ADM_videoStreamCopy::getPacket(out))
return false;
//return true;
// Remove AUDs in place
static NALU_descriptor desc[51]; // Only one instance max, no risk of simulatenous access
int size=4;
if(h265) size=5;
int nbNalu=ADM_splitNalu_internal(out->data, out->data+out->len,50,desc,size);
if(!nbNalu) return true;
uint8_t *head=out->data;
for(int i=0;i<nbNalu;i++)
{
bool copy=true;
NALU_descriptor *d=desc+i;
if(h265)
{
if(((d->nalu>>1)&0x3f)==NAL_H265_AUD)
{
copy=false;
}
}else
{
if((d->nalu&0x1f)==NAL_AU_DELIMITER)
{
copy=false;
}
}
if(copy==false)
{
continue;
}
//
if(head==d->start-size) // nothing to do, already at the right place
{
head+=d->size+size;
continue;
}
// Else copy
memmove(head,d->start-size,d->size+size); // also copy NAL header
head+=d->size+size;
}
uint64_t org=out->len;
out->len=(intptr_t)head-(intptr_t)out->data;
if(out->len!=org)
{
aprintf("Saved %d bytes\n",(int)(org-out->len));
}
return true;
}
// EOF