Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFMPEG plugin does not support virtual stack slice deletion #1

Open
imagejan opened this issue May 13, 2023 · 1 comment
Open

FFMPEG plugin does not support virtual stack slice deletion #1

imagejan opened this issue May 13, 2023 · 1 comment

Comments

@imagejan
Copy link
Member

See this forum post.

The deleteSlice method likely need to be overridden in this code:

ImageStack stack = new VirtualStack(codecContext.width, codecContext.height, null, null) {
int previousSlice = -1;
long frameDuration = guessFrameDuration();
@Override
public void finalize() {
free();
}
@Override
public int getSize() {
int size = (int)(stream.duration / frameDuration);
if (last >= 0)
size = Math.min(last, size);
if (first > 0)
size -= first;
return size;
}
@Override
public String getSliceLabel(int slice) {
return ""; // maybe calculate the time?
}
public long guessFrameDuration() {
if (avFormat.av_read_frame(formatContext, packet) < 0)
return 1;
long firstPTS = packet.pts;
int frameCount = 5;
for (int i = 0; i < frameCount; previousSlice = i++)
if (avFormat.av_read_frame(formatContext, packet) < 0)
return 1;
return (packet.pts - firstPTS) / frameCount;
}
// TODO: cache two
@Override
public ImageProcessor getProcessor(int slice) {
long time = (first + slice - 1) * frameDuration;
if (time > 0)
time -= frameDuration / 2;
if (stream.start_time != 0x8000000000000000l /* TODO: AVUTIL.AV_NOPTS_VALUE */)
time += stream.start_time;
if (previousSlice != slice - 1)
avFormat.av_seek_frame(formatContext, videoStreamIndex, time,
AVFORMAT.AVSEEK_FLAG_BACKWARD);
for (;;) {
if (avFormat.av_read_frame(formatContext, packet) < 0) {
packet.data = null;
packet.size = 0;
break;
}
if (packet.stream_index != videoStreamIndex)
continue;
if (previousSlice == slice - 1 || packet.pts >= time)
break;
avCodec.avcodec_decode_video2(codecContext, frame, gotPicture, packet);
}
previousSlice = slice;
return readOneFrame(packet);
}
};

Related to the plugin served via the FFMPEG update site, corresponding to this branch:
https://github.com/scifio/scifio-javacv/tree/ffmpeg/plugin/src/main/java/fiji/ffmpeg

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/ffmpeg-plugin-does-not-support-virtual-stack-slice-deletion/81112/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants