javacv
javacv copied to clipboard
color loss and image duplication when using xfade to merge two videos.
my platform version is:
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.9</version>
</dependency>
my code is as follow (i learned from #1776 ):
public static void main(String[] args) throws FFmpegFrameGrabber.Exception, FFmpegFrameRecorder.Exception, FFmpegFrameFilter.Exception {
String out = "/home/hxl/vlogdemo/" + new SimpleDateFormat("MMdd-HHmmss'.mp4'").format(new Date());
String inputFilePath = "/home/hxl/vlogdemo/1.mp4";
String inputFilePath2 = "/home/hxl/vlogdemo/2.mp4";
FFmpegLogCallback.set();
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFilePath);
grabber.start();
FFmpegFrameGrabber grabber2 = new FFmpegFrameGrabber(inputFilePath2);
grabber2.start();
FFmpegFrameFilter filter = new FFmpegFrameFilter(
"[0:v][1:v]xfade=transition=wipeleft:offset=5s:duration=2[v]",
grabber.getImageWidth(), grabber.getImageHeight());
filter.setPixelFormat(grabber.getPixelFormat());
filter.setSampleFormat(grabber.getSampleFormat());
filter.setVideoInputs(2);
filter.setImageHeight(grabber.getImageHeight());
filter.setImageWidth(grabber.getImageWidth());
filter.start();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(out, grabber.getImageWidth(), grabber.getImageHeight());
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setFormat("mp4");
recorder.setAudioBitrate(grabber.getAudioBitrate());
recorder.setVideoBitrate(grabber.getVideoBitrate());
recorder.setFrameRate(grabber.getFrameRate());
recorder.setAudioChannels(grabber.getAudioChannels());
recorder.setSampleRate(grabber.getSampleRate());
recorder.start();
Frame frame1, frame2, frame;
while ((frame1 = grabber.grabImage()) != null && (frame2 = grabber2.grabImage()) != null) {
filter.push(0, frame1);
filter.push(1, frame2);
frame = filter.pullImage();
if (frame != null && frame.image != null) {
recorder.record(frame);
}
}
grabber.stop();
grabber2.stop();
filter.stop();
recorder.stop();
System.out.println("finish");
}
and the output video is like this:
my first video:
and my second video:
why does color lose?and why dose image duplicated?
here is output in console:
Warning: [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8d18c53800] Unknown cover type: 0x1.
Info: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/hxl/vlogdemo/1.mp4':
Info: Metadata:
Info: major_brand :
Info: qt
Info:
Info: minor_version :
Info: 0
Info:
Info: compatible_brands:
Info: qt
Info:
Info: creation_time :
Info: 2023-11-22T06:42:43.000000Z
Info:
Info: Duration:
Info: 00:00:21.03
Info: , start:
Info: 0.000000
Info: , bitrate:
Info: 16116 kb/s
Info:
Info: Stream #0:0
Info: [0x1]
Info: (und)
Info: : Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080, 15985 kb/s
Info: ,
Info: 30 fps,
Info: 30 tbr,
Info: 600 tbn
Info: (default)
Info:
Info: Metadata:
Info: creation_time :
Info: 2023-11-22T06:42:43.000000Z
Info:
Info: handler_name :
Info: Core Media Video
Info:
Info: vendor_id :
Info: [0][0][0][0]
Info:
Info: encoder :
Info: H.264
Info:
Info: Stream #0:1
Info: [0x2]
Info: (und)
Info: : Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 124 kb/s
Info: (default)
Info:
Info: Metadata:
Info: creation_time :
Info: 2023-11-22T06:42:43.000000Z
Info:
Info: handler_name :
Info: Core Media Audio
Info:
Info: vendor_id :
Info: [0][0][0][0]
Info:
Warning: [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8d196d6f40] Unknown cover type: 0x1.
Info: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/hxl/vlogdemo/2.mp4':
Info: Metadata:
Info: major_brand :
Info: qt
Info:
Info: minor_version :
Info: 0
Info:
Info: compatible_brands:
Info: qt
Info:
Info: creation_time :
Info: 2023-11-22T08:54:18.000000Z
Info:
Info: Duration:
Info: 00:00:19.00
Info: , start:
Info: 0.000000
Info: , bitrate:
Info: 15364 kb/s
Info:
Info: Stream #0:0
Info: [0x1]
Info: (und)
Info: : Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080, 15237 kb/s
Info: ,
Info: 30 fps,
Info: 30 tbr,
Info: 600 tbn
Info: (default)
Info:
Info: Metadata:
Info: creation_time :
Info: 2023-11-22T08:54:18.000000Z
Info:
Info: handler_name :
Info: Core Media Video
Info:
Info: vendor_id :
Info: [0][0][0][0]
Info:
Info: encoder :
Info: H.264
Info:
Info: Stream #0:1
Info: [0x2]
Info: (und)
Info: : Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 121 kb/s
Info: (default)
Info:
Info: Metadata:
Info: creation_time :
Info: 2023-11-22T08:54:18.000000Z
Info:
Info: handler_name :
Info: Core Media Audio
Info:
Info: vendor_id :
Info: [0][0][0][0]
Info:
Warning: [libopenh264 @ 0x7f8d1a270100] [OpenH264] this = 0x0x7f8d1942b490, Warning:layerId(0) doesn't support profile(578), change to UNSPECIFIC profile
Warning: [libopenh264 @ 0x7f8d1a270100] [OpenH264] this = 0x0x7f8d1942b490, Warning:bEnableFrameSkip = 0,bitrate can't be controlled for RC_QUALITY_MODE,RC_BITRATE_MODE and RC_TIMESTAMP_MODE without enabling skip frame.
Info: Output #0, mp4, to '/home/hxl/vlogdemo/1214-142225.mp4':
Info: Metadata:
Info: encoder :
Info: Lavf60.3.100
Info:
Info: Stream #0:0
Info: : Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, q=2-31, 15985 kb/s
Info: ,
Info: 30 fps,
Info: 15360 tbn
Info:
Info: Stream #0:1
Info: : Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 124 kb/s
Info:
Warning: [v @ 0x7f8d1a11c300] 100 buffers queued in v, something may be wrong.
Info: [aac @ 0x7f8d1a271440] Qavg: nan
Make sure you're calling getPixelFormat() and using its values where appropriate such as when calling push(), record(), etc