2017-10-08 10 views
0

J'essaye d'écrire une application de streaming vidéo http avec Java en utilisant la bibliothèque VLCJ mais j'ai un problème "votre entrée ne peut pas être ouverte".Vidéo http Streaming Java avec VLCJ - Votre entrée ne peut pas être ouverte

OS: Windows 10 x64

Mon code source: https://github.com/caprica/vlcj/blob/master/src/test/java/uk/co/caprica/vlcj/test/streaming/StreamHttp.java

import com.sun.jna.Native; 
import com.sun.jna.NativeLibrary; 
import uk.co.caprica.vlcj.binding.LibVlc; 
import uk.co.caprica.vlcj.player.MediaPlayerFactory; 
import uk.co.caprica.vlcj.player.headless.HeadlessMediaPlayer; 
import uk.co.caprica.vlcj.runtime.RuntimeUtil; 
import uk.co.caprica.vlcj.runtime.x.LibXUtil; 
import java.io.File; 

/** 
* An example of how to stream a media file over HTTP. 
* <p> 
* The client specifies an MRL of <code>http://127.0.0.1:5555</code> 
*/ 
public class VideoStream extends VlcjTest{ 

    public static void main(String[] args) throws Exception { 
     System.setProperty("VLC_PLUGIN_PATH", "D:\\Program Files\\VideoLAN\\VLC\\plugins"); 
     File vlcInstallPath = new File("D:\\Program Files\\VideoLAN\\VLC"); 
     NativeLibrary.addSearchPath(
       RuntimeUtil.getLibVlcLibraryName(), vlcInstallPath.getAbsolutePath()); 
     Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); 
     LibXUtil.initialise(); 
     String media = "D://demo.mp4"; 
     String options = formatHttpStream("127.0.0.1", 5555); 
     System.out.println("Streaming '" + media + "' to '" + options + "'"); 

     MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory(); 
     HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer(); 
     mediaPlayer.playMedia(media, options); 

     // Don't exit 
     Thread.currentThread().join(); 
    } 

    private static String formatHttpStream(String serverAddress, int serverPort) { 
     StringBuilder sb = new StringBuilder(60); 
     sb.append(":sout=#duplicate{dst=std{access=http,mux=ts,"); 
     sb.append("dst="); 
     sb.append(serverAddress); 
     sb.append(':'); 
     sb.append(serverPort); 
     sb.append("}}"); 
     return sb.toString(); 
    } 
} 

et résultat:

[000000001a948be0] access_output_http access out: Consider passing --http-host=IP on the command line instead. 
[000000001aa2def0] core input error: open of `D://demo.mp4' failed 
[000000001aa2def0] core input error: Your input can't be opened 
[000000001aa2def0] core input error: VLC is unable to open the MRL 'D://demo.mp4'. Check the log for details. 
+0

'D' ne semble pas être un protocole d'accès [Media Resource Locator] correct (https://wiki.videolan.org/Media_resource_locator/). –

+0

J'utilise ce fichier multimédia http://www.sample-videos.com/video/mp4/240/big_buck_bunny_240p_5mb.mp4 – mesutpiskin

Répondre

0

La question est

String media = "D://demo.mp4"; 

comme suggéré par le commentaire. Avec // après le D: il sera considéré comme un nom de protocole.

L'une des variantes suivantes devrait fonctionner pour vous:

String media = "D:/demo.mp4"; 

à condition que playMedia prend en charge les chemins de fichiers locaux. Ou

String media = new File("D:/demo.mp4").toURI().toURL(); 

si cela nécessite une chaîne d'URL.