gpt4 book ai didi

Android 直播视频 - 音频不工作

转载 作者:太空宇宙 更新时间:2023-11-03 10:45:05 25 4
gpt4 key购买 nike

目标:

制作一个 Android 应用程序以将实时视频/音频流式传输到 PC。这些文件不应保存在任何地方。由于发现了库 libstreamer 和 vlcj,Atm 在两端(android/PC)都在 java 中工作。

总体:

我可以播放视频,但无法在 PC 上播放音频。我尝试了不同的音频编码。尝试使用 AAC 时 - VLC 会报错说这是未知格式。使用 AMRNB 格式不会出现同样的错误,所以必须通过某些音频,或者我对此有误吗?我尝试了来自 G33Ktricks 的几个不同的 RTPS 测试链接。没能找到一个不能与 PC vlcj 一起工作的。PC连接android后启动的logcat pastebin

问题:

要使音频正常工作,我缺少什么?如果无法回答,我应该看看是 Android 端还是 PC 端,以便最幸运地找到缺失的行?

安卓:

我正在使用 libstreamer 和 Spydroid 中的示例来实现此功能。我开始使用的代码可以在 libstreamer 包示例 1 中找到:

public class MainActivity extends Activity {
private final static String TAG = "MainActivity";
private SurfaceView mSurfaceView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

mSurfaceView = (SurfaceView) findViewById(R.id.surface);

// Sets the port of the RTSP server to 1234
Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString(RtspServer.KEY_PORT, String.valueOf(1234));
editor.commit();

// Configures the SessionBuilder
SessionBuilder builder = SessionBuilder.getInstance();

builder.setSurfaceView(mSurfaceView);
builder.setPreviewOrientation(90);
builder.setContext(getApplicationContext());
builder.setAudioEncoder(SessionBuilder.AUDIO_AMRNB);
builder.setAudioQuality(new AudioQuality(8000,16000));
builder.setVideoEncoder(SessionBuilder.VIDEO_H264);
builder.setVideoQuality(new VideoQuality(480,320,10,500000));
builder.setCamera(CameraInfo.CAMERA_FACING_FRONT);
builder.build();

// Starts the RTSP server
this.startService(new Intent(this,RtspServer.class));
}
}

电脑

使用 VLCJ 进行流式传输。我开始使用的代码可以在 vlcj-master 官方包中找到 - 示例 2:

public class Example2
{
private final JFrame frame;
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;

public static void main( String[ ] args )
{
new NativeDiscovery().discover();

final String mrl = "rtsp://10.251.1.107:1234/trackID=0";

SwingUtilities.invokeLater( new Runnable() {
@Override
public void run( )
{
new Example2().start( mrl );
}
} );
}

public Example2( )
{
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
frame = new JFrame( "vlcj quickstart" );
frame.setLocation( 0, 0 );
frame.setSize( 1400, 800 );
frame.setContentPane( mediaPlayerComponent );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
}

private void start( String mrl )
{
String[] options = {"--ffmpeg-threads=1"};

EmbeddedMediaPlayer p = mediaPlayerComponent.getMediaPlayer();
p.playMedia( mrl, options );
}
}

SDP

从安卓端:

RTSP/1.0 200 OK
Server: MajorKernelPanic RTSP Server
Cseq: 3
Content-Length: 366
Content-Base: 10.251.1.107:1234/
Content-Type: application/sdp
v=0
o=- 0 0 IN IP4 10.251.1.107
s=Unnamed
i=N/A
c=IN IP4 10.251.1.125
t=0 0
a=recvonly
m=audio 5004 RTP/AVP 96
a=rtpmap:96 AMR/8000
a=fmtp:96 octet-align=1;
a=control:trackID=0
m=video 5006 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=428015;sprop-parameter-sets=Z0KAFdoHgpoBtChNQA==,aM4G4g==;
a=control:trackID=1
SETUP 10.251.1.107:1234/trackID=0
Requested audio with 16kbps at 8kHz

最佳答案

我找到了原因......

以下代码来自libstreaming net.majorkernelpanic.streaming.SessionBuilder.java

if (session.getVideoTrack()!=null) {
VideoStream video = session.getVideoTrack();
video.setFlashState(mFlash);
video.setVideoQuality(mVideoQuality);
video.setSurfaceView(mSurfaceView);
video.setPreviewOrientation(mOrientation);
video.setDestinationPorts(5006);
}

if (session.getAudioTrack()!=null) {
AudioStream audio = session.getAudioTrack();
audio.setAudioQuality(mAudioQuality);
audio.setDestinationPorts(5004); //Change this port to anything else fx 5010 worked for me
}

关于Android 直播视频 - 音频不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25377211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com