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

How to Switching between audio tracks of MPG file in exoplayer V2? #4406

Closed
donny8chen opened this issue Jun 22, 2018 · 14 comments
Closed

How to Switching between audio tracks of MPG file in exoplayer V2? #4406

donny8chen opened this issue Jun 22, 2018 · 14 comments
Assignees
Labels

Comments

@donny8chen
Copy link

I using exoplayer V2 in our project, and i have a issue as bellow:

How to Switching between audio tracks of MPG file in exoplayer V2?

Yes, I can switch audio tracks on MP4/MKV but MPG.

Cloud anyone let me know the key point or other ?

@tonihei
Copy link
Collaborator

tonihei commented Jun 22, 2018

Switching tracks works the same for all file types and formats. Can you explain in more detail what you did for MP4 and why the same doesn't work for MPG?

@tonihei tonihei self-assigned this Jun 22, 2018
@donny8chen
Copy link
Author

donny8chen commented Jun 25, 2018

Version:ExoPlayer V2 2.8.1
Demo: ExoPlayer/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java

This is a music video in mpeg2 format, I use the Android 6.0 SDK's android.media.MediaExtractor class to read all the track information and get the following tracks:

1、{height=1080, width=1920, mime=video/mpeg2, durationUs=265831733, csd-0=java.nio.ByteArrayBuffer[position=0,limit=22,capacity=22], slice-height=1080, stride=1920}
2、{channel-count=2, mime=audio/mpeg-L2, sample-rate=48000, durationUs=265831733}
3、{channel-count=2, mime=audio/mpeg-L2, sample-rate=48000, durationUs=265831733}

For the same MPG file, useing EXOPlayer V2 to get all the track information, as follows:

EventLogger: tracksChanged [0.93, 0.00, window=0, period=0,
Renderer:0 [
Group:0, adaptive_supported=N/A [[X] Track:0, id=224, mimeType=video/mpeg2, res=1920x1080, supported=YES]
]
Renderer:1 [
Group:0, adaptive_supported=N/A [
[X] Track:0, id=192, mimeType=audio/mpeg-L2, channels=2, sample_rate=48000, supported=YES
]
]
]

Another MKV format file,useing EXOPlayer V2 to get all the track information, as follows:

EventLogger: tracksChanged [0.26, 0.00, window=0, period=0,
Renderer:0 [
Group:0, adaptive_supported=N/A [
[X] Track:0, id=1, mimeType=video/avc, res=720x540, supported=YES
]
]
Renderer:1 [
Group:0, adaptive_supported=N/A [
[X] Track:0, id=2, mimeType=audio/mp4a-latm, channels=2, sample_rate=48000, language=und, supported=YES
]
Group:1, adaptive_supported=N/A [
[ ] Track:0, id=3, mimeType=audio/mp4a-latm, channels=2, sample_rate=48000, language=und, supported=YES
]
]
]

@donny8chen
Copy link
Author

donny8chen commented Jun 25, 2018

@tonihei Thanks a lot for your answers.

I use MediaInfo software to read the file format information as follows:

General
Complete name : D:\StudioProjects2\ExoPlayer\50000445.mpg
Format : MPEG-PS
File size : 272 MiB
Duration : 4 min 25 s
Overall bit rate mode : Variable
Overall bit rate : 8 618 kb/s

Video
ID : 224 (0xE0)
Format : MPEG Video
Format version : Version 2
Format profile : Main@High
Format settings : BVOP
Format settings, BVOP : Yes
Format settings, Matrix : Default
Format settings, GOP : Variable
Duration : 7 s 40 ms
Bit rate mode : Variable
Bit rate : 7 934 kb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate : 29.970 (30000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 0.128
Time code of first frame : 00:00:00:00
Time code source : Group of pictures header
GOP, Open/Closed : Open
Stream size : 6.66 MiB (2%)

Audio #1
ID : 192 (0xC0)
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 2
Duration : 4 min 25 s
Bit rate mode : Constant
Bit rate : 256 kb/s
Channel(s) : 2 channels
Sampling rate : 48.0 kHz
Frame rate : 41.667 FPS (1152 SPF)
Compression mode : Lossy
Stream size : 8.09 MiB (3%)

Audio #2
ID : 193 (0xC1)
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 2
Duration : 4 min 25 s
Bit rate mode : Constant
Bit rate : 256 kb/s
Channel(s) : 2 channels
Sampling rate : 48.0 kHz
Frame rate : 41.667 FPS (1152 SPF)
Compression mode : Lossy
Stream size : 8.09 MiB (3%)

@donny8chen
Copy link
Author

I use DEMO to test, without modifying any code, only modify the media.exolist.json file in the assets directory, just add two video addresses, as follows:
{
         "name": "http BS18K63.mkv",
         "uri": "file:///storage/0E6AAFDD6AAFBFB7/song/BS18K63.mkv"
       },
       {
         "name": "file 50000445.mpg",
         "uri": "file:///storage/0E6AAFDD6AAFBFB7/song/50000445.mpg"
       }
}

@donny8chen
Copy link
Author

There are two problems with playing MPG video:
1、can not seek progess;
2、can not read all audio tracks;

I tried to track the code that reads the track information and found that this class (com.google.android.exoplayer2.extractor.ts.PsExtractor) reads it。

public final class PsExtractor implements Extractor {
...
private boolean foundAllTracks;
private boolean foundAudioTrack;
private boolean foundVideoTrack;
...

@Override

public int read(ExtractorInput input, PositionHolder seekPosition) throws IOException, InterruptedException {
...
PesReader payloadReader = psPayloadReaders.get(streamId);
if (!foundAllTracks) {
if (payloadReader == null) {
ElementaryStreamReader elementaryStreamReader = null;
if (!foundAudioTrack && streamId == PRIVATE_STREAM_1) {
elementaryStreamReader = new Ac3Reader();
foundAudioTrack = true;
} else if (!foundAudioTrack && (streamId & AUDIO_STREAM_MASK) == AUDIO_STREAM) {
elementaryStreamReader = new MpegAudioReader();
The problem arises here. Before the audio track is found, The foundAudioTrack value is false.
If an audio track is found, its forever value is true, and when it is read to the second audio track,
it will not be parsed.

foundAudioTrack = true;
} else if (!foundVideoTrack && (streamId & VIDEO_STREAM_MASK) == VIDEO_STREAM) {
elementaryStreamReader = new H262Reader();
foundVideoTrack = true;
}
if (elementaryStreamReader != null) {
TrackIdGenerator idGenerator = new TrackIdGenerator(streamId, MAX_STREAM_ID_PLUS_ONE);
elementaryStreamReader.createTracks(output, idGenerator);
payloadReader = new PesReader(elementaryStreamReader, timestampAdjuster);
psPayloadReaders.put(streamId, payloadReader);
}
}
if ((foundAudioTrack && foundVideoTrack) || input.getPosition() > MAX_SEARCH_LENGTH) {
foundAllTracks = true;
output.endTracks();
}
}
....
}
}

But I haven't guessed why the author did this , and How to modify it so that it can read all audio track information?

@tonihei
Copy link
Collaborator

tonihei commented Jun 25, 2018

Thanks. I understand your problem now and that looks indeed like a bug.

Can you send us the example file which causes the problems? If you don't want to post it publicly, feel free to send an email to dev.exoplayer@gmail.com with "Issue #4406" in the subject.

@tonihei tonihei added bug and removed question labels Jun 25, 2018
@donny8chen
Copy link
Author

@tonihei Thanks a lot for your answers.

I have sent the file that caused the problem to dev.exoplayer@gmail.com, please check!!

@tonihei
Copy link
Collaborator

tonihei commented Jun 25, 2018

Thanks, I can reproduce the problem and we will provide a fix for this soon.

ojw28 pushed a commit that referenced this issue Jun 28, 2018
Currently we immediately stop searching after we found one video and one
audio track. This change adds some leeway to detect additional tracks.

Issue:#4406

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202455491
@donny8chen
Copy link
Author

@tonihei Thanks a lot for your kind help! this bug has been fixed,But still there are two problems:

Still that same MPG file,There are two problems with playing MPG video:
1、can not seek progess;
2、SimpleExoPlayer.getDuration(),This method returns 1 ;

I use the Android 6.0 SDK's android.media.MediaExtractor class to read all the track information, each track, The durationUs is 265831733:

1、{height=1080, width=1920, mime=video/mpeg2, durationUs=265831733, csd-0=java.nio.ByteArrayBuffer[position=0,limit=22,capacity=22], slice-height=1080, stride=1920}
2、{channel-count=2, mime=audio/mpeg-L2, sample-rate=48000, durationUs=265831733}
3、{channel-count=2, mime=audio/mpeg-L2, sample-rate=48000, durationUs=265831733}

@tonihei
Copy link
Collaborator

tonihei commented Jul 4, 2018

What's wrong with the duration? It's about 4 minutes and 25 seconds - the same as shown by the media info software you used above .

@donny8chen
Copy link
Author

@tonihei Thanks a lot for your answers.

The problem is :
I can get the total seconds of any kind of video but MPG format with using EXO player . I found the exo always return the result what is C.TIME_UNSET. The issue will lead EXO's Seek Function will not work.

Also I can get the real data if I using the android.media.MediaExtractor class under Android 6.0 SDK.

So as above desc , I just want to get your help for how to get the Duration Time of MPG file in EXO .

BR,

@ojw28
Copy link
Contributor

ojw28 commented Jul 4, 2018

See here for why PS streams are currently not seekable. @botaydotcom is currently looking at determining stream duration + enabling seeking for non-seek-friendly formats, so we might be able to fix this fairly soon.

@tonihei
Copy link
Collaborator

tonihei commented Jul 4, 2018

Closing because the bug is solved and I think @ojw28 kindly answered your follow up question.

@tonihei tonihei closed this as completed Jul 4, 2018
ojw28 pushed a commit that referenced this issue Jul 23, 2018
Currently we immediately stop searching after we found one video and one
audio track. This change adds some leeway to detect additional tracks.

Issue:#4406

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=202455491
@khizar1556

This comment has been minimized.

@google google locked and limited conversation to collaborators Nov 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants