The first thing that came to mind when I saw this error was: What's a -22 error? Sure would be nice to have them in a readable format.......
So the 22 means "Invalid argument". Which argument is invalid is what I am struggling with. The application I wrote merges two media files. First I figure out if the media to be merged is audio or video and then I merge an introduction and copyright notice to an uploaded file. This has been working great for audio, I am just getting started with video. Both the intro and the uploaded file had been processed with Handbrake and they look pretty similar but obviously I am failing to account for something. So here is the whole trace:
root@prod logs]# Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Copyright.mp4':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2036-02-06 06:28:16
Duration: 00:00:34.68, start: 0.000000, bitrate: 315 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 960x720 [SAR 1:1 DAR 4:3], 147 kb/s, 30.30 fps, 30.30 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2036-02-06 06:28:16
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 160 kb/s (default)
Metadata:
creation_time : 2036-02-06 06:28:16
handler_name : Stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'TEMPlecture.mlt':
Metadata:
major_brand : mp42
minor_version : 512
compatible_brands: isomiso2avc1mp41
creation_time : 2016-04-12 16:25:24
Duration: 00:48:03.78, start: 0.000000, bitrate: 720 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 480x270 [SAR 1:1 DAR 16:9], 569 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 180k tbc (default)
Metadata:
creation_time : 2016-04-12 16:25:24
handler_name : VideoHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 136 kb/s (default)
Metadata:
creation_time : 2016-04-12 16:25:24
handler_name : Stereo
Output #0, mp4, to 'lecture.mp4':
Stream #0:0: Video: h264, yuv420p, 640x480, q=-1--1, 147 kb/s, 90k tbn, 30.30 tbc
Stream #0:1: Audio: aac, 44100 Hz, stereo, fltp, 64 kb/s
[libx264 @ 0x453426a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x453426a0] profile High, level 3.0
[libx264 @ 0x453426a0] 264 - core 142 r2 ac76440 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 -
http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=9 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=147 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[libx264 @ 0x453426a0] non-strictly-monotonic PTS
[mp4 @ 0x475b8160] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 555456 >= 555456
[libx264 @ 0x453426a0] frame I:6 Avg QP:11.83 size: 24765
[libx264 @ 0x453426a0] frame P:483 Avg QP:13.02 size: 701
[libx264 @ 0x453426a0] frame B:568 Avg QP:10.37 size: 64
[libx264 @ 0x453426a0] consecutive B-frames: 22.2% 17.9% 0.3% 59.6%
[libx264 @ 0x453426a0] mb I I16..4: 52.3% 19.9% 27.8%
[libx264 @ 0x453426a0] mb P I16..4: 0.1% 0.1% 0.0% P16..4: 5.6% 1.8% 1.4% 0.0% 0.0% skip:91.0%
[libx264 @ 0x453426a0] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 3.7% 0.1% 0.0% direct: 0.0% skip:96.2% L0:37.8% L1:59.5% BI: 2.7%
[libx264 @ 0x453426a0] final ratefactor: 18.32
[libx264 @ 0x453426a0] 8x8 transform intra:23.1% inter:30.4%
[libx264 @ 0x453426a0] coded y,uvDC,uvAC intra: 27.8% 13.6% 13.3% inter: 1.4% 0.0% 0.0%
[libx264 @ 0x453426a0] i16 v,h,dc,p: 86% 8% 6% 0%
[libx264 @ 0x453426a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 46% 16% 34% 0% 1% 1% 0% 1% 1%
[libx264 @ 0x453426a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 23% 12% 3% 4% 5% 5% 4% 5%
[libx264 @ 0x453426a0] i8c dc,h,v,p: 86% 3% 10% 1%
[libx264 @ 0x453426a0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x453426a0] ref P L0: 61.8% 2.5% 27.5% 8.3%
[libx264 @ 0x453426a0] ref B L0: 83.3% 16.2% 0.5%
[libx264 @ 0x453426a0] ref B L1: 98.4% 1.6%
[libx264 @ 0x453426a0] kb/s:120.28
[#|2016-04-12T17:19:41.881+0000|SEVERE|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=1803;_ThreadName=Thread-52570;|org.bytedeco.javacv.FrameRecorder$Exception: av_interleaved_write_frame() error -22 while writing interleaved video frame.
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:725)
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:629)
at org.bytedeco.javacv.FrameRecorder.record(FrameRecorder.java:290)
at org.bsfinternational.filemgr.MergeUsingFFMPEG.run(MergeUsingFFMPEG.java:293)
at java.lang.Thread.run(Thread.java:662)
This is running on RHEL5 with Java 6 and Glassfish 3.01 the relevant code (not all of it) is:
try {
intro.start();
if(isVideo){
lecture.start();
videoFormat = lecture.getFormat();
introVideoBitrate = intro.getVideoBitrate();
introVideoCodec = intro.getVideoCodec();
}
introAudioChannels = intro.getAudioChannels();
mediaFormat = intro.getFormat();
introSampleRate = intro.getSampleRate();
introSampleFormat = intro.getSampleFormat();
introAudioBitrate = intro.getAudioBitrate();
audioCodec = intro.getAudioCodec();
// we'll be recording a video perhaps
if(isVideo){
double introFrameRate = intro.getFrameRate();
recorder = new FFmpegFrameRecorder(output, 640, 480, introAudioChannels);
recorder.setFrameRate(introFrameRate);
// There is an issue with fltp format I am going to try switching but might run into an issue in Linux
if(avutil.AV_SAMPLE_FMT_FLTP == introSampleFormat && !SystemUtils.IS_OS_LINUX)
introSampleFormat = avutil.AV_SAMPLE_FMT_S16;// Looks like we have to set this rather than pull it from the intro
recorder.setSampleFormat(introSampleFormat);
recorder.setVideoBitrate(introVideoBitrate);
recorder.setFormat("mp4");
recorder.setVideoCodec(introVideoCodec);
recorder.setAudioCodec(audioCodec);
//recorder.setVideoOption(key, value);
}
else{
// Just audio
recorder = new FFmpegFrameRecorder(output,introAudioChannels);
recorder.setSampleFormat(introSampleFormat);
recorder.setSampleRate(introSampleRate);
recorder.setAudioBitrate(introAudioBitrate);
}
// Applies to both audio and video
//avcodec.avcodec_register_all();
recorder.start();
if(debug)
System.out.println("Opening output file:" + (System.currentTimeMillis()-intermediatetime));
Frame frame;
intermediatetime = System.currentTimeMillis();
while ((frame = intro.grabFrame()) != null) {
if(isVideo)
recorder.setTimestamp(intro.getTimestamp());
recorder.record(frame);
}
if(debug)
System.out.println("Done processing intro, opening and processing lecture:" + (System.currentTimeMillis()-intermediatetime));
intermediatetime = System.currentTimeMillis();
if(!isVideo){
lecture.start(); //if it is video we already started it...
}
intermediatetime = System.currentTimeMillis();
long t = recorder.getTimestamp();
while ((frame = lecture.grabFrame()) != null) {
if(isVideo)
recorder.setTimestamp(t+lecture.getTimestamp());
------>>>>> recorder.record(frame);
}
if(debug)
System.out.println("Done processing lecture:" + (System.currentTimeMillis()-intermediatetime));
lecture.stop();
intro.stop();
recorder.stop();
The error occurs where the arrows indicate above, while it is recording the frames. I can't tell if this is just a corruption in the file itself or something I can fix. If I process this file again with Handbrake, it doesn't throw this error but then the characteristics may have changed.
A little bit of research pointed in a couple of different direction. I wonder if there is something that jumps out at you that might point me in the right direction?
Thanks.