FFmpegFrameRecorder return error message when record decoded AVPacket
#1,861 opened on Aug 4, 2022
Repository metrics
- Stars
- (6,985 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
After I encoded the grabbed packets and decoded the encoded byte array to AVPacket, I attempted record the decoded packets. It makes error code and recorded video did not play properly. But, when I tried recording the grabbed packets directly, it was work well.
So I think I have a problem with the encoding process. I wonder what value should be added or what process should be added in decoded AVPacket.
I used 1.5.7 version of javacv-platform
public static void main(String[] args) throws Exception {
avutil.logCallback();
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtsp://~~~/~~~");
grabber.setFormat("rtsp");
grabber.start();
AVFormatContext context = grabber.getFormatContext();
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("C:\\test\\aaa.mp4", 1920, 1080, 0);
recorder.start(context);
AVPacket pkt = null;
Long millis = System.currentTimeMillis();
while (System.currentTimeMillis() - millis < 15000L) {
pkt = grabber.grabPacket();
Packet encoded = Encoding.encode(pkt);
AVBufferRef av = pkt.buf();
AVPacket packet = Decoding.decode(encoded.getData());
packet.buf(av);
recorder.recordPacket(packet);
}
recorder.flush();
recorder.close();
}
public static AVPacket decode(byte[] data){
AVPacket avPacket = av_packet_alloc();
int size = Utils.byteToInt(data, Utils.SIZE_FIELD);
int stream_index = Utils.byteToInt(data, Utils.STREAM_INDEX_FIELD);
long dts = Utils.byteToLong(data, Utils.DTS_FIELD);
long pts = Utils.byteToLong(data, Utils.PTS_FIELD);
int flag = Utils.byteToInt(data, Utils.FLAGS_FIELD);
long pos = Utils.byteToLong(data, Utils.POS_FIELD);
byte content[] = new byte[size];
System.arraycopy(data, Utils.DATA_OFFSET, content, 0, size);
BytePointer bp = new BytePointer(content);
bp.capacity(content.length);
avPacket.data(bp);
avPacket.size(content.length);
avPacket.pts(pts);
avPacket.dts(dts);
avPacket.flags(flag);
avPacket.pos(pos);
avPacket.stream_index(stream_index);
avPacket.duration(3000);
avPacket.position(0);
avPacket.capacity(1);
return avPacket;
}
Input #0, rtsp, from 'rtsp://~~~/~~~': Metadata: title : Session streamed with GStreamer comment : rtsp-server Duration: N/A, start: 0.066667, bitrate: N/A Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1920x1080, 30 fps, 30 tbr, 90k tbn Output #0, mp4, to 'C:\test\aaa.mp4': Metadata: encoder : Lavf59.16.100 Stream #0:0: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080, q=2-31, 30 fps, 15360 tbn
[mp4 @ 0000029a2d689e80] Application provided duration: 12297829382474058 / timestamp: 1024 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value [mp4 @ 0000029a2d689e80] Application provided duration: 12297829382474569 / timestamp: 1536 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value [mp4 @ 0000029a2d689e80] Application provided duration: 12297829382475080 / timestamp: 2048 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value [mp4 @ 0000029a2d689e80] Application provided duration: 12297829382475591 / timestamp: 2560 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value [mp4 @ 0000029a2d689e80] Application provided duration: 12297829382476102 / timestamp: 3072 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value [mp4 @ 0000029a2d689e80] Application provided duration: 12297829382476613 / timestamp: 3584 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value [mp4 @ 0000029a2d689e80] Application provided duration: 12297829382477124 / timestamp: 4096 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value [mp4 @ 0000029a2d689e80] Application provided duration: 12297829382477635 / timestamp: 4608 is out of range for mov/mp4 format [mp4 @ 0000029a2d689e80] pts has no value