question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change the dubbing sound of the video while playing a video

See original GitHub issue

Description

Hi I have 1 video (.mp4), 2 audio files (.aac/.mp3) and 3 subtitle files (.vtt).

What do i want ? for example, the default language of the video is English. When I change the sound the video should resume and the sound of the video dubbing should be in French. As in netflix application.

I am trying to do this with the following code.

Format format_audio_en = Format.createAudioSampleFormat("en", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, Format.NO_VALUE, 44100, null, null, C.SELECTION_FLAG_DEFAULT, "en");
Format format_audio_de = Format.createAudioSampleFormat("de", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.NO_VALUE, Format.NO_VALUE, 44100, null, null, 0, "de");

SingleSampleMediaSource audio_source_de = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse("http://*******/sound_de.aac"), format_audio_de, C.TIME_UNSET);
SingleSampleMediaSource audio_source_en = new SingleSampleMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse("http://*******/sound_en.aac"), format_audio_en, C.TIME_UNSET);

MediaSource videoSource = buildMediaSource(uri, dataSourceFactory);

MediaSource[] mediaSourceList = new MediaSource[3];
mediaSourceList[0] = videoSource;
mediaSourceList[1] = audio_source_en ;
mediaSourceList[2] = audio_source_de ;
    

MergingMediaSource mergingMediaSource = new MergingMediaSource(mediaSourceList);

player.setPlayWhenReady(playWhenReady);
player.seekTo(playbackPosition);
player.prepare(mergingMediaSource, false, false);


But when I use it this way, I get an error.

E/ExoPlayerImplInternal: Internal runtime error.
    java.lang.IllegalStateException: Buffer too small (524288 < 2241155)
        at com.google.android.exoplayer2.decoder.DecoderInputBuffer.createReplacementByteBuffer(DecoderInputBuffer.java:167)
        at com.google.android.exoplayer2.decoder.DecoderInputBuffer.ensureSpaceForWrite(DecoderInputBuffer.java:117)
        at com.google.android.exoplayer2.source.SingleSampleMediaPeriod$SampleStreamImpl.readData(SingleSampleMediaPeriod.java:334)
        at com.google.android.exoplayer2.BaseRenderer.readSource(BaseRenderer.java:308)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.java:1028)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:658)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:575)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:326)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:146)
        at android.os.HandlerThread.run(HandlerThread.java:61)

I do this with HLS. Elephants Dream Hls Video have two sound (english and spanish) I can easily change the dubbing sound when I use the following code. However, I have mp4 (video) and mp3 / aac (audio) files.

 trackSelector.setParameters(trackSelector.getParameters().buildUpon().setMaxVideoSizeSd()
.setPreferredTextLanguage(subTextLanguage)
.setPreferredAudioLanguage("<en or es>").build());

I looked at these

#4600 #4698

How can I do what I want using mp4 (video) and mp3 (audio) files?

I hope you can help, thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ojw28commented, Feb 13, 2020

Glad you got it working!

0reactions
mustafaberk1996commented, Feb 13, 2020

thank you so much @ojw28

I got what I wanted.

First of all, I added language information to my audio files with this program. and then I edited the code like this;

    Uri uri_sound_en = Uri.parse("http://********/lm_sound_en.mka");
    Uri uri_sound_tr = Uri.parse("http://********/lm_sound_tr.mka");
    soundSourceTR = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(getApplicationContext(), getPackageName())).createMediaSource(uri_sound_tr);
    soundSourceEN = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(getApplicationContext(), getPackageName())).createMediaSource(uri_sound_en);

    Uri videoUri = Uri.parse("http://********/lm_video.mp4");
    videoSource = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(getApplicationContext(), getPackageName())).createMediaSource(videoUri);
    mergingMediaSource = new MergingMediaSource(soundSourceEN, soundSourceTR, videoSource);
    player.prepare(mergingMediaSource, false, false);

for english voice

trackSelector.setParameters(trackSelector.getParameters().buildUpon()
.setPreferredAudioLanguage("eng").build());

for turkish voice

trackSelector.setParameters(trackSelector.getParameters().buildUpon()
.setPreferredAudioLanguage("tur").build());

the issue can be closed, thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Add Dubbing Voice Over to Videos in 4 Steps
Learn how to add voice over to video, dubbing the audio into another language. Understand localized translation and lip-syncing.
Read more >
Replace Your Voice! - How To Make A Dubbing Video
Have you wanted to learn how to making a dubbing video and replace your voice? Today I'll teach you how to replace the...
Read more >
How to change voice in a video - YouTube
Get Movavi Video Editor Plus and the Vlogger Essentials effects bundle at 15% off! https://www.movavi.com/buy-videoeditorplusyear ...
Read more >
Adding Sound to a Movie: How to Dub Audio Over Video
Open the audio mixer by pressing the "M" key and adjust the volume of all the audio tracks. Be sure to check the...
Read more >
Video Voice Dubbing Changer - - Apps on Google Play
Video Voice Dubbing Changer - Audio Video Mixerwith you can now easily replace a video with bad quality sound with your own voice...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found