Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FrameGrabber When reading a frame, the audio encoded in G722 format cannot be read #2316

Open
water-rookie opened this issue Feb 13, 2025 · 17 comments

Comments

@water-rookie
Copy link

When the frame catcher reads the frame, it cannot read the audio in G722 format. Instead, the audio format obtained is MP2

@saudet
Copy link
Member

saudet commented Feb 13, 2025

Try to set the format by calling setFormat() before calling start(). There is also setAudioCodec() if what you want to set is the codec instead.

@water-rookie
Copy link
Author

Set the audio decoder to G.722, but it is invalid, still can't get the audio information

@saudet
Copy link
Member

saudet commented Feb 14, 2025

Please provide the code you are using and the error message you are getting.

@water-rookie
Copy link
Author

        FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
        grabber.setAudioCodec(avcodec.AV_CODEC_ID_ADPCM_G722);
        grabber.setVideoCodec(avcodec.AV_CODEC_ID_H264);
        grabber.setOption("loglevel", "debug");
        grabber.start();
        log.info("imageWidth:" + grabber.getImageWidth());
        log.info("audio_c: " + grabber.getAudioCodecName());

        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputFile, grabber.getImageWidth(), grabber.getImageHeight());
        recorder.setAudioChannels(grabber.getAudioChannels());
        recorder.setOption("loglevel", "debug");
        recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
        recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);
        recorder.start();

        Frame frame;
        while ((frame = grabber.grab()) != null) {
            if (frame.image != null) {
                recorder.record(frame);
            } else if (frame.samples != null) {
                recorder.recordSamples(frame.sampleRate, frame.audioChannels, frame.samples);
            }
        }
        grabber.close();
        recorder.close();

@water-rookie
Copy link
Author

[mp2 @ 00000268510d8f40] Header missing
Input #0, mpeg, from 'D:\tools\HCISUPSDKV2.5.1.35_build20241101_Win64_ZH\demo\ISUPSDK_JAVA_DEMO_BASE\ISUPSDK_JAVA_DEMO_BASE\outputFiles\previewVideo.mp4':
Duration: 25:19:28.73, start: 4294.978000, bitrate: 0 kb/s
Stream #0:0[0x1e0]: Video: h264 (Baseline), yuv420p(tv, unknown/bt470bg/unknown, progressive), 1280x960, 90k tbr, 90k tbn
Stream #0:1[0x1c0]: Audio: mp2, 44100 Hz, stereo, s16p, 160 kb/s
[libopenh264 @ 000002685273a100] [OpenH264] this = 0x0000026857bde080, Warning:layerId(0) doesn't support profile(578), change to UNSPECIFIC profile
[libopenh264 @ 000002685273a100] [OpenH264] this = 0x0000026857bde080, Warning:bEnableFrameSkip = 0,bitrate can't be controlled for RC_QUALITY_MODE,RC_BITRATE_MODE and RC_TIMESTAMP_MODE without enabling skip frame.
Output #0, mp4, to 'C:\Users\hzdou\Desktop\output11111.mp4':
Metadata:
encoder : Lavf61.7.100
Stream #0:0: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x960, q=2-31, 400 kb/s, 30 fps, 15360 tbn
Side data:
cpb: bitrate max/min/avg: 400000/0/400000 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 64 kb/s
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing
[mp2 @ 0000026852739d40] Header missing

@water-rookie
Copy link
Author

Image

@saudet
Copy link
Member

saudet commented Feb 14, 2025

Please also try to call setFormat() to set the format to the correct value.

@water-rookie
Copy link
Author

I set format to mpeg and the result is still the same

@water-rookie
Copy link
Author

        FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputFile);
        grabber.setAudioCodec(avcodec.AV_CODEC_ID_ADPCM_G722);
        grabber.setVideoCodec(avcodec.AV_CODEC_ID_H264);
        grabber.setOption("loglevel", "debug");
        grabber.setFormat("mpeg");
        grabber.start();
        log.info("imageWidth:" + grabber.getImageWidth());
        log.info("audio_c: " + grabber.getAudioCodecName());

@saudet
Copy link
Member

saudet commented Feb 14, 2025

Calling setAudioCodecName() instead of setAudioCodec() might work better?

@water-rookie
Copy link
Author

Is audioCodecName set to G722?

@water-rookie
Copy link
Author

grabber.setAudioCodecName("ADPCM_G722");

@water-rookie
Copy link
Author

Still can't

@water-rookie
Copy link
Author

Image

@water-rookie
Copy link
Author

Audio is still identified as Mp2

@saudet
Copy link
Member

saudet commented Feb 15, 2025

It's probably grabber.setAudioCodecName("g722"); before calling start(). Check the log for any error messages

@water-rookie
Copy link
Author

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants