-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
I record rtmp to a video file with x264 encorder with errors, similler to #778. I have add recorder.setVideoOption("threads", "1");
, but still the same error. when i remove line recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
, it work fine. but the video file is not H264 ecoder. I use javacv-platform 1.5.4. and i did not use multithreading. below is my code and exception.
Snippet from code:
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("rtmp://10.160.21.186/live/camera_11");
grabber.start();
String videoFile = videoSavePath + File.separator + DateFormatUtils.format(t1, "yyyyMMddHHmmss") + ".mp4";
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(videoFile, 1280, 720, audioChannel);
recorder.setVideoOption("threads", "1");
recorder.setFrameRate(grabber.getFrameRate());
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setFormat("flv");
recorder.start();
Frame frame;
int frames = 0;
int conNullFrames = 0;
while (conNullFrames <= 5) {
if((frame = grabber.grabFrame()) != null){
conNullFrames = 0;
recorder.record(frame);
frames ++;
if (frames >= grabber.getFrameRate() * 30) {
recorder.stop();
and i got this error:
org.bytedeco.javacv.FrameRecorder$Exception: avcodec_encode_video2() error -542398533: Could not encode video packet.
at org.bytedeco.javacv.FFmpegFrameRecorder.recordImage(FFmpegFrameRecorder.java:1045)
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:948)
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:941)
at video.record.RtmpRecorder.frameRecord(RtmpRecorder.java:157)
at video.record.RtmpRecorder.main(RtmpRecorder.java:269)
and ffmpeg log:
Input #0, flv, from 'rtmp://10.160.21.186/live/camera_11':
Metadata:
Server : NGINX HTTP-FLV (https://github.com/winshining/nginx-http-flv-module)
displayWidth : 1280
displayHeight : 720
fps : 25
profile :
level :
Duration: 00:00:00.00, start: 0.000000, bitrate: N/A
Stream #0:0: Data: none
Stream #0:1: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc
[libx264 @ 00000000212002c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 00000000212002c0] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 00000000212002c0] 264 - core 160 - H.264/MPEG-4 AVC codec - Copyleft 2003-2020 - 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=1 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=400 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to '/opt/video/\20210114142430.mp4':
Metadata:
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (Constrained Baseline) ([7][0][0][0] / 0x0007), yuv420p, 1280x720, q=2-31, 400 kb/s, 25 fps, 1k tbn, 25 tbc
[swscaler @ 0000000025189e40] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 00000000212002c0] lookahead thread is already stopped
appreciate any suggestions. thank u.