Search in sources :

Example 1 with VisualMediaMetadata

use of com.helospark.tactview.core.decoder.VisualMediaMetadata in project tactview by helospark.

the class VideoClip method requestFrame.

@Override
public ReadOnlyClipImage requestFrame(RequestFrameParameter frameRequest) {
    VisualMediaMetadata metadataToUse;
    VisualMediaSource mediaSourceToUse;
    if (frameRequest.isLowResolutionPreview() && lowResolutionProxySource.isPresent()) {
        metadataToUse = lowResolutionProxySource.get().mediaMetadata;
        mediaSourceToUse = lowResolutionProxySource.get().source;
    } else {
        metadataToUse = mediaMetadata;
        mediaSourceToUse = backingSource;
    }
    VideoMediaDataRequest request = VideoMediaDataRequest.builder().withFilePath(mediaSourceToUse.backingFile).withHeight(frameRequest.getHeight()).withWidth(frameRequest.getWidth()).withMetadata(metadataToUse).withStart(frameRequest.getPosition()).withUseApproximatePosition(frameRequest.useApproximatePosition()).build();
    ByteBuffer frame = mediaSourceToUse.decoder.readFrames(request).getFrame();
    ClipImage result = new ClipImage(frame, frameRequest.getWidth(), frameRequest.getHeight());
    if (isRotationEnabledAt(frameRequest.getPosition()) && !MathUtil.fuzzyEquals(getRotationFromMetadata(), 0.0)) {
        RotateServiceRequest serviceRequest = RotateServiceRequest.builder().withAngle(getRotationFromMetadata()).withImage(result).withCenterX(0.5).withCenterY(0.5).build();
        ClipImage rotatedImage = rotateService.rotateExactSize(serviceRequest);
        GlobalMemoryManagerAccessor.memoryManager.returnBuffer(result.getBuffer());
        result = rotatedImage;
    }
    return result;
}
Also used : ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) VisualMediaMetadata(com.helospark.tactview.core.decoder.VisualMediaMetadata) RotateServiceRequest(com.helospark.tactview.core.timeline.effect.rotate.RotateServiceRequest) VideoMediaDataRequest(com.helospark.tactview.core.decoder.VideoMediaDataRequest) ByteBuffer(java.nio.ByteBuffer)

Example 2 with VisualMediaMetadata

use of com.helospark.tactview.core.decoder.VisualMediaMetadata in project tactview by helospark.

the class TimelineImagePatternService method createTimelinePattern.

public Image createTimelinePattern(VisualTimelineClip videoClip, int expectedWidth, double visibleStartPosition, double visibleEndPosition) {
    VisualMediaMetadata metadata = videoClip.getMediaMetadata();
    int scaledFrameWidth = (int) ((double) metadata.getWidth() / metadata.getHeight() * PREVIEW_HEIGHT);
    int scaledFrameHeight = PREVIEW_HEIGHT;
    int numberOfFrames = (int) Math.ceil((double) (expectedWidth + BLACK_FILM_TAPE_LINE_WIDTH) / scaledFrameWidth);
    double timejump = (visibleEndPosition - visibleStartPosition) / numberOfFrames;
    BufferedImage result = new BufferedImage(expectedWidth, RECTANGLE_HEIGHT, TYPE_INT_RGB);
    Graphics graphics = result.getGraphics();
    graphics.setColor(Color.BLACK);
    graphics.fillRect(0, 0, expectedWidth, FILM_TAPE_SIZE);
    boolean isDynamicallyGenerated = videoClip instanceof ProceduralVisualClip;
    int index = 0;
    for (double seconds = visibleStartPosition; seconds < visibleEndPosition; seconds += timejump, ++index) {
        TimelinePosition position = TimelinePosition.ofSeconds(seconds);
        int width = isDynamicallyGenerated ? uiProjectRepository.getPreviewWidth() : videoClip.getMediaMetadata().getWidth();
        int height = isDynamicallyGenerated ? uiProjectRepository.getPreviewHeight() : videoClip.getMediaMetadata().getHeight();
        GetFrameRequest frameRequest = GetFrameRequest.builder().withApplyEffects(false).withUseApproximatePosition(true).withExpectedWidth(width).withExpectedHeight(height).withRelativePosition(position).withScale(uiProjectRepository.getScaleFactor()).build();
        ReadOnlyClipImage frame = videoClip.getFrame(frameRequest);
        if (isDynamicallyGenerated) {
            FrameExtendRequest extendFrameRequest = FrameExtendRequest.builder().withClip(videoClip).withFrameResult(frame).withPreviewWidth(uiProjectRepository.getPreviewWidth()).withPreviewHeight(uiProjectRepository.getPreviewHeight()).withScale(uiProjectRepository.getScaleFactor()).withTimelinePosition(position.add(videoClip.getInterval().getStartPosition())).build();
            ClipImage expandedFrame = frameExtender.expandFrame(extendFrameRequest);
            BufferedImage bf = byteBufferToImageConverter.byteBufferToBufferedImage(expandedFrame.getBuffer(), expandedFrame.getWidth(), expandedFrame.getHeight());
            java.awt.Image img = bf.getScaledInstance(scaledFrameWidth, scaledFrameHeight, BufferedImage.SCALE_SMOOTH);
            GlobalMemoryManagerAccessor.memoryManager.returnBuffer(frame.getBuffer());
            GlobalMemoryManagerAccessor.memoryManager.returnBuffer(expandedFrame.getBuffer());
            graphics.drawImage(img, index * (scaledFrameWidth + BLACK_FILM_TAPE_LINE_WIDTH) + BLACK_FILM_TAPE_LINE_WIDTH, FILM_TAPE_SIZE, null);
        } else {
            BufferedImage bf = byteBufferToImageConverter.byteBufferToBufferedImage(frame.getBuffer(), frame.getWidth(), frame.getHeight());
            java.awt.Image img = bf.getScaledInstance(scaledFrameWidth, scaledFrameHeight, BufferedImage.SCALE_SMOOTH);
            graphics.drawImage(img, index * (scaledFrameWidth + BLACK_FILM_TAPE_LINE_WIDTH) + BLACK_FILM_TAPE_LINE_WIDTH, FILM_TAPE_SIZE, null);
            GlobalMemoryManagerAccessor.memoryManager.returnBuffer(frame.getBuffer());
        }
    }
    dragFilmEffect(expectedWidth, graphics);
    return byteBufferToJavaFxImageConverter.convertToJavafxImage(result);
}
Also used : GetFrameRequest(com.helospark.tactview.core.timeline.GetFrameRequest) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) ClipImage(com.helospark.tactview.core.timeline.image.ClipImage) BufferedImage(java.awt.image.BufferedImage) Graphics(java.awt.Graphics) ProceduralVisualClip(com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) FrameExtendRequest(com.helospark.tactview.core.timeline.render.FrameExtender.FrameExtendRequest) VisualMediaMetadata(com.helospark.tactview.core.decoder.VisualMediaMetadata) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition)

Example 3 with VisualMediaMetadata

use of com.helospark.tactview.core.decoder.VisualMediaMetadata in project tactview by helospark.

the class GifMediaDecoder method readFrames.

@Override
public MediaDataResponse readFrames(VideoMediaDataRequest request) {
    GifDecoder gifDecoder = gifFileReader.readFile(request.getFile().getAbsolutePath());
    VisualMediaMetadata metadata = request.getMetadata();
    int loopCount = ((GifVideoMetadata) metadata).getLoopCount();
    int positionInMilliseconds;
    BigDecimal startSeconds = request.getStart().getSeconds();
    BigDecimal lengthSeconds = metadata.getLength().getSeconds();
    if (loopCount == INFINITE_LOOP) {
        positionInMilliseconds = getWrappedMilliseconds(startSeconds, lengthSeconds);
    } else {
        int actualLoopCount = startSeconds.divide(lengthSeconds, 1, RoundingMode.FLOOR).intValue();
        if (actualLoopCount < loopCount) {
            positionInMilliseconds = getWrappedMilliseconds(startSeconds, lengthSeconds);
        } else {
            positionInMilliseconds = startSeconds.multiply(BigDecimal.valueOf(1000)).intValue();
        }
    }
    int currentFramePosition = 0;
    for (int i = 0; i < gifDecoder.getFrameCount(); ++i) {
        int newPosition = currentFramePosition + gifDecoder.getDelay(i);
        if (positionInMilliseconds >= currentFramePosition && positionInMilliseconds < newPosition) {
            return getImageAt(gifDecoder, i, request);
        }
        currentFramePosition = newPosition;
    }
    return getImageAt(gifDecoder, gifDecoder.getFrameCount() - 1, request);
}
Also used : GifDecoder(com.madgag.gif.fmsware.GifDecoder) VisualMediaMetadata(com.helospark.tactview.core.decoder.VisualMediaMetadata) BigDecimal(java.math.BigDecimal)

Example 4 with VisualMediaMetadata

use of com.helospark.tactview.core.decoder.VisualMediaMetadata in project tactview by helospark.

the class ClipAddedListener method initializeProjectOnFirstVideoClipAdded.

private void initializeProjectOnFirstVideoClipAdded(TimelineClip clip) {
    if (!projectRepository.isVideoInitialized() && clip instanceof VisualTimelineClip) {
        VisualTimelineClip visualClip = (VisualTimelineClip) clip;
        VisualMediaMetadata metadata = visualClip.getMediaMetadata();
        int width = metadata.getWidth();
        int height = metadata.getHeight();
        if (metadata instanceof VideoMetadata && visualClip instanceof VideoClip) {
            double rotation = ((VideoMetadata) metadata).getRotation();
            if (MathUtil.fuzzyEquals(Math.abs(rotation), 90.0) && ((VideoClip) visualClip).isRotationEnabledAt(TimelinePosition.ofZero())) {
                int tmp = width;
                width = height;
                height = tmp;
            }
        }
        BigDecimal fps = metadata instanceof VideoMetadata ? new BigDecimal(((VideoMetadata) metadata).getFps()) : new BigDecimal("30");
        projectSizeInitializer.initializeProjectSize(width, height, fps);
    }
    if (!projectRepository.isAudioInitialized() && clip instanceof AudibleTimelineClip) {
        AudibleTimelineClip audioClip = (AudibleTimelineClip) clip;
        int sampleRate = audioClip.getMediaMetadata().getSampleRate();
        int bytesPerSample = audioClip.getMediaMetadata().getBytesPerSample();
        int numberOfChannels = audioClip.getMediaMetadata().getChannels();
        projectRepository.initializeAudio(sampleRate, bytesPerSample, numberOfChannels);
    }
}
Also used : VideoClip(com.helospark.tactview.core.timeline.VideoClip) VisualMediaMetadata(com.helospark.tactview.core.decoder.VisualMediaMetadata) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) VideoMetadata(com.helospark.tactview.core.decoder.VideoMetadata) BigDecimal(java.math.BigDecimal) AudibleTimelineClip(com.helospark.tactview.core.timeline.AudibleTimelineClip)

Example 5 with VisualMediaMetadata

use of com.helospark.tactview.core.decoder.VisualMediaMetadata in project tactview by helospark.

the class AddScaleCommand method execute.

@Override
public void execute() {
    VisualTimelineClip clip = (VisualTimelineClip) timelineManager.findClipById(clipId).orElseThrow();
    VisualMediaMetadata metadata = clip.getMediaMetadata();
    double scaleX = (double) projectRepository.getWidth() / metadata.getWidth();
    double scaleY = (double) projectRepository.getHeight() / metadata.getHeight();
    CreateEffectRequest createEffectRequest = new CreateEffectRequest(TimelinePosition.ofZero(), scaleEffectFactory.getEffectId(), TimelineClipType.VIDEO, clip.getInterval());
    addedEffect = (ScaleEffect) effectFactoryChain.createEffect(createEffectRequest);
    addedEffect.setScale(scaleX, scaleY);
    // due to relative position
    addedEffect.setInterval(clip.getInterval().butMoveStartPostionTo(TimelinePosition.ofZero()));
    timelineManager.addEffectForClip(clip, addedEffect);
}
Also used : VisualMediaMetadata(com.helospark.tactview.core.decoder.VisualMediaMetadata) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) CreateEffectRequest(com.helospark.tactview.core.timeline.effect.CreateEffectRequest)

Aggregations

VisualMediaMetadata (com.helospark.tactview.core.decoder.VisualMediaMetadata)6 VideoMetadata (com.helospark.tactview.core.decoder.VideoMetadata)2 VisualTimelineClip (com.helospark.tactview.core.timeline.VisualTimelineClip)2 ClipImage (com.helospark.tactview.core.timeline.image.ClipImage)2 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)2 BigDecimal (java.math.BigDecimal)2 VideoMediaDataRequest (com.helospark.tactview.core.decoder.VideoMediaDataRequest)1 AudibleTimelineClip (com.helospark.tactview.core.timeline.AudibleTimelineClip)1 GetFrameRequest (com.helospark.tactview.core.timeline.GetFrameRequest)1 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)1 VideoClip (com.helospark.tactview.core.timeline.VideoClip)1 CreateEffectRequest (com.helospark.tactview.core.timeline.effect.CreateEffectRequest)1 RotateServiceRequest (com.helospark.tactview.core.timeline.effect.rotate.RotateServiceRequest)1 ProceduralVisualClip (com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip)1 FrameExtendRequest (com.helospark.tactview.core.timeline.render.FrameExtender.FrameExtendRequest)1 GifDecoder (com.madgag.gif.fmsware.GifDecoder)1 Graphics (java.awt.Graphics)1 BufferedImage (java.awt.image.BufferedImage)1 ByteBuffer (java.nio.ByteBuffer)1 Label (javafx.scene.control.Label)1