目标:
制作一个Android应用程序,将实时视频/音频流式传输到PC.文件不应保存在任何地方.由于库libstreamer和vlcj的发现,Atm我在java两端(android / PC)工作.
总体:
我让视频工作但它没有在PC上播放音频.
我尝试了不同的音频编码.尝试使用AAC时 – VLC会发出错误消息,说这是一种未知格式. Aint使用格式AMRNB得到相同的错误,所以有些音频必须通过或者我错了吗?
我已经尝试了从G33Ktricks开始的几个不同的RTPS测试链接没有设法找到一个不使用PC vlcj.
PC连接到android pastebin后启动的logcat
题:
我错过了什么音频工作?
如果无法回答,那么我应该看看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
从android方面:
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
}