Giter VIP home page Giter VIP logo

velvet-video's Introduction

velvet-video

Java library for encoding/decoding/muxing/demuxing video and audio. The API is high level, so the library users do not need to dive deep into details of video/audio encoding technology.

In particular, with velvet-video it's easy to:

  • create video from still images
  • extract frames from a video
  • extract audio tracks from video files
  • remux video or audio from one container format to another (like mp4 to mkv)
  • transcode (recompress) videos/audios using another codec (like x264 to vp9 or wav to mp3)
  • change video timing (slo-mo, timelapse etc)
  • merge videos or split them to segments
  • apply filters of transformations (before encoding or after decoding)

velvet-video supports dozens of container formats (including mp4, avi, webm, matroska) and codecs (including x264, hevc, vp9, av1).

Travis CI velvet-video on bintray

velvet-video embeds FFmpeg libraries under the hood, so it works at native speed and uses all FFmpeg's hardware optimization. Extracting and loading native libs is fully covered by velvet-video.

Supported platforms:

  • Windows 64 bit
  • Linux 64 bit

Please contact me if you need support for a platform not listed here.

Setup

To use velvet-video add the core dependency plus an appropriate native FFmpeg components package. velvet-video is available on Maven Central

The choice for native package is:

  • velvet-video-natives:free

    • only royalty-free components are included
    • encoders/decoders: Google VP8 and VP9, AOM av1
    • muxers/demuxers: webm, mkv, ogg
  • velvet-video-natives:full

    • maximum FFmpeg functionality included
    • the included components use patented technologies and may require royalty fees for commercial usage

gradle

dependencies {
    compile 'com.github.zakgof:velvet-video:0.5.2'
    compile 'com.github.zakgof:velvet-video-natives:0.2.8.full'
}

maven

<dependency>
  <groupId>com.github.zakgof</groupId>
  <artifactId>velvet-video</artifactId>
  <version>0.5.2</version>
  <type>pom</type>
</dependency>
<dependency>
  <groupId>com.github.zakgof</groupId>
  <artifactId>velvet-video-natives</artifactId>
  <version>0.2.8.full</version>
  <type>pom</type>
</dependency>

Quick start

Encode images into a video:

    IVelvetVideoLib lib = VelvetVideoLib().getInstance();
    try (IMuxer muxer = lib.muxer("matroska")
        .video(lib.videoEncoder("libaom-av1").bitrate(800000))
        .build(new File("/some/path/output.mkv"))) {
             IEncoderVideoStream videoStream = muxer.videoStream(0);	        
             videoStream.encode(image1);
             videoStream.encode(image2);
             videoStream.encode(image3);
    }      

Obtain images from a video:

	IVelvetVideoLib lib = VelvetVideoLib().getInstance();
	try (IDemuxer demuxer = lib.demuxer(new File("/some/path/example.mp4"))) {
	    IDecoderVideoStream videoStream = demuxer.videoStream(0);
	    IFrame videoFrame;
	    while ((videoFrame = videoStream.nextFrame()) != null) {
	   	    BufferedImage image = videoFrame.image();
	   	    // Use image as needed...
	    }
	}      

More examples

https://github.com/zakgof/velvet-video/tree/master/src/example/java/com/zakgof/velvetvideo/example

Example Description
ImagesToVideoAndBack Extract frame images from a video + compose a video from images
TranscodeVideoWithTimingEffects Transcode a video using another codec and applying slomo
RemuxVideo Repackage a video into another container format without transcoding
ScreenCaptureToVideo Capture the whole desktop to video
AudioPlayback Play a compressed audio file
ExtractAndTranscodeAudio Fetch audio tracks from a video file and save them as mp3 files

Advanced example: video player

See https://github.com/zakgof/velvet-video-player

License

velvet-video-core is dual-licensed under Apache 2.0 and GPL 3.0 (or any later version).

To comply with the FFMpeg components license present bundles into velvet-video-natives, choose Apache-2.0 when using with velvet-video-natives:free or GPL-3.0-or-later when using with velvet-video-natives:full

SPDX-License-Identifier: Apache-2.0 OR GPL-3.0-or-later

velvet-video-natives binaries on jcenter are licensed:

  • velvet-video-natives:free - under LGPL 3.0 or later
  • velvet-video-natives:full - under GPL 3.0 or later

velvet-video-natives build scripts are licensed under Apache 2.0

velvet-video's People

Contributors

zakgof avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

velvet-video's Issues

How to pause a video playback!

I'm trying to make a video player using your demo project as a reference. Do you have an example of how you would implement a pause functionality?

don't apply audio filter on mp3 file

don't work audio filter. example apply fade in and fade out

File src = new File("path");
`IVelvetVideoLib lib = VelvetVideoLib.getInstance();
IAudioDecoderStream audioStream = lib.demuxer(src).audioStreams().get(0);
AudioFormat format = audioStream.properties().format();

File output = new File(src.getParent(),filename);
IMuxerBuilder muxerBuilder = lib.muxer("mp3");

IAudioEncoderBuilder audioEncoderBuilder = lib.audioEncoder("libmp3lame", format).enableExperimental()
.filter("afade=t=in:st=0:d=15,afade=t=out:st=63:d=15");

IMuxer muxer = muxerBuilder.audioEncoder(audioEncoderBuilder).build(output);

IAudioEncoderStream audioEncoder = muxer.audioEncoder(0);

for (IAudioFrame audioFrame : audioStream) {
audioEncoder.encode(audioFrame.samples());
}`

crash on linux caused by loading wrong version of native libs

I've tried to play back some audio based on AudioPlayback example, and on linux (manjaro, though I doubt that matters) I got crash in libavutil:

[main] INFO velvet-video - Loading velvet-video-natives version 0.2.8.full
[main] DEBUG velvet-video - Velvet-video native extraction location is /home/<user>/.velvet-video/natives/0.2.8.full
[main] DEBUG velvet-video - Requesting loading native lib avutil.56
[main] DEBUG velvet-video - Checking native lib libavutil.so.56 at /home/<user>/.velvet-video/natives/0.2.8.full
[main] DEBUG velvet-video - Loaded libavutil.so.56
[main] DEBUG velvet-video - Requesting loading native lib swresample.3
[main] DEBUG velvet-video - Checking native lib libswresample.so.3 at /home/<user>/.velvet-video/natives/0.2.8.full
[main] DEBUG velvet-video - Loaded libswresample.so.3
[main] DEBUG velvet-video - Preloading native lib dependendcy: /home/<user>/.velvet-video/natives/0.2.8.full/libopenh264.so.5
[main] DEBUG velvet-video - Requesting loading native lib avcodec.58
[main] DEBUG velvet-video - Checking native lib libavcodec.so.58 at /home/<user>/.velvet-video/natives/0.2.8.full
[main] DEBUG velvet-video - Loaded libavcodec.so.58
[main] DEBUG velvet-video - Requesting loading native lib avformat.58
[main] DEBUG velvet-video - Checking native lib libavformat.so.58 at /home/<user>/.velvet-video/natives/0.2.8.full
[main] DEBUG velvet-video - Loaded libavformat.so.58
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f8aa2e7dc77, pid=55483, tid=55484
#
# JRE version: OpenJDK Runtime Environment (17.0.3+3) (build 17.0.3+3)
# Java VM: OpenJDK 64-Bit Server VM (17.0.3+3, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C  [libavutil.so.57.17.100+0x39c77]  av_opt_child_next+0x7
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/<user>/Documents/src/opus_decode_test/core.55483)
#
# An error report file with more information is saved as:
# /home/<user>/Documents/src/opus_decode_test/hs_err_pid55483.log
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
[1]    55483 IOT instruction (core dumped)

It seems like even though logs at the beginning say that libavutil.so.56 was loaded (from ~/.velvet-video), crash occured in libavutil.so.57.17.100. Looking at error report (hs_err_pid55483.log), it turns out that libavutil from my system was loaded: velvet is using /usr/lib/libavutil.so.57.17.100, /usr/lib/libswresample.so.4.3.100, /usr/lib/libavcodec.so.59.18.100 and /usr/lib/libavformat.so.59.16.100. Only lib that was actually loaded from ~/.velvet-video is libopenh264.so.5, which I don't have installed.

A weird thing from the error report is the fact that it seems like java tried to load the libs from ~/.velvet-video, but failed? Here are relevant lines:

Event: 0,606 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x0000000716640630}: avutil: cannot open shared object file: No such file or directory> (0x0000000716640630) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]
Event: 0,672 Thread 0x00007f845c012630 Exception <a 'java/lang/NoSuchMethodError'{0x0000000716bd6d58}: 'java.lang.Object java.lang.invoke.DirectMethodHandle$Holder.newInvokeSpecial(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)'> (0x0000000716bd6d58) 
thrown [src/hotspot/share/interpreter/linkResolver.cpp, line 765]
Event: 0,741 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x00000007169ecc28}: /usr/lib64/libavutil.so.57.17.100: undefined symbol: av_frame_get_pkt_duration> (0x00000007169ecc28) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]
Event: 0,754 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x0000000716674630}: swresample: cannot open shared object file: No such file or directory> (0x0000000716674630) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]
Event: 0,795 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x0000000716b9a240}: avcodec: cannot open shared object file: No such file or directory> (0x0000000716b9a240) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]
Event: 0,840 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x0000000715f04280}: /usr/lib64/libavcodec.so.59.18.100: undefined symbol: avcodec_open2x> (0x0000000715f04280) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]
Event: 0,842 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x0000000715f21058}: /usr/lib64/libavcodec.so.59.18.100: undefined symbol: avcodec_register_all> (0x0000000715f21058) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]
Event: 0,843 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x0000000715f2ad50}: /usr/lib64/libavcodec.so.59.18.100: undefined symbol: avcodec_encode_video2> (0x0000000715f2ad50) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]
Event: 0,857 Thread 0x00007f845c012630 Exception <a 'java/lang/UnsatisfiedLinkError'{0x0000000715fb8e10}: avformat: cannot open shared object file: No such file or directory> (0x0000000715fb8e10) 
thrown [src/hotspot/share/prims/jni.cpp, line 535]

I'd look into it some more, but at the moment I have pretty much no idea how java is handling native libraries.

Demuxing internal sample goliath

[matroska,webm @ 00000000203337c0] Could not find codec parameters for stream 0 (Video: h264, none, 1920x1080): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options

Natives not re-extracted when using .free then .full natives

I'm attempting to play a mp4 file but I'm getting the following exception:

Apr 01, 2020 10:30:27 PM de.gurkenlabs.litiengine.configuration.Configuration load
INFO: Configuration config.properties loaded
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
Apr 01, 2020 10:30:28 PM de.gurkenlabs.litiengine.DefaultUncaughtExceptionHandler uncaughtException
SEVERE: Game crashed! :(
com.zakgof.velvetvideo.VelvetVideoException: FFMPEG error -1094995529 : Invalid data found when processing input
        at com.zakgof.velvetvideo.impl.jnr.LibAVUtil.checkcode(LibAVUtil.java:101)
	at com.zakgof.velvetvideo.impl.VelvetVideoLib.checkcode(VelvetVideoLib.java:124)
	at com.zakgof.velvetvideo.impl.VelvetVideoLib.access$200(VelvetVideoLib.java:87)
	at com.zakgof.velvetvideo.impl.VelvetVideoLib$DemuxerImpl.<init>(VelvetVideoLib.java:818)
	at com.zakgof.velvetvideo.impl.VelvetVideoLib.demuxer(VelvetVideoLib.java:794)
	at com.zakgof.velvetvideo.IVelvetVideoLib.demuxer(IVelvetVideoLib.java:27)
	at de.gurkenlabs.litiengine.video.VideoPlayer$Demuxer.<init>(VideoPlayer.java:149)
	at de.gurkenlabs.litiengine.video.VideoPlayer.setVideo(VideoPlayer.java:37)
	at de.gurkenlabs.litiengine.video.VideoPlayer.<init>(VideoPlayer.java:30)
	at de.gurkenlabs.litiengine.video.VideoComponent.setVideo(VideoComponent.java:68)
	at de.gurkenlabs.litiengine.video.VideoComponent.setVideo(VideoComponent.java:50)
	at de.gurkenlabs.litiengine.video.VideoComponent.play(VideoComponent.java:54)
	at de.gurkenlabs.litiengine.video.VideoComponent.<init>(VideoComponent.java:28)
	at de.gurkenlabs.litiengine.resources.Videos.load(Videos.java:16)
	at com.gamebuster19901.Game.Main$VideoScreen.<init>(Main.java:37)
	at com.gamebuster19901.Game.Main.main(Main.java:32)

These are the video properties:

image

Loading velvet-video-natives from jar only is supported

I'm using intelliJ and I've downloaded velvet-video-natives-0.2.8.full.jar. I've added it to my classpath with intelliJ but I'm getting the error: "Loading velvet-video-natives from jar only is supported". What's going on?

Support MP4+flac

Getting error flac in MP4 support is experimental despite strict=-2 set

Can't find locale libs

I'm in trouble using velvet-video

Using maven dependencies 0.5.1 :
-Xms4000m
-Xmx4000m

        <additionalClasspathElement>/home/cabox/workspace/empty3/.velvet-video-natives/velvet-video-natives-0.5.1-SNAPSHOT.jar</additionalClasspathElement>
      </additionalClasspathElements>
            </configuration>
        </plugin>

(i ve tried relative and absolute path)

Put compilation of velvet-video natives into this folder.

Encode/decode audio

Add api for encoding/decoding audio + include audio codec into native builds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.