Giter VIP home page Giter VIP logo

Comments (11)

natario1 avatar natario1 commented on May 22, 2024 1

Ah, that's correct ! Would you like to set up a PR?

from transcoder.

pawegio avatar pawegio commented on May 22, 2024

only workaround for me is applying in the builder:

.setAudioTrackStrategy(
    if (file.hasAudioTrack) {
        DefaultAudioStrategy.Builder().build()
    } else {
        RemoveTrackStrategy()
    }
)
.addDataSource(file.absolutePath)

where hasAudioTrack is extension function defined:

private val File.hasAudioTrack: Boolean
    get() {
        val hasAudioMetadata = MediaMetadataRetriever().apply {
            setDataSource(absolutePath)
        }.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_AUDIO)
        return hasAudioMetadata != null && hasAudioMetadata == "yes"
    }

from transcoder.

natario1 avatar natario1 commented on May 22, 2024

@pawegio what is the value of hasAudioMetadata in your case? null, or just something different than yes?

from transcoder.

pawegio avatar pawegio commented on May 22, 2024

the value is null

from transcoder.

natario1 avatar natario1 commented on May 22, 2024

I see. I'm not sure if we can trust that all files that have audio will have this key set.

Could you send here your file?

from transcoder.

pawegio avatar pawegio commented on May 22, 2024

Unfortunately, I can't send you the file, but I can share with you MediaFormat map value passed to decodeMediaFormat() for type AUDIO:

{track-id=1, level=512, mime=video/avc, frame-count=114, profile=1, language=```, display-width=1088, csd-1=java.nio.HeapByteBuffer[pos=0 lim=8 cap=8], durationUs=5700000, display-height=512, width=1088, rotation-degrees=90, max-input-size=84261, frame-rate=20, height=512, csd-0=java.nio.HeapByteBuffer[pos=0 lim=13 cap=13]}

Btw. after updating to 0.7.2 (and without my workaround), the call stack for exception is now:

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
    at com.otaliastudios.transcoder.source.DefaultDataSource.selectTrack(DefaultDataSource.java:62)
    at com.otaliastudios.transcoder.engine.MediaFormatProvider.decodeMediaFormat(MediaFormatProvider.java:87)
    at com.otaliastudios.transcoder.engine.MediaFormatProvider.provideMediaFormat(MediaFormatProvider.java:42)
    at com.otaliastudios.transcoder.engine.Engine.computeTrackStatus(Engine.java:121)
    at com.otaliastudios.transcoder.engine.Engine.transcode(Engine.java:323)
    at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:134)
    at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:124)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)

from transcoder.

pawegio avatar pawegio commented on May 22, 2024

In 0.7.2 my workaround no longer works...

from transcoder.

natario1 avatar natario1 commented on May 22, 2024

I'd like to see the MediaFormat map that is passed as an input format to DefaultAudioStrategy in 0.7.1.

About 0.7.2, not sure why you are getting a video format for type=AUDIO, but we can investigate this later.

from transcoder.

pawegio avatar pawegio commented on May 22, 2024

0.7.1:

DefaultAudioStrategy.createOutputFormat

input media format:

{track-id=1, level=512, mime=video/avc, frame-count=114, profile=1, language=```, display-width=1088, csd-1=java.nio.HeapByteBuffer[pos=0 lim=8 cap=8], durationUs=5700000, display-height=512, width=1088, rotation-degrees=90, max-input-size=84261, frame-rate=20, height=512, csd-0=java.nio.HeapByteBuffer[pos=0 lim=13 cap=13]}

so it's video format as well.

I think the problem is with DefaultDataSource.getTrackFormat function that returns video format instead of null.

@Nullable
@Override
public MediaFormat getTrackFormat(@NonNull TrackType type) {
    if (mFormats.has(type)) return mFormats.get(type);
    ensureExtractor();
    int trackCount = mExtractor.getTrackCount();
    MediaFormat format = null;
    for (int i = 0; i < trackCount; i++) {
        format = mExtractor.getTrackFormat(i); <-- Is it correct to assign value here?
        String mime = format.getString(MediaFormat.KEY_MIME);
        if (type == TrackType.VIDEO && mime.startsWith("video/")) {
            mIndex.set(TrackType.VIDEO, i);
            break;
        }
        if (type == TrackType.AUDIO && mime.startsWith("audio/")) {
            mIndex.set(TrackType.AUDIO, i);
            break;
        }
    }
    mFormats.set(type, format);
    return format;
}

so later video format is used as audio input format here:

MediaFormat inputFormat = source.getTrackFormat(type);
if (inputFormat != null) {
    inputFormats.add(inputFormat);
} else if (sources.size() > 1) {
    throw new IllegalArgumentException("More than one source selected for type " + type
            + ", but getTrackFormat returned null.");
}

from transcoder.

joeShuff avatar joeShuff commented on May 22, 2024

In version 0.7.3 I am still getting the same issue with a file that doesn't have an audio track. Stack Trace:

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference 
        at com.otaliastudios.transcoder.source.DefaultDataSource.selectTrack(DefaultDataSource.java:62)
        at com.otaliastudios.transcoder.engine.Engine.openCurrentStep(Engine.java:149)
        at com.otaliastudios.transcoder.engine.Engine.getCurrentTrackTranscoder(Engine.java:219)
        at com.otaliastudios.transcoder.engine.Engine.transcode(Engine.java:368)
        at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:134)
        at com.otaliastudios.transcoder.Transcoder$1.call(Transcoder.java:124)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)

I am simply calling
builder.addDataSource(filePath)

I am not sure whether the documentation is just not complete for the new fix or not?

I implemented your hasAudioTrack method and that is correctly reporting that the file I have doesn't have an audio track.

Any help is appreciated. Feel free to ask for more info

from transcoder.

nzackoya avatar nzackoya commented on May 22, 2024

@joeShuff you're right it is still happening, you can try the workaround below for now

val transcoder = Transcoder.into(toPath)
.addDataSource(TrackType.VIDEO, source)
.setListener(transcoderListener)

if (source.getTrackFormat(TrackType.AUDIO) != null) {
  transcoder.addDataSource(TrackType.AUDIO, source)
}
transcoder.transcode()

from transcoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.