Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using FFmpegFrameRecorder to concat two MP4 videos #1191

Closed
li310 opened this issue Apr 23, 2019 · 1 comment
Closed

Error when using FFmpegFrameRecorder to concat two MP4 videos #1191

li310 opened this issue Apr 23, 2019 · 1 comment
Labels

Comments

@li310
Copy link

li310 commented Apr 23, 2019

I have the same problem merge two mp4 videos, two videos have the same rate
below my code:
FFmpegFrameGrabber grabber1 = new FFmpegFrameGrabber(videoPath+"1.mp4");
FFmpegFrameGrabber grabber2 = new FFmpegFrameGrabber(videoPath+"2.mp4");
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoOutputPath + "output.mp4",1280,720, 2);
grabber1.start();
grabber2.start();
recorder.start(grabber1.getFormatContext());
AVPacket packet1, packet2;
while ((packet1 = grabber1.grabPacket()) != null) {
recorder.recordPacket(packet1);
}
while ((packet2 = grabber2.grabPacket()) != null) {
recorder.recordPacket(packet2);
}
recorder.stop();
grabber1.stop();
grabber2.stop();

and the error:
Exception in thread "main" org.bytedeco.javacv.FrameRecorder$Exception: av_interleaved_write_frame() error -22 while writing interleaved video packet.
at org.bytedeco.javacv.FFmpegFrameRecorder.writePacket(FFmpegFrameRecorder.java:1222)
at org.bytedeco.javacv.FFmpegFrameRecorder.recordPacket(FFmpegFrameRecorder.java:1255)
at javacvdemo.VideoProcessing.packetRecord(VideoProcessing.java:177)
at javacvdemo.Application.main(Application.java:20)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'F:\work\javacvdemo\1.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:03.86, start: 0.000000, bitrate: 701 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 665 kb/s, 26 fps, 26 tbr, 13312 tbn, 52 tbc (default)
Metadata:
handler_name : 片头.mp4.vc.264#video - Imported with GPAC 0.5.1-DEV-rev4102M
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 37 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'F:\work\javacvdemo\2.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:09.66, start: 0.000000, bitrate: 989 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 946 kb/s, 26 fps, 26 tbr, 13312 tbn, 52 tbc (default)
Metadata:
handler_name : 正前 Comp 1.mp4.vc.264#video - Imported with GPAC 0.5.1-DEV-rev4102M
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 37 kb/s (default)
Metadata:
handler_name : SoundHandler
[mp4 @ 00000000205a7bc0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
[mp4 @ 00000000205a7bc0] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, mp4, to 'F:\work\javacvdemo\output.mp4':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 665 kb/s, 26 fps, 13312 tbn, 26 tbc
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 16000 Hz, mono, fltp, 37 kb/s
[mp4 @ 00000000205a7bc0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 49152 >= -1024

@saudet
Copy link
Member

saudet commented Apr 23, 2019

It just looks like you need to give the packets proper timestamps:

[mp4 @ 00000000205a7bc0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 49152 >= -1024

But if that still doesn't work, see issue #818.

@saudet saudet closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants