2011-11-25 14:14
浏览 76


Im using VCL to broadcast to my localhost, with UDP (legacy) method. To catch the traffic, I use this code:

$address = '';
$port = 1234;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($sock, $address, $port) or die('Could not bind to address');
$f = fopen ('output', 'w');
fclose ($f);
$sock = stream_socket_server('udp://', $errno, $errstr, STREAM_SERVER_BIND);
    $a = stream_socket_recvfrom($sock, 65536);
    $f = fopen('output', 'a');
    fwrite ($f, $a);
    fclose ($f);

this logs the packets and saves, I rename it to .MP4 and open - well, the result is a little messy. I can recognize the output, the top screen is visible, the lower part is not good. I tried to capture it with another VCL player, and there were no problem.

图片转代码服务由CSDN问答提供 功能建议

我使用VCL广播到我的localhost,使用UDP(传统)方法。 为了捕获流量,我使用以下代码:

  $ address =''; 
 $ port = 1234; 
 $ sock = socket_create(AF_INET,SOCK_DGRAM  ,SOL_UDP); 
socket_bind($ sock,$ address,$ port)或die('无法绑定到地址'); 
 $ f = fopen('output','w'); 
 nclclose($ f)  ; 
 $ sock = stream_socket_server('udp://',$ errno,$ errstr,STREAM_SERVER_BIND); 
 $ a = stream_socket_recvfrom($ sock,65536);  
 $ f = fopen('output','a'); 
 fwrite($ f,$ a); 
 fclose($ f); 

这会记录数据包并保存,我将其重命名为.MP4​​并打开 - 好吧,结果有点乱。 我可以识别输出,顶部屏幕可见,下部不好。 我试图用另一个VCL播放器捕获它,没有问题。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanjie3267 2011-11-25 14:37

    Here is your code with a lot of useless stuff removed and a few efficiency improvements. Try it out and see what happens. It may or may not fix the problem, but report back with what happens and we'll take it from there.

    // Settings
    $address = '';
    $port = 1234;
    $outfile = "output.mp4";
    // Open pointers
    if (!$ofp = fopen($outfile, 'w'))
      exit("Could not open output file for writing");
    if (!$ifp = stream_socket_server("udp://$address:$port", $errno, $errstr, STREAM_SERVER_BIND))
      exit("Could not create listen socket ($errno: $errstr)");
    // Loop and fetch data
    // This method of looping is flawed and will cause problems because you are using
    // UDP. The socket will never be "closed", so the loop will never exit. But you
    // were looping infinitely before, so this is no different - we can address this
    // later
    while (!feof($ifp)) {
      if (!strlen($chunk = fread($ifp, 8192))) continue;
      fwrite($ofp, $chunk);
    // Close file pointers
    点赞 评论

相关推荐 更多相似问题