RedReader icon indicating copy to clipboard operation
RedReader copied to clipboard

Allow videos to be unmuted

Open QuantumBadger opened this issue 7 years ago • 24 comments

Some videos have an audio track, but this is currently muted. It would be good to have some way of unmuting such videos.

QuantumBadger avatar Sep 24 '17 09:09 QuantumBadger

What would be the complexity of doing this and where would one start? So many more things are now v.redd.it that this seems like an important feature to have.

ajgoda90 avatar Jan 09 '18 18:01 ajgoda90

Hi @ajgoda90, sorry for the delay in responding.

The MediaVideoView control is used to render the video:

https://github.com/QuantumBadger/RedReader/blob/master/src/main/java/org/quantumbadger/redreader/views/MediaVideoView.java

Which is used in the ImageViewActivity:

https://github.com/QuantumBadger/RedReader/blob/master/src/main/java/org/quantumbadger/redreader/activities/ImageViewActivity.java

The videos themselves are obtained from reddit using the following URL:

final String imageUrl = "https://v.redd.it/" + imgId + "/DASH_600_K";

https://github.com/QuantumBadger/RedReader/blob/master/src/main/java/org/quantumbadger/redreader/common/LinkHandler.java#L688

I'm not sure whether the video file returned actually has audio in it, or whether MPEG-DASH splits it out. If you have a link to a reddit video with an audio track, it should be possible to play it back in e.g. VLC and see the details.

I suspect the issue is that the audio is separate, in which case we need to figure out how to download the audio from reddit.

Hope that helps, let me know if anything is unclear :)

QuantumBadger avatar Jan 16 '18 15:01 QuantumBadger

So it seems the audio is a separate mp4 that's at the v.redd.it/imgid/audio url. Looking into how we can sync up video and audio files I found this library which can handle that:

https://github.com/protyposis/MediaPlayer-Extended

Apache 2 licensed stuff can be included in a GPL 3 project so that'll work. What are your thoughts on using it?

ajgoda90 avatar Jan 21 '18 18:01 ajgoda90

Thank you for doing the research -- that library looks promising, I don't have any objections to it.

One thing to bear in mind is that the video/audio will need to be downloaded using RedReader's cache system as currently, so it won't be as simple as instantiating that library and passing it the URL.

Currently, images and videos less than 15MB are precached (on WiFi) when viewing the post list. This logic may need changing to download the video and audio separately where necessary.

Similarly, ImageViewActivity may need to set up two parallel requests through the cache, rather than just one as currently.

QuantumBadger avatar Jan 23 '18 20:01 QuantumBadger

@QuantumBadger Hey just tuning in, having the exact same issues with my implementation with Slide.

I ended up switching over to ExoPlayer which allows native DASH .mpd streaming (adding /DASHPlaylist.mpd returns a playlist with different bitrates, channels, and audio which I used instead of adding /DASH_600_K to the ID and downloading it as an MP4 as RedReader does) which natively supports audio, but it has no way of interfacing with my caching system and the progress of download/file size indicator have no way to interface with ExoPlayer's more closed DASH streaming system. ExoPlayer also has pretty aggressive bitrate switching, and tends to use much lower quality streams than I would like (Reddit automatically splits videos into many different streams with varying bitrates/sizes).

Using the fallback_url from the submission JSON actually lets you get the original quality video DASH link which is actually encoded as an mp4 (600_k are usually pretty low resolution), and this works with my caching/loading system, but audio is split into v.redd.it/VIDEOID/audio as another MP4, which makes combining the two streams pretty difficult (mp3/mp4 splicing pretty straightforward, but MP4 video/MP4 audio combinations are not).

Seems like we're stuck between a rock and a hard place, the only real solution I see is using a library like FFMEG to combine two streams into one, which would work with directly with my caching/display system, but adds a ton of unnecessary complication to the code and makes a library do something it wasn't really meant to do. Honestly it's pretty ridiculous Reddit has decided to only allow for DASH streaming instead of a more ubiquitous standard like an actual MP4 with audio...

ccrama avatar Feb 01 '18 20:02 ccrama

Thanks for the info @ccrama.

audio is split into v.redd.it/VIDEOID/audio as another MP4

Android provides the MediaExtractor class for demuxing containers like mp4, and MediaMuxer for combining them. If those are suitable, they'd avoid the need to bring in ffmpeg.

QuantumBadger avatar Feb 02 '18 20:02 QuantumBadger

Unfortunately the MediaMuxer requires API 18, while I am trying to retain support for API 15. Might be time to raise the min SDK, but will continue looking for solutions that are more backwards compatible. Thank you for the info though! Will update you if I find another a solution

ccrama avatar Feb 03 '18 20:02 ccrama

Unfortunately the MediaMuxer requires API 18, while I am trying to retain support for API 15.

As far as RedReader goes, I'd be happy to have two code paths -- one for API 18+, and one for 17 and below. That way users on up-to-date versions of Android will have audio, and users on older versions at least won't experience a regression.

QuantumBadger avatar Feb 03 '18 20:02 QuantumBadger

@QuantumBadger ended up using this library which worked beautifully, seems to be supporting older API versions as well. Will link to my commit later if you'd like to see how I implemented it

ccrama avatar Feb 03 '18 22:02 ccrama

The MediaPlayer-Extended library only needs API 16 if we can make that work for our needs. I haven't had a ton of time to work on it, but I do know the library drops right into place as it promises.

ajgoda90 avatar Feb 03 '18 22:02 ajgoda90

Is there any update on this? None of the video options (including vlc) play audio for v.reddit links.

ghost avatar Aug 31 '18 07:08 ghost

Any progress on this?

TippyLion28 avatar Nov 19 '18 22:11 TippyLion28

I haven't had time to make any progress, but I still think the MediaPlayer-Extended library would be a good choice. As QuantumBadger mentioned, the cache part was complicated and that's where I was stuck last time I looked at it. I can try to get back to it during the holidays, unless someone else wants to give it a go.

ajgoda90 avatar Nov 19 '18 22:11 ajgoda90

I've spent the last few hours implementing this, and it seems to work :)

https://github.com/QuantumBadger/RedReader/commit/77a2201291f9567d9f5efc80812eaa24e1aed012

I've switched to ExoPlayer to merge the streams, but rather than giving it the .mpd file URL, the app now manually parses the .mpd file to find the video and audio, downloads them in parallel using the usual cache manager, and then hands the two local files to ExoPlayer.

It's in Alpha 168, so please try it out and let me know if it works:

https://redreader.org/alpha

Stuff that still needs to be added:

  • Ability to mute videos (in general). A preference for this would be nice.
  • When sharing reddit videos, the comment page link should be shared rather than the video-only link
  • Same with viewing in external browser

QuantumBadger avatar Nov 24 '18 17:11 QuantumBadger

The ability to mute videos has now been added.

QuantumBadger avatar Feb 02 '19 18:02 QuantumBadger

Any update on this? Also, saved videos don't have audio on them.

spicadays avatar Jul 11 '20 05:07 spicadays

Any update on this? Also, saved videos don't have audio on them.

That's the only remaining issue for this ticket (adding audio to saved videos). I'm not aware of any activity related to this ticket, but obviously anyone is free to submit a PR using the solution I mentioned above (MediaMuxer on Android 18+).

QuantumBadger avatar Jul 15 '20 21:07 QuantumBadger

Any update on this? Also, saved videos don't have audio on them.

That's the only remaining issue for this ticket (adding audio to saved videos). I'm not aware of any activity related to this ticket, but obviously anyone is free to submit a PR using the solution I mentioned above (MediaMuxer on Android 18+).

Hi! I believe based on your response you are saying you can then SHARE videos with audio, correct? If so how is that possible? Sharing either using the 'Share' button or copying/pasting the URL from the Reddit post all leads to the v.redd.it link with no audio stream.

x4nit0s avatar Jul 22 '20 12:07 x4nit0s

based on your response you are saying you can then SHARE videos with audio, correct?

Sorry, that's not possible yet.

I'm not sure it'll ever be possible to share videos with audio via a link, other than by linking to the reddit comments page. (Maybe possible to share the DASH/m3u8 playlist, but I doubt most devices would support opening these directly).

Regarding sharing not via a link (i.e. attaching directly), this should be possible to add once saving with audio is implemented, as it relies on the same multiplexing logic.

QuantumBadger avatar Jul 23 '20 10:07 QuantumBadger

I found a way but I don't know if it is a good idea. There is a Free Software alternative front-end for reddit.com called teddit.net.

Original Reddit url: https://reddit.com/r/shittyrobots/comments/lxmfys/difficult_to_master_a_robots_frustrating_path_to/

Teddit url: https://teddit.net/r/shittyrobots/comments/lxmfys/difficult_to_master_a_robots_frustrating_path_to/

When you share a video from Reddit with the share button you get an url like: https://v.redd.it/we8buxwc01l61/DASH_1080.mp4?source=fallback

Which has no audio. But at the teddit.net page you can get a direct link to the video with audio like this: https://teddit.net/vids/we8buxwc01l61.mp4

This is just an idea maybe its an interesting approach that I found @QuantumBadger

vbramselaar avatar Mar 04 '21 21:03 vbramselaar

Thanks for the info @vbramselaar! I think it would still be good to do the merge locally on the device using MediaMuxer to avoid the download from the 3rd party server.

QuantumBadger avatar Mar 05 '21 20:03 QuantumBadger

Ah no problem @QuantumBadger, I did find that the url https://teddit.net/vids/we8buxwc01l61.mp4 does not always work anyway. I think that teddit.net caches the video when you visit the normal post with comments, because after a while the direct link does not work for me anymore. It went like this:

  1. visit direct link: no video
  2. visit post with comment section link: video and comments
  3. visit direct link again: a video with audio

So not really a good idea of mine, but it was worth trying.

vbramselaar avatar Mar 06 '21 20:03 vbramselaar

@vbramselaar No problem, I appreciate the suggestion! Thanks again.

QuantumBadger avatar Mar 07 '21 22:03 QuantumBadger

I've implemented video/audio muxing in the latest alpha :) This means that if you save or share a video file from v.redd.it, it should have audio included. Please feel free to test the latest alpha and let me know if it works (note: you must be running Android 4.3 or above).

I'd still like to do the following before closing this ticket:

  • Add a loading indicator while the video is being muxed
  • Fix audio when sharing a link to the video, as opposed to the file itself

QuantumBadger avatar Nov 28 '21 23:11 QuantumBadger