ios 如何仅流式传输来自 YouTube 的视频的声音?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10282908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:00:27  来源:igfitidea点击:

How can I stream only the sound of a video from YouTube?

objective-ciosaudiostreamyoutube

提问by David

I would like to stream only sound from youtube. I need this for IOS but others can be ok. I have searched on stackoverflow but I couldn't find. Because I don't want to use another software, I want to directly stream only sound of youtube video by code. Also It should work on background.

我只想从 youtube 播放声音。我需要这个用于 IOS,但其他人可以。我在 stackoverflow 上搜索过,但找不到。因为我不想使用其他软件,所以我想直接通过代码仅流式传输 youtube 视频的声音。它也应该在后台工作。

回答by enigmaticPhysicist

Flashgot (for Firefox) has a way to download only the audio of a Youtube video. It exposes links to the audio that looks like this:

Flashgot(适用于 Firefox)有一种方法可以只下载 Youtube 视频的音频。它公开指向音频的链接,如下所示:

https://r3---sn-p5qlsu7d.googlevideo.com/videoplayback?id=887ce37c617a3225&itag=141&source=youtube&requiressl=yes&gcr=ca&ratebypass=yes&mime=audio%2Fmp4&gir=yes&clen=4012348&lmt=1409362978343745&dur=125.828&signature=0A00B9B16BB6EF3192DF33EEF9B2AB67F66F501F.0B649D407144B914A7CC7BE00E795B5BD1B9D932&upn=VFAbXgDGSU8&key=cms1&fexp=900718%2C924231%2C924637%2C927622%2C930809%2C931354%2C932404%2C9405454%2C941004%2C943917%2C945066%2C947209%2C947218%2C948124%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201&sver=3&ip=24.235.37.181&ipbits=0&expire=1419930614&sparams=clen,dur,expire,gcr,gir,id,ip,ipbits,itag,lmt,mime,mm,ms,mv,ratebypass,requiressl,source&cmbypass=yes&req_id=3eb2c618c54ca3ee&redirect_counter=2&cms_redirect=yes&mm=26&ms=tsu&mt=1419909012&mv=m

https://r3---sn-p5qlsu7d.googlevideo.com/videoplayback?id=887ce37c617a3225&itag=141&source=youtube&requiressl=yes&gcr=ca&ratebypass=yes&mime=audio%2Fmp4&gir=yes&clen=4012348&lmt=1409362978343745&dur=125.828&signature=0A00B9B16BB6EF3192DF33EEF9B2AB67F66F501F.0B649D407144B914A7CC7BE00E795B5BD1B9D932&upn=VFAbXgDGSU8&key = CMS1&FEXP = 900718%2C924231%2C924637%2C927622%2C930809%2C931354%2C932404%2C9405454%2C941004%2C943917%2C945066%2C947209%2C947218%2C948124%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201&sver = 3&IP = 24.235.37.181 &ipbits = 0&到期= 1419930614&sparams = CLEN,DUR,到期,GCR,GIR,ID,IP,ipbits,ITAG,LMT,MIME,毫米,MS,MV,ratebypass,requiressl,源&cmbypass = YES&REQ_ID = 3eb2c618c54ca3ee&redirect_counter = 2&cms_redirect = YES&毫米= 26&MS = tsu&mt=1419909012&mv=m

OK, so that is a very big link. This is the same link dissected into pieces:

好的,这是一个非常大的链接。这是分解为多个部分的相同链接:

https://r3---sn-p5qlsu7d.googlevideo.com/videoplayback?id=887ce37c617a3225
&itag=141
&source=youtube
&requiressl=yes
&gcr=ca
&ratebypass=yes
&mime=audio/mp4 #Here's where audio only is specified.
&gir=yes
&clen=4012348
&lmt=1409362978343745
&dur=125.828
&signature=0A00B9B16BB6EF3192DF33EEF9B2AB67F66F501F.0B649D407144B914A7CC7BE00E795B5BD1B9D932
&upn=VFAbXgDGSU8
&key=cms1
&fexp=900718,924231,924637,927622,930809,931354,932404,9405454,941004,943917,945066,947209,947218,948124,952302,952605,952901,955301,957103,957105,957201
&sver=3
&ip=24.235.37.181 #Oh, look. My IP address.
&ipbits=0
&expire=1419930614
&sparams=clen,dur,expire,gcr,gir,id,ip,ipbits,itag,lmt,mime,mm,ms,mv,ratebypass,requiressl,source
&cmbypass=yes
&req_id=3eb2c618c54ca3ee
&redirect_counter=2
&cms_redirect=yes
&mm=26
&ms=tsu
&mt=1419909012
&mv=m

Very interesting. This enables Flashgot to download only the audio and skip the video, thus saving bandwidth. I'm missing details, like how Flashgot created this link, but if Flashgot has a way to do it, it stands to reason that other HTTP clients could do it too.

很有意思。这使 Flashgot 能够仅下载音频并跳过视频,从而节省带宽。我缺少细节,例如 Flashgot 如何创建此链接,但如果 Flashgot 有办法做到这一点,那么其他 HTTP 客户端也可以做到这一点是理所当然的。

回答by Dmitry Sadakov

According to the Youtube API blog post, the only options you have of playing youtube on iOS is to link to the video (and have the internal YouTube app play the video), or link from a UIWebView and play from there. Audio-only playback is not supported.

根据Youtube API 博客文章,在 iOS 上播放 youtube 的唯一选择是链接到视频(并让内部 YouTube 应用播放视频),或从 UIWebView 链接并从那里播放。 不支持纯音频播放

回答by karlphillip

You can't. The data stream that you receive from youtube includes both video/audio streams.

你不能。您从 youtube 收到的数据流包括视频/音频流。

What you do with the data, it's up to you. This threadhas interesting info on the subject.

你如何处理数据,这取决于你。这个线程有关于这个主题的有趣信息。

回答by karlphillip

In Linux:

在 Linux 中:

  • mps-youtubea CLI solution. More details here.

  • VLCcan do that too if started without video - more here.

  • mplayercan be used with the command mplayer -novideo URL

  • mpvcan be used with the command mpv --no-video URL

  • Youtube Viewer, a CLI video player can be also used as indicated here.

  • mps-youtube一个 CLI 解决方案。更多细节在这里

  • 如果在没有视频的情况下启动,VLC也可以做到这一点——更多在这里

  • mplayer可以与命令一起使用mplayer -novideo URL

  • mpv可以与命令一起使用mpv --no-video URL

  • Youtube Viewer,一个 CLI 视频播放器也可以按照这里的指示使用。

A cross-platform solution:

跨平台解决方案:

As indicated in another answerthe Flashgot addon for Firefoxcan identify in order to download an audio of a Youtube video. It will display a list of available streams for each video.

另一个答案所示,用于 Firefox 的 Flashgot 插件可以识别以下载 Youtube 视频的音频。它将显示每个视频的可用流列表。

The idea is to start the youtube stream in an external player, but to be able to select only the audio stream with the Flashgot addon in Firefoxby adding the external player as Flashgot "downloader" (like here) and then, after starting the youtube video in Firefox, using Flashgot to play only the audio stream by going to 'Available formats/DASH (separate audio and video tracks)'

这个想法是在外部播放器中启动 youtube 流,但通过将外部播放器添加为 Flashgot“下载器”(如此),然后在启动 youtube 后,能够仅选择带有 Flashgot 插件的音频流在 Firefox 中Firefox 中的视频,使用 Flashgot 通过转到“可用格式/DASH(单独的音频和视频轨道)”来仅播放音频流

[enter image description here

[在此处输入图片说明

and select the specific audio track.

并选择特定的音轨。

[enter image description here

[在此处输入图片说明

Multimedia players can be assigned in Flashgot instead of a downloader, like VLC or SMPlayer, as most video players seem able to do the job (in Linux; for Windows, see below update); or even audio players like Clementine, although some audio players may not work.

多媒体播放器可以在 Flashgot 中分配,而不是像 VLC 或 SMPlayer 这样的下载器,因为大多数视频播放器似乎都能完成这项工作(在 Linux 中;对于 Windows,请参阅下面的更新);甚至像 Clementine 这样的音频播放器,虽然有些音频播放器可能无法工作。

It will start after a few seconds, some players after more than others. The fastest in Linux seems to be SMPlayer.

它会在几秒钟后开始,一些玩家比其他玩家更多。Linux 中最快的似乎是SMPlayer

UPDATE:

更新

  • Flashgot has to be up to date.

  • In Windows, Flashgot seems to display some audio streams in a different location than in the above image, that is already on the first list (before the DASH list). SMPlayer works the best AFAICT. VLC works, but not with all the audio streams listed by Flashgot. Clementine, Foobar2000 and XMPlay failed. It may be an overall-Windows codecs problem. MPC-HC starts but doesn't buffer correctly and stops long before it should.

  • Flashgot 必须是最新的。

  • 在 Windows 中,Flashgot 似乎在与上图不同的位置显示一些音频流,该位置已经在第一个列表中(在 DASH 列表之前)。SMPlayer 是最好的 AFAICT。VLC 有效,但不适用于 Flashgot 列出的所有音频流。Clementine、Foobar2000 和 XMPlay 失败。这可能是一个整体的 Windows 编解码器问题。MPC-HC 启动但未正确缓冲并在应有时间之前停止。

回答by L3x0R

There are separate streamsfor audioand video. This is by default in mp4 to flash conversion.

单独的流音频视频。这是 mp4 到 flash 转换的默认设置。

You can get the combined stream in flash format or separate in mp4 form.

您可以获取 Flash 格式的组合流或以 mp4 格式分离。

Exemple: [Headphones Stereo Test (HD)][youtube.com/watch?v=ZjAQylVPU3I]

示例:[耳机立体声测试 (HD)][youtube.com/watch?v=ZjAQylVPU3I]

contain

包含

[the flash stream][youtube.com/v/ZjAQylVPU3I]

[闪流][youtube.com/v/ZjAQylVPU3I]

containing the combination of audio streamand video streamin mp4 format.

包含mp4 格式的音频流视频流的组合 。

*I'm sorry but the links will not work because they are customized based on ip , expire data , and other things.

*很抱歉,这些链接将无法使用,因为它们是基于 ip 、过期数据和其他内容定制的。

To get these links i used uBlock origin for chrome because it has the logger function showing all connections made to server. search for : mime=video and you can see all links then remove the range to get full length. Same with mime=audio and also you can use that for stream in other flash players but it is against the Terms of Service.

为了获得这些链接,我使用了 uBlock origin for chrome,因为它具有记录器功能,可显示与服务器的所有连接。搜索 : mime=video ,您可以看到所有链接,然后删除范围以获得完整长度。与 mime=audio 相同,您也可以将其用于其他 Flash 播放器中的流,但这违反了服务条款

回答by N A

Using Audacity software, you could record the audio played on your computer from any source. Since Audacity is open source and you can find open source browsers, you could combine them and get the audio from youtube. Of course its a lot of work, but I am only saying it could be possible unlike others.

使用 Audacity 软件,您可以录制从任何来源在计算机上播放的音频。由于 Audacity 是开源的,您可以找到开源浏览器,您可以将它们组合起来并从 youtube 获取音频。当然它有很多工作,但我只是说它可能与其他人不同。

回答by Steve Moser

I would use a MPMoviePlayerController and hide it's view.

我会用的MPMoviePlayerController和隐藏的观点。