Search in sources :

Example 6 with VisualTimelineClip

use of com.helospark.tactview.core.timeline.VisualTimelineClip in project tactview by helospark.

the class CommonEffectTest method testThatEffectCanBeSavedAndRestored.

@Test
public void testThatEffectCanBeSavedAndRestored() throws IOException {
    LightDiContext lightDi = IntegrationTestUtil.startContext();
    List<EffectFactory> effectFactories = lightDi.getListOfBeans(EffectFactory.class);
    FakeUi fakeUi = lightDi.getBean(FakeUi.class);
    VisualTimelineClip clip = (VisualTimelineClip) fakeUi.dragProceduralClipToFirstChannel("singlecolor", TimelinePosition.ofZero());
    for (var effectFactory : effectFactories) {
        StatelessEffect effect = effectFactory.createEffect(new CreateEffectRequest(TimelinePosition.ofZero(), effectFactory.getEffectId(), TimelineClipType.VIDEO, clip.getInterval()));
        if (!(effect instanceof StatelessVideoEffect)) {
            continue;
        }
        if (!(effect instanceof StatelessVideoEffect) || effectFactory.getEffectId().equals("lensdistort")) /**
         * trello.201, check why this occasionally fails
         */
        {
            continue;
        }
        ReadOnlyClipImage originalFrame = getFrame((StatelessVideoEffect) effect, clip);
        SaveMetadata saveMetadata = new SaveMetadata(false);
        Object savedEffect = effect.generateSavedContent(saveMetadata);
        String saveData = createObjectMapper(saveMetadata).writeValueAsString(savedEffect);
        JsonNode readData = StaticObjectMapper.objectMapper.readTree(saveData);
        StatelessEffect restoredEffect = effectFactory.restoreEffect(readData, new LoadMetadata("filepath", StaticObjectMapper.objectMapper, lightDi));
        ReadOnlyClipImage clonedFrame = getFrame((StatelessVideoEffect) restoredEffect, clip);
        IntegrationTestUtil.assertFrameEquals(originalFrame, clonedFrame, effectFactory.getEffectId() + " is generating different image after save and restore");
        freeFrame(originalFrame);
        freeFrame(clonedFrame);
    }
    lightDi.close();
}
Also used : LightDiContext(com.helospark.lightdi.LightDiContext) StatelessEffect(com.helospark.tactview.core.timeline.StatelessEffect) LoadMetadata(com.helospark.tactview.core.save.LoadMetadata) JsonNode(com.fasterxml.jackson.databind.JsonNode) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory) SaveMetadata(com.helospark.tactview.core.save.SaveMetadata) FakeUi(com.helospark.tactview.core.it.util.ui.FakeUi) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) StatelessVideoEffect(com.helospark.tactview.core.timeline.StatelessVideoEffect) CreateEffectRequest(com.helospark.tactview.core.timeline.effect.CreateEffectRequest) Test(org.junit.jupiter.api.Test)

Example 7 with VisualTimelineClip

use of com.helospark.tactview.core.timeline.VisualTimelineClip in project tactview by helospark.

the class StandardGraphElementFactoryConfiguration method fileClipGraphElementFactory.

@Bean
public GraphElementFactory fileClipGraphElementFactory(List<ClipFactory> clipFactories, ClipFactoryChain clipFactoryChain, MessagingService messagingService) {
    return StandardGraphElementFactory.builder().withId("file").withDoesSupport(uri -> uri.startsWith("file://")).withName("File").withCategory(GraphCategory.INPUT).withNeedsInputParam(true).withCreator(graphRequest -> {
        AddClipRequest request = AddClipRequest.builder().withAddClipRequestMetadataKey(Map.of()).withPosition(TimelinePosition.ofZero()).withFilePath(graphRequest.uri.replaceFirst("file://", "")).build();
        VisualTimelineClip clip = (VisualTimelineClip) clipFactoryChain.createClips(request).get(0);
        clip.setInterval(INTERVAL);
        messagingService.sendAsyncMessage(new ClipDescriptorsAdded(clip.getId(), clip.getDescriptors(), clip));
        return new VisualTimelineClipElement(clip);
    }).withRestorer((node, metadata) -> {
        node.get("creatorFactoryId").asText();
        return new VisualTimelineClipElement(node, metadata, (VisualTimelineClip) clipFactoryChain.restoreClip(node.get("clip"), metadata));
    }).build();
}
Also used : TimelineClipType(com.helospark.tactview.core.timeline.TimelineClipType) TactviewPlatform(com.helospark.tactview.core.util.conditional.TactviewPlatform) ConditionalOnPlatform(com.helospark.tactview.core.util.conditional.ConditionalOnPlatform) ClipFactory(com.helospark.tactview.core.timeline.ClipFactory) StatelessVideoEffect(com.helospark.tactview.core.timeline.StatelessVideoEffect) EffectParametersRepository(com.helospark.tactview.core.timeline.effect.EffectParametersRepository) Configuration(com.helospark.lightdi.annotation.Configuration) CreateEffectRequest(com.helospark.tactview.core.timeline.effect.CreateEffectRequest) KeyframeSuccesfullyAddedMessage(com.helospark.tactview.core.timeline.message.KeyframeSuccesfullyAddedMessage) ConditionalOnProperty(com.helospark.lightdi.annotation.ConditionalOnProperty) AddClipRequest(com.helospark.tactview.core.timeline.AddClipRequest) EffectFactory(com.helospark.tactview.core.timeline.effect.EffectFactory) GraphProvider(com.helospark.tactview.core.timeline.effect.interpolation.provider.GraphProvider) Map(java.util.Map) Bean(com.helospark.lightdi.annotation.Bean) CameraOutputToV4L2LoopbackElement(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.realtime.CameraOutputToV4L2LoopbackElement) ProceduralClipFactoryChainItem(com.helospark.tactview.core.timeline.proceduralclip.ProceduralClipFactoryChainItem) GraphCategory(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.GraphElementFactory.GraphCategory) TimelinePosition(com.helospark.tactview.core.timeline.TimelinePosition) OpencvL4V2LoopbackImplementation(com.helospark.tactview.core.timeline.effect.interpolation.graph.domain.types.realtime.camera.OpencvL4V2LoopbackImplementation) ClipDescriptorsAdded(com.helospark.tactview.core.timeline.message.ClipDescriptorsAdded) Collectors(java.util.stream.Collectors) TimelineLength(com.helospark.tactview.core.timeline.TimelineLength) MessagingService(com.helospark.tactview.core.util.messaging.MessagingService) TimelineInterval(com.helospark.tactview.core.timeline.TimelineInterval) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) List(java.util.List) Optional(java.util.Optional) ClipFactoryChain(com.helospark.tactview.core.timeline.ClipFactoryChain) ProceduralVisualClip(com.helospark.tactview.core.timeline.proceduralclip.ProceduralVisualClip) AddClipRequest(com.helospark.tactview.core.timeline.AddClipRequest) ClipDescriptorsAdded(com.helospark.tactview.core.timeline.message.ClipDescriptorsAdded) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip) Bean(com.helospark.lightdi.annotation.Bean)

Example 8 with VisualTimelineClip

use of com.helospark.tactview.core.timeline.VisualTimelineClip 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 9 with VisualTimelineClip

use of com.helospark.tactview.core.timeline.VisualTimelineClip in project tactview by helospark.

the class FrameHoldEffect method createFrame.

@Override
public ReadOnlyClipImage createFrame(StatelessEffectRequest request) {
    VisualTimelineClip clip = request.getCurrentTimelineClip();
    ReadOnlyClipImage currentFrame = request.getCurrentFrame();
    GetFrameRequest frameRequest = GetFrameRequest.builder().withApplyEffects(true).withApplyEffectsLessThanEffectChannel(Optional.of(request.getEffectChannel())).withExpectedWidth(currentFrame.getWidth()).withExpectedHeight(currentFrame.getHeight()).withPosition(getInterval().getStartPosition()).withScale(request.getScale()).build();
    ReadOnlyClipImage frame = clip.getFrame(frameRequest);
    return frame;
}
Also used : GetFrameRequest(com.helospark.tactview.core.timeline.GetFrameRequest) ReadOnlyClipImage(com.helospark.tactview.core.timeline.image.ReadOnlyClipImage) VisualTimelineClip(com.helospark.tactview.core.timeline.VisualTimelineClip)

Example 10 with VisualTimelineClip

use of com.helospark.tactview.core.timeline.VisualTimelineClip 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

VisualTimelineClip (com.helospark.tactview.core.timeline.VisualTimelineClip)11 ReadOnlyClipImage (com.helospark.tactview.core.timeline.image.ReadOnlyClipImage)6 CreateEffectRequest (com.helospark.tactview.core.timeline.effect.CreateEffectRequest)4 GetFrameRequest (com.helospark.tactview.core.timeline.GetFrameRequest)3 StatelessVideoEffect (com.helospark.tactview.core.timeline.StatelessVideoEffect)3 TimelinePosition (com.helospark.tactview.core.timeline.TimelinePosition)3 EffectFactory (com.helospark.tactview.core.timeline.effect.EffectFactory)3 LightDiContext (com.helospark.lightdi.LightDiContext)2 VisualMediaMetadata (com.helospark.tactview.core.decoder.VisualMediaMetadata)2 FakeUi (com.helospark.tactview.core.it.util.ui.FakeUi)2 AudibleTimelineClip (com.helospark.tactview.core.timeline.AudibleTimelineClip)2 StatelessEffect (com.helospark.tactview.core.timeline.StatelessEffect)2 BigDecimal (java.math.BigDecimal)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Bean (com.helospark.lightdi.annotation.Bean)1 ConditionalOnProperty (com.helospark.lightdi.annotation.ConditionalOnProperty)1 Configuration (com.helospark.lightdi.annotation.Configuration)1 VideoMetadata (com.helospark.tactview.core.decoder.VideoMetadata)1 LoadMetadata (com.helospark.tactview.core.save.LoadMetadata)1 SaveMetadata (com.helospark.tactview.core.save.SaveMetadata)1