Skip to content

record rtmp with exception: avcodec_send_frame() error -541478725: Error sending a video frame for encoding #1858

@wangyiedge

Description

@wangyiedge

version: 1.5.7

I want to save the stream to MP4 file. I tried RTSP and m3u8, they are all success. But when using RTMP, I got an exception(avcodec_send_frame() error -541478725: Error sending a video frame for encoding). At first, I suspected that there was a problem with my RTMP stream, but when I changed a RTMP soure open on the Internet, the error stills there.

...
record! 82
record! 83
record! 84
2022-08-02 14:39:09.532  INFO 16831 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-08-02 14:39:09.579 ERROR 16831 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to execute CommandLineRunner
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:774) [spring-boot-2.7.2.jar:2.7.2]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:755) [spring-boot-2.7.2.jar:2.7.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.7.2.jar:2.7.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-2.7.2.jar:2.7.2]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) [spring-boot-2.7.2.jar:2.7.2]
	at cn.sibat.cvtest.CvTestApplication.main(CvTestApplication.java:10) [classes/:na]
Caused by: org.bytedeco.javacv.FFmpegFrameRecorder$Exception: avcodec_send_frame() error -541478725: Error sending a video frame for encoding. (For more details, make sure FFmpegLogCallback.set() has been called.)
	at org.bytedeco.javacv.FFmpegFrameRecorder.recordImage(FFmpegFrameRecorder.java:1056) ~[javacv-1.5.7.jar:1.5.7]
	at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:961) ~[javacv-1.5.7.jar:1.5.7]
	at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:954) ~[javacv-1.5.7.jar:1.5.7]
	at cn.sibat.cvtest.MainThread.run(MainThread.java:69) ~[classes/:na]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:771) [spring-boot-2.7.2.jar:2.7.2]
	... 5 common frames omitted
//        String url = "rtmp://10.0.24.23/live/2001";
String url = "rtmp://ns8.indexforce.com/home/mystream";
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(url);
grabber.start();

String localUrl = "/Users/yanwang/work/javacv.mp4";
FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(localUrl, grabber.getImageWidth(), grabber.getImageHeight(), grabber.getAudioChannels());
recorder.setFormat("mp4");
recorder.setFrameRate(grabber.getFrameRate());
recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
recorder.setVideoBitrate(grabber.getVideoBitrate());
recorder.start();

LocalDateTime startTime = LocalDateTime.now();
int times = 0;
Frame frame = null;
while (startTime.plusSeconds(10).compareTo(LocalDateTime.now()) > 0) {
    if ((frame = grabber.grab()) != null) {
        recorder.record(frame);
        times++;
        System.out.println("record! "+times);
    }
}
recorder.stop();
grabber.stop();
System.out.println("success");

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions