bytedeco/javacv

when trying to seek audio I keep getting

Open

#1 346 ouverte le 4 déc. 2019

Voir sur GitHub
 (3 commentaires) (0 réactions) (0 assignés)Java (1 583 forks)batch import
help wantedquestion

Métriques du dépôt

Stars
 (6 985 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 0.0 Hz, 16 bit, 0 channels, 0 bytes/frame, big-endian is supported.

what is causing the sample rate to be zero? I'm running MAC OSX 10.12 and using java 8

which somtimes leads to

ava(20454,0x700004c2c000) malloc: *** error for object 0x7f82a9bc5d00: double free
*** set a breakpoint in malloc_error_break to debug

or


[NULL @ 0x7ff1ef060c00] sample/frame number mismatch in adjacent frames
[NULL @ 0x7ff1ef060c00] crc check failed from offset 902 (frame 2968) to 1926 (frame 2968)
[flac @ 0x7ff1ef555400] read_timestamp() failed in the middle
objc[20627]: Hash table corrupted. This is probably a memory error somewhere. (table at 0x7fffb32bccc8, buckets at 0x7ff1ef26d400 (4096 bytes), 256 buckets, 10 entries, 48 tombstones, data 0xc00000 0x0 0x0 0xffffffffffffffff)

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

here is my playing code


public class FFMpegPlayer implements Player {
    private  SourceDataLine line;
    private  AudioFormat format;
    private FFmpegFrameGrabber frameGrabber;
    MusicPlayer player;
    public FFMpegPlayer(MusicPlayer player) {
        this.player = player;
    }
    @Override
    public boolean play(File audioFile, int startSeconds, int playStartSeconds, int endSeconds, float volume, float pan) { // plays a song with a given  j audiotagger audio file
            frameGrabber = new FFmpegFrameGrabber(audioFile.getAbsolutePath());
        try {
            frameGrabber.start();
            format=new AudioFormat(frameGrabber.getSampleRate(), 16, frameGrabber.getAudioChannels(),true, true );
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
            line= (SourceDataLine) AudioSystem.getLine(info);
            line.open(format);
            setPan(pan); // set line pan and volume
            setVolume(volume);
            line.start();
            double lengthInSeconds=frameGrabber.getLengthInTime()/1000000;
            double framesPerSecond=frameGrabber.getLengthInAudioFrames()/lengthInSeconds;
         
            if(endSeconds==0){
                endSeconds=(int)(lengthInSeconds);
            }
            double startFrame = ((startSeconds + playStartSeconds) * (framesPerSecond));// calculate start frame for ffmpeg.
        
            frameGrabber.setAudioFrameNumber((int) startFrame);// set the start frame.
            frameGrabber.setVideoBitrate(0); // set to avoid seg faults
            frameGrabber.setImageHeight(0);//""
            frameGrabber.setImageWidth(0);//""

            Thread thread=Thread.currentThread();
            int frames = (int) (playStartSeconds*framesPerSecond);// total number of frames being played
            int endFrame= (int) (endSeconds*framesPerSecond);// last frame number
            player.startTime();// start the displayed time counter
            while (!thread.interrupted()) {
                Frame frame = frameGrabber.grabSamples();
                if (frame == null || frames >= endFrame ) {// frame is null on the end point is reached terminate playing
                    System.out.println("Stopped " + frame);
                    break;
                }
                else if (frame.samples != null) {
                    ShortBuffer channelSamplesFloatBuffer = (ShortBuffer) frame.samples[0];
                    channelSamplesFloatBuffer.rewind();
                    ByteBuffer outBuffer = ByteBuffer.allocate(channelSamplesFloatBuffer.capacity() * 2);
                    for (int i = 0; i < channelSamplesFloatBuffer.capacity(); i++) {
                        short val = (short)((double) channelSamplesFloatBuffer.get(i) );
                        outBuffer.putShort(val);
                    }
                    line.write(outBuffer.array(), 0, outBuffer.capacity());
                    outBuffer.clear();
                    frames++;

                }
            }
            frameGrabber.stop();
            frameGrabber.release();
                line.stop();
                line.close();
                line.drain();
        } catch (FrameGrabber.Exception e) {
            new OptionPane().showOptionPane("The File Cannot Be Played"+e.getStackTrace(), "OK");
        } catch (LineUnavailableException e) {
            new OptionPane().showOptionPane("The File Cannot Be Played"+e.getStackTrace(), "OK");
        }
        player.stopTime();
        return true;
    }



Guide contributeur