Comments (11)
Ah, that's correct ! Would you like to set up a PR?
from transcoder.
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.
@pawegio what is the value of hasAudioMetadata
in your case? null, or just something different than yes
?
from transcoder.
the value is null
from transcoder.
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.
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.
In 0.7.2 my workaround no longer works...
from transcoder.
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.
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.
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.
@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)
- Trimming the start position slows transcode
- video trimming issue
- [Bug]Sometimes the compressed video file would be corrupted.
- Unexpected error while transcoding. android.media.MediaCodec$CodecException: Error 0xffffec77 HOT 1
- MPEG4 movie File Encoding fails(H.264) HOT 1
- Does not transcode when setSpeed(0.5F) or less 1 HOT 1
- java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.otaliastudios.transcoder.source.DataSource.isInitialized()' on a null object reference HOT 5
- aspect ration in merge HOT 1
- BlankAudioDataSource makes transcoding stuck forever. HOT 8
- java.lang.IllegalStateException: Can't stop due to wrong state(INITIALIZED) HOT 1
- java.lang.NullPointerException: buffers.getOutputBuffer(result) must not be null
- How to get demo app?
- Output to a Surface instead of a file HOT 1
- BufferOverflowException (ref #163) #164 is not fixed in implementation 'com.github.jumperson:transcoder:0.10.4.2' HOT 2
- Failed to initialize video/dolby-vision
- Trim and Merge issue
- Update the nuget to the latest version
- HDR Tone Mapping
- [Q] MP4 concatenation with Video PassThroughTrackStrategy does nothing
- Video returns as a 0 bytes file for high quality videos, specifically with videos with HEVC codec
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transcoder.