简体   繁体   English

Android直播视频 - 音频无效

[英]Android live streaming Video - Audio not working

The Goal: 目标:

Make an android app to stream live video/audio to a PC. 制作一个Android应用程序,将实时视频/音频流式传输到PC。 The files should not be saved anywhere. 文件不应保存在任何地方。 Atm im working in java on both ends (android / PC) due to the finds of the libraries libstreamer and vlcj. 由于库libstreamer和vlcj的发现,Atm我在java两端(android / PC)工作。

Overall: 总体:

I got the video to work but it doesn't play the audio on the PC. 我让视频工作但它没有在PC上播放音频。 I tried different encoding for the audio. 我尝试了不同的音频编码。 When trying with AAC - VLC will give an error saying this is an unknown format. 尝试使用AAC时 - VLC会发出错误消息,说这是一种未知格式。 Aint getting same error using the format AMRNB, so some audio must be coming through or am i wrong about this? Aint使用格式AMRNB得到相同的错误,所以有些音频必须通过或者我错了吗? I have tried several different RTPS testlinks from G33Ktricks Did not manage to find one not working with the PC vlcj. 我尝试过G33Ktricks的几个不同的RTPS测试链接 。没有设法找到一个不使用PC vlcj的测试链接。 A logcat for the startup after PC connects to android pastebin PC连接到android pastebin后启动的logcat

Question: 题:

What am i missing for the audio to work? 我错过了什么音频工作? If that cannot be answered, is it the android or PC side i should look at to have the most luck finding the missing line? 如果无法回答,那么我应该看看Android或PC方面是否有运气找到缺失线?

Android: 安卓:

im using libstreamer and examples from Spydroid to get this working. 即时通讯使用libstreamer和Spydroid中的示例来实现这一点。 The code i startet with is found in the libstreamer pack example 1: 我发现的代码可以在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));
}
}

PC 个人计算机

Using VLCJ for the streaming. 使用VLCJ进行流式传输。 The code i startet with is found in the vlcj-master official pack - Example2: 我发现的代码可以在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 SDP

From the android side: 从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

I found the reason why... 我找到了原因......

The following code is from libstreaming net.majorkernelpanic.streaming.SessionBuilder.java 以下代码来自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
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM