bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.6k stars 1.59k forks source link

crf not working on mac m2 #2274

Closed marlsenwang closed 3 months ago

marlsenwang commented 3 months ago

I test javacv with mp4 video compression below is the code

FFmpegFrameGrabber grabber = null;
        FFmpegFrameRecorder recorder = null;
        FFmpegLogCallback.setLevel(32);
        FFmpegLogCallback.set();
        try {
            // Initialize the grabber
            grabber = new FFmpegFrameGrabber(input);
            grabber.start();

            // Initialize the recorder
            recorder = new FFmpegFrameRecorder(output, grabber.getImageWidth(), grabber.getImageHeight(), grabber.getAudioChannels());
            recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
            recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
            recorder.setVideoQuality(5);
            recorder.setAudioQuality(5);
            recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
            recorder.start();

            // Read and write frames
            Frame frame;
            while ((frame = grabber.grab()) != null) {
                recorder.record(frame);
                recorder.setTimestamp(grabber.getTimestamp());

problem is whatever value I set to the quality, the output size does not change. Below is my dependency, my computer is mac m2 mini , is this a bug or my code misconfigured, any one explain to me , thanks.

<dependencies>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv</artifactId>
            <version>1.5.10</version>
        </dependency>

        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacpp</artifactId>
            <version>1.5.10</version>
            <classifier>${system.mac.classifier}</classifier>
        </dependency>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>ffmpeg</artifactId>
            <version>6.1.1-1.5.10</version>
            <classifier>${system.mac.classifier}</classifier>
        </dependency>

below is the javacv output including some warnings

Info:   Metadata:

Info:     major_brand     : 
Info: isom
Info: 

Info:     minor_version   : 
Info: 512
Info: 

Info:     compatible_brands: 
Info: isomiso2avc1mp41
Info: 

Info:     encoder         : 
Info: Lavf58.20.100
Info: 

Info:   Duration: 
Info: 00:00:30.08
Info: , start: 
Info: 0.000000
Info: , bitrate: 
Info: 4073 kb/s
Info: 

Info:   Stream #0:0
Info: [0x1]
Info: (und)
Info: : Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], 4071 kb/s
Info: , 
Info: 25 fps, 
Info: 25 tbr, 
Info: 12800 tbn
Info:  (default)
Info: 

Info:     Metadata:

Info:       handler_name    : 
Info: ETI ISO Video Media Handler
Info: 

Info:       vendor_id       : 
Info: [0][0][0][0]
Info: 

Warning: [libopenh264 @ 0x149616670] [OpenH264] this = 0x0x600000ec08d0, Warning:layerId(0) doesn't support profile(578), change to UNSPECIFIC profile

Warning: [libopenh264 @ 0x149616670] [OpenH264] this = 0x0x600000ec08d0, Warning:bEnableFrameSkip = 0,bitrate can't be controlled for RC_QUALITY_MODE,RC_BITRATE_MODE and RC_TIMESTAMP_MODE without enabling skip frame.

Info: Output #0, mp4, to '/Users/hwkf-marlsen-47932/Documents/sample-3_compress.mp4':

Info:   Metadata:

Info:     encoder         : 
Info: Lavf60.16.100
Info: 

Info:   Stream #0:0
Info: : Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, q=2-31, 400 kb/s
Info: , 
Info: 30 fps, 
Info: 15360 tbn
Info: 

Info:     Side data:

Info:       
Info: cpb: 
Info: bitrate max/min/avg: 400000/0/400000 buffer size: 0 
Info: vbv_delay: N/A
Info: 

Warning: [swscaler @ 0x158b88000] No accelerated colorspace conversion found from yuv420p to bgr24.

Process finished with exit code 0
saudet commented 3 months ago

Please try to use libx264 instead

marlsenwang commented 3 months ago

@saudet thanks for your reply. I change ffmpeg dependency to the gpl version and problem solved

<dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>ffmpeg</artifactId>
            <version>6.1.1-1.5.10</version>
            <classifier>macosx-arm64-gpl</classifier>
        </dependency>