a-schild / jave2

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project
GNU General Public License v3.0
1.28k stars 249 forks source link

How to use SetPtsFilter to set video pts? #232

Open MrSSai opened 1 year ago

MrSSai commented 1 year ago

Hello, I'm new in ws.schild. I want to do it like use ffmpeg -filter:v "setpts=0.5*PTS", but when I use SetPtsFilter() to VideoAttributes().addFilter() method, it doesn't work. This is my code, can you help me?

public class VideoTranscoder {
    public static void main(String[] args) throws EncoderException {
        String inputPath = "/home/user/video.mp4";
        String outputPath = "/home/user/output.mp4";

        SetPtsFilter setPtsFilter = new SetPtsFilter();
        setPtsFilter.addInputLabel("0.5*PTS");

        VideoAttributes video = new VideoAttributes();
        video.setCodec("libx264");
        video.setFrameRate(30);
        video.addFilter(setPtsFilter);

        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setOutputFormat("mp4");
        attrs.setVideoAttributes(video);

        Encoder encoder = new Encoder();
        MultimediaObject mediaObject = new MultimediaObject(new File(inputPath));
        encoder.encode(mediaObject, new File(outputPath), attrs);
        System.out.println("Video transcoding complete.");
    }
}