feat(mm2): smear frames
This commit is contained in:
parent
bb29832f71
commit
2c045d4c73
@ -1,3 +1,82 @@
|
||||
#include <avcpp/av.h>
|
||||
#include <avcpp/avtime.h>
|
||||
#include <avcpp/format.h>
|
||||
#include <avcpp/formatcontext.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <vector>
|
||||
|
||||
int main() { spdlog::info("MM2"); }
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc < 4) {
|
||||
spdlog::error("Usage: {} <input-file> <output-file> <smear-frames>",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *input_file = argv[1];
|
||||
const char *output_file = argv[2];
|
||||
int smear_frames = atoi(argv[3]);
|
||||
|
||||
av::init();
|
||||
|
||||
av::FormatContext ictx;
|
||||
av::FormatContext octx;
|
||||
ictx.openInput(input_file);
|
||||
ictx.findStreamInfo();
|
||||
|
||||
std::vector<off_t> stream_map(ictx.streamsCount());
|
||||
|
||||
off_t oix = 0;
|
||||
for (size_t i = 0; i < stream_map.size(); i++) {
|
||||
auto istream = ictx.stream(i);
|
||||
|
||||
if (istream.codecParameters().codecType() != AVMEDIA_TYPE_AUDIO ||
|
||||
istream.codecParameters().codecType() != AVMEDIA_TYPE_VIDEO ||
|
||||
istream.codecParameters().codecType() != AVMEDIA_TYPE_SUBTITLE) {
|
||||
stream_map[i] = -1;
|
||||
}
|
||||
|
||||
auto ostream = octx.addStream();
|
||||
ostream.setCodecParameters(istream.codecParameters());
|
||||
ostream.codecParameters().codecTag(0);
|
||||
stream_map[i] = oix++;
|
||||
}
|
||||
|
||||
octx.openOutput(output_file);
|
||||
octx.writeHeader();
|
||||
|
||||
av::Packet packet_buffer;
|
||||
|
||||
for (;;) {
|
||||
auto pkt = ictx.readPacket();
|
||||
|
||||
if (pkt.isNull()) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto istream = ictx.stream(pkt.streamIndex());
|
||||
|
||||
if (pkt.streamIndex() >= stream_map.size() ||
|
||||
stream_map[pkt.streamIndex()] < 0 || pkt.isKeyPacket()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pkt.setStreamIndex(stream_map[pkt.streamIndex()]);
|
||||
|
||||
if (auto ts = pkt.pts().timestamp(); ts % smear_frames == 0) {
|
||||
packet_buffer = pkt;
|
||||
} else {
|
||||
auto dts = pkt.dts();
|
||||
auto pts = pkt.pts();
|
||||
auto dur = pkt.duration();
|
||||
pkt = packet_buffer;
|
||||
pkt.setDts(dts);
|
||||
pkt.setPts(pts);
|
||||
pkt.setDuration(dur);
|
||||
}
|
||||
|
||||
octx.writePacket(pkt);
|
||||
}
|
||||
|
||||
octx.writeTrailer();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user