forked from forks/ffprobe-wasm
Read video I/P/B frames.
This commit is contained in:
@@ -128,7 +128,7 @@ FileInfoResponse get_file_info() {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
FramesResponse get_frames() {
|
FramesResponse get_frames(int offset) {
|
||||||
av_log_set_level(AV_LOG_QUIET); // No logging output for libav.
|
av_log_set_level(AV_LOG_QUIET); // No logging output for libav.
|
||||||
|
|
||||||
FILE *file = fopen("file", "rb");
|
FILE *file = fopen("file", "rb");
|
||||||
@@ -190,22 +190,39 @@ FramesResponse get_frames() {
|
|||||||
AVPacket *pPacket = av_packet_alloc();
|
AVPacket *pPacket = av_packet_alloc();
|
||||||
AVFrame *pFrame = av_frame_alloc();
|
AVFrame *pFrame = av_frame_alloc();
|
||||||
|
|
||||||
int how_many_packets_to_process = 100;
|
int how_many_packets_to_process = 300;
|
||||||
// av_seek_frame(pFormatContext, 1, 1001*30, AVSEEK_FLAG_ANY);
|
int frame_count = 0;
|
||||||
|
|
||||||
|
// Read video frames.
|
||||||
|
// TODO: Support seek so we don't have to cap at 300 frames.
|
||||||
while (av_read_frame(pFormatContext, pPacket) >= 0) {
|
while (av_read_frame(pFormatContext, pPacket) >= 0) {
|
||||||
|
if (frame_count >= offset) {
|
||||||
if (pPacket->stream_index == video_stream_index) {
|
if (pPacket->stream_index == video_stream_index) {
|
||||||
|
|
||||||
avcodec_send_packet(pCodecContext, pPacket);
|
int response = 0;
|
||||||
avcodec_receive_frame(pCodecContext, pFrame);
|
response = avcodec_send_packet(pCodecContext, pPacket);
|
||||||
|
|
||||||
|
if (response >= 0) {
|
||||||
|
response = avcodec_receive_frame(pCodecContext, pFrame);
|
||||||
|
if (response == AVERROR(EAGAIN) || response == AVERROR_EOF) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Frame f = {
|
Frame f = {
|
||||||
.pict_type = (char) av_get_picture_type_char(pFrame->pict_type),
|
.pict_type = (char) av_get_picture_type_char(pFrame->pict_type),
|
||||||
.frame_number = pCodecContext->frame_number,
|
.frame_number = pCodecContext->frame_number,
|
||||||
.pkt_size = pFrame->pkt_size,
|
.pkt_size = pFrame->pkt_size,
|
||||||
};
|
};
|
||||||
r.frames.push_back(f);
|
r.frames.push_back(f);
|
||||||
}
|
|
||||||
if (--how_many_packets_to_process <= 0) break;
|
if (--how_many_packets_to_process <= 0) break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
frame_count++;
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,9 +251,9 @@ EMSCRIPTEN_BINDINGS(FileInfoResponse_struct) {
|
|||||||
register_vector<Stream>("Stream");
|
register_vector<Stream>("Stream");
|
||||||
|
|
||||||
emscripten::value_object<Frame>("Frame")
|
emscripten::value_object<Frame>("Frame")
|
||||||
.field("frame_type", &Frame::pict_type)
|
.field("pict_type", &Frame::pict_type)
|
||||||
.field("frame_number", &Frame::frame_number)
|
.field("frame_number", &Frame::frame_number)
|
||||||
.field("frame_size", &Frame::pkt_size);
|
.field("pkt_size", &Frame::pkt_size);
|
||||||
register_vector<Frame>("Frame");
|
register_vector<Frame>("Frame");
|
||||||
|
|
||||||
emscripten::value_object<FileInfoResponse>("FileInfoResponse")
|
emscripten::value_object<FileInfoResponse>("FileInfoResponse")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<h4>Frames</h4>
|
<h4>Frames</h4>
|
||||||
<b-table striped hover :items="frames">
|
<b-table striped hover :items="frames">
|
||||||
<template #cell(frame_type)="data">
|
<template #cell(pict_type)="data">
|
||||||
{{ String.fromCharCode(data.value) }}
|
{{ String.fromCharCode(data.value) }}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: 'Frames',
|
name: 'Frames',
|
||||||
props: [''],
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
data: null,
|
data: null,
|
||||||
@@ -21,6 +20,8 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
frames() {
|
frames() {
|
||||||
|
if (!this.data) return [];
|
||||||
|
|
||||||
const s = [];
|
const s = [];
|
||||||
for (let i = 0; i < this.data.frames.size(); i++) {
|
for (let i = 0; i < this.data.frames.size(); i++) {
|
||||||
s.push(this.data.frames.get(i));
|
s.push(this.data.frames.get(i));
|
||||||
@@ -29,7 +30,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.data = window.Module.get_frames();
|
this.data = window.Module.get_frames(0);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user