Open fantasylhd opened 1 year ago
We can easily use the ffmpeg program from Java as well if that does what you need: http://bytedeco.org/javacpp-presets/ffmpeg/apidocs/org/bytedeco/ffmpeg/ffmpeg.html
What is the problem with my code? Javacv does not support such writing
Well, you didn't set the codec, so maybe it's not using a codec supported by your player?
Cannot play after encoder is set
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtmp://xxx.com/3573613170/18573613170");
grabber.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("C:\\Users\\lhd\\Desktop\\2.mp4", grabber.getImageWidth(), grabber.getImageHeight(),grabber.getAudioChannels());
recorder.setVideoCodec(grabber.getVideoCodec());
recorder.setAudioCodec(grabber.getAudioCodec());
recorder.setFormat("mp4");
recorder.start(grabber.getFormatContext());
LocalDateTime startTime = LocalDateTime.now();
int times = 0;
AVPacket avPacket = null;
while (startTime.plusSeconds(10).compareTo(LocalDateTime.now()) > 0) {
avPacket = grabber.grabPacket();
if (avPacket != null) {
recorder.recordPacket(avPacket);
times++;
System.out.println("record! "+times);
}
}
recorder.close();
grabber.close();
Stored as flv files can be played
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtmp://xxx.com/3573613170/18573613170");
grabber.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("C:\\Users\\lhd\\Desktop\\2.flv", grabber.getImageWidth(), grabber.getImageHeight(),grabber.getAudioChannels());
// recorder.setVideoCodec(grabber.getVideoCodec());
// recorder.setAudioCodec(grabber.getAudioCodec());
recorder.setFormat("flv");
recorder.start(grabber.getFormatContext());
LocalDateTime startTime = LocalDateTime.now();
int times = 0;
AVPacket avPacket = null;
while (startTime.plusSeconds(10).compareTo(LocalDateTime.now()) > 0) {
avPacket = grabber.grabPacket();
if (avPacket != null) {
recorder.recordPacket(avPacket);
times++;
System.out.println("record! "+times);
}
}
recorder.close();
grabber.close();
Hi,I want to store the rmtp stream as an mp4 file,For example, use the ffmpeg command :
ffmpeg -i rtmp://xx.com/3573613170/18573613170 -f mp4 -vcodec copy -acodec copy C:\Users\lhd\Desktop\2.mp4
But what should we do in javacv can you give me some advise? thank you! If there is some example code, that's perfect! thank you ~~This is the code I tried to use javacv to complete this task, but the recorded video cannot be played:
Dependent version: