Get video stream from an RTMP video.

@throws Exception If the popen stream was not created correctly

@return resource popen stream
164138
public function getRtmpStream()
    {
        $urls = $this->getUrl();

        $process = new Process(
            array_merge(
                [
                    $this->config->avconv,
                    '-v', $this->config->avconvVerbosity,
                ],
                $this->getRtmpArguments(),
                [
                    '-i', $urls[0],
                    '-f', $this->ext,
                    'pipe:1',
                ]
            )
        );
        $stream = popen($process->getCommandLine(), 'r');
        if (!is_resource($stream)) {
            throw new Exception(_('Could not open popen stream.'));
        }

        return $stream;
    }
103825
public function readByte()
    {
        if (($this->_needle + 1) > $this->_streamLength) {
            throw new Exception(
                'Buffer underrun at needle position: '
                . $this->_needle
                . ' while requesting length: '
                . $this->_streamLength
            );
        }

        return ord($this->_stream{$this->_needle++});
    }
213392
protected function createStream()
    {
        $stream = Psr7\stream_for();
        $this->writePartHeadersTo($stream);
        $stream->rewind();
        return $stream;
    }
408622
public function getThumbnail()
    {
        try {
            $ffmpeg = FFMpeg::create();
            $video = $ffmpeg->open($this->file->getPathname());

            $frame = $video->frame(TimeCode::fromSeconds(0));
            $base64 = $frame->save(tempnam(sys_get_temp_dir(), $this->file->getBasename()), true, true);

            return Imagick::readImageBlob($base64);
        } catch (Exception $e) {
            return;
        }
    }
934090
public function download()
    {
        $driveLocator = "/drives/{$this->parentReference->driveId}";
        $itemLocator  = "/items/{$this->id}";
        $endpoint     = "$driveLocator$itemLocator/content";

        $response = $this
            ->graph
            ->createRequest('GET', $endpoint)
            ->execute();

        $status = $response->getStatus();

        if ($status != 200) {
            throw new \Exception("Unexpected status code produced by 'GET $endpoint': $status");
        }

        return $response->getResponseAsObject(Stream::class);
    }
1285501
public function getInputStream()
    {
        if (0 === func_num_args() || func_get_arg(0)) {
            @trigger_error(sprintf('The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use %s::getStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED);
        }

        return $this->inputStream;
    }
1006315
public function getStream()
    {
        $fp = @fopen($this->getPath(), 'rb');

        if ($fp === false) {
            $msg = "Cannot retrieve QTI File Stream from '" . $this->getPath() . "'.";
            throw new RuntimeException($msg);
        }

        $len = current(unpack('S', fread($fp, 2)));
        fseek($fp, $len, SEEK_CUR);

        $len = current(unpack('S', fread($fp, 2)));
        fseek($fp, $len, SEEK_CUR);

        return $fp;
    }
741606
protected function getSocketStream()
    {
        if (!is_resource($this->socketResource)) {
            $this->connect();
            return $this->socketResource;
        }
        $meta = stream_get_meta_data($this->socketResource);
        if (($meta['timed_out'] || $meta['eof']))
            $this->connect();
        return $this->socketResource;
    }
1090011
def download_video_no_cache(self):
        
        video_url = self.presentation.metadata['video_url']
        video_path = self.presentation.metadata['video_path']

        # After a while, when downloading a long video (> 1h), the RTMP server seems to reset the connection (rtmpdump
        # returns exit code 2). The only way to get the full stream is to resume the download.
        resume_download = True
        while resume_download:
            try:
                cmd = [self.rtmpdump, '-q', '-e', '-r', video_url, '-y', video_path, "-o", self._video_path]
                subprocess.check_output(cmd, stderr=subprocess.STDOUT)
                resume_download = False
            except subprocess.CalledProcessError as e:
                if e.returncode != 2:
                    try:
                        os.unlink(self._video_path)
                    except OSError:
                        pass

                    raise client.DownloadError("Failed to download video at %s: rtmpdump exited with %s.\n\tOutput:\n%s"
                                           % (video_url, e.returncode, e.output))

        return self._video_path
710959
public function createStreamFromFile(string $filename, string $mode = "r"): StreamInterface{
        if(false === ($resource = fopen($filename, $mode))){
            throw new Exception\FileOpenException(
                "{$filename} could not be opened in {$mode} mode"
            );
        }

        return $this->createStreamFromResource($resource);
    }
40308
public InputStream getResourceAsStream(String resourceName) {
		InputStream is = null;
		String realPath = getRealResourcePath(resourceName);
		if (isFileSystemPath(resourceName, realPath)) { // The resource has been
														// remapped to a file
														// system path
			try {
				is = new FileInputStream(realPath);
			} catch (FileNotFoundException e) {
				LOGGER.debug("The resource " + realPath + " has not been found");
			}
		}
		if (is == null) {
			is = super.getResourceAsStream(realPath);
		}
		return is;
	}
425841
protected function _getRemoteMTime()
    {
        $remote_datetime = $this->_getRemoteData($this->remoteVerUrl);
        $remote_tmstp = strtotime($remote_datetime);

        if (!$remote_tmstp) {
            throw new Exception("Bad datetime format from {$this->remoteVerUrl}");
        }

        return $remote_tmstp;
    }
653155
def realtime_stream(self, channel=1, typeno=0, path_file=None):
        
        ret = self.command(
            'realmonitor.cgi?action=getStream&channel={0}&subtype={1}'.format(
                channel, typeno)
        )

        if path_file:
            with open(path_file, 'wb') as out_file:
                shutil.copyfileobj(ret.raw, out_file)

        return ret.raw
869373
public function getContents(){
        if(null === $this->resource){
            throw new Exception\StreamUnavailableException(
                static::EXCEPTION_MSG_UNAVAILABLE
            );
        }

        if(!$this->isReadable()){
            throw new Exception\StreamUnreadableException(
                static::EXCEPTION_MSG_UNREADABLE
            );
        }

        if(false === ($contents = stream_get_contents($this->resource))){
            throw new \RuntimeException("Failed to read stream.");
        }

        return $contents;
    }
484605
private function getPipe()
    {
        if (!isset($this->pipe) || !isset($this->proc)) {
            $desc = [['pipe', 'r'], $this->stream, \fopen('php://stderr', 'w')];
            $this->proc = \proc_open($this->cmd, $desc, $pipes);

            if (!\is_resource($this->proc)) {
                throw new \RuntimeException('Error opening output stream');
            }

            $this->pipe = $pipes[0];
        }

        return $this->pipe;
    }
160877
public function getPeerName()
    {
        $ret = @socket_getpeername($this->resource, $address, $port);
        if ($ret === false) {
            throw Exception::createFromSocketResource($this->resource);
        }
        return $this->formatAddress($address, $port);
    }
938002
protected function localFileStream() {

    $tmp = fopen('php://temp', 'rw');
    fwrite($tmp, $this->content(), $this->contentLength());
    rewind($tmp);

    return $tmp;
  }