Skip to content

Instantly share code, notes, and snippets.

@chocotan
Created December 26, 2021 04:20
Show Gist options
  • Save chocotan/17bacad11878f8abce41574f9f502c44 to your computer and use it in GitHub Desktop.
Save chocotan/17bacad11878f8abce41574f9f502c44 to your computer and use it in GitHub Desktop.
public class JafTest {
public static void main(String[] args) throws InterruptedException {
FFmpeg.atPath()
.addInput(UrlInput.fromUrl("这里是flv地址"))
.setLogLevel(LogLevel.INFO)
.setOverwriteOutput(true)
.addOutput(UrlOutput.toUrl("/tmp/test.flv"))
.addOutput(FrameOutput
.withConsumer(
new FrameConsumer() {
private long num = 1;
@Override
public void consumeStreams(List<Stream> streams) {
// All stream type except video are disabled. just ignore
}
@Override
public void consume(Frame frame) {
// End of Stream
if (frame == null) {
return;
}
try {
String filename = "/tmp/"+new SimpleDateFormat("HH:mm:ss").format(new Date())+".png";
ImageIO.write(frame.getImage(), "png", new File(filename));
} catch (Exception e) {
e.printStackTrace();
}
}
}
)
// 1 frame every 10 seconds
.setFrameRate(0.1)
// Disable all streams except video
.disableStream(StreamType.AUDIO)
.disableStream(StreamType.SUBTITLE)
.disableStream(StreamType.DATA)
)
.execute();
Thread.sleep(1000000L);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment