GVKun编程网logo

PHP、golang 如何播放 mp4 文件(golang解析php)

1

对于PHP、golang如何播放mp4文件感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍golang解析php,并为您提供关于.mp4文件未在Django模板和FireFox或Chrome中播

对于PHP、golang 如何播放 mp4 文件感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍golang解析php,并为您提供关于.mp4 文件未在 Django 模板和 FireFox 或 Chrome 中播放 我正在不同的 Ubuntu PC 上实现此代码我尝试了不同的fourcc来保存.mp4,但在ubuntu中使用fourcc以下的文件效果很好、Android 如何播放 mov 格式的视频文件?、Bootstrap 3 - 响应式 mp4 视频 - Bootstrap 3 - Responsive mp4-video、CentOs 8 + PHP 下载视频 .mp4的有用信息。

本文目录一览:

PHP、golang 如何播放 mp4 文件(golang解析php)

PHP、golang 如何播放 mp4 文件(golang解析php)

 

<?php
function PutMovie($file) {
    header("Content-type: video/mp4");
    header("Accept-Ranges: bytes");
     
    $size = filesize($file);
    if(isset($_SERVER[''HTTP_RANGE''])){
        header("HTTP/1.1 206 Partial Content");
        list($name, $range) = explode("=", $_SERVER[''HTTP_RANGE'']);
        list($begin, $end) =explode("-", $range);
        if($end == 0) $end = $size - 1;
    }
    else {
        $begin = 0; $end = $size - 1;
    }
    header("Content-Length: " . ($end - $begin + 1));
    header("Content-Disposition: filename=".basename($file));
    header("Content-Range: bytes ".$begin."-".$end."/".$size);
 
    $fp = fopen($file, ''rb'');
    fseek($fp, $begin);
    while(!feof($fp)) {
        $p = min(1024, $end - $begin + 1);
        $begin += $p;
        echo fread($fp, $p);
    }
    fclose($fp);
}
PutMovie("1.mp4");
?>
http.ServeFile(w, r, "/webserver/1.mp4")

 

.mp4 文件未在 Django 模板和 FireFox 或 Chrome 中播放 我正在不同的 Ubuntu PC 上实现此代码我尝试了不同的fourcc来保存.mp4,但在ubuntu中使用fourcc以下的文件效果很好

.mp4 文件未在 Django 模板和 FireFox 或 Chrome 中播放 我正在不同的 Ubuntu PC 上实现此代码我尝试了不同的fourcc来保存.mp4,但在ubuntu中使用fourcc以下的文件效果很好

如何解决.mp4 文件未在 Django 模板和 FireFox 或 Chrome 中播放 我正在不同的 Ubuntu PC 上实现此代码我尝试了不同的fourcc来保存.mp4,但在ubuntu中使用fourcc以下的文件效果很好

我可以将实时 RTSP 视频流保存在 .mp4 中,但是当我在 Django 模板、Firefox、Chrome 浏览器或 VLC 中运行保存的 .mp4 视频时,视频无法在 ubuntu 中播放。 我想我在 .mp4 中有一个兼容问题。此外,我想在 Django 中显示和播放 .mp4 保存的文件。

我有两个 IP 摄像头,可提供实时 RTSP 视频流。

self.input_stream---> rtsp://admin:Admin123@192.168.1.208/user=admin_password=Admin123_channel=0channel_number_stream=0.sdp

self.input_stream---> rtsp://Admin:@192.168.1.209/user=Admin_password=_channel=0channel_number_stream=0.sdp

Python 3.8.5(默认,2020 年 7 月 28 日,12:59:40) [GCC 9.3.0] 在 linux 上,

Django==3.1.2

我正在不同的 Ubuntu PC 上实现此代码

Ubuntu = 18.04 和 20.04

opencv-contrib-python==4.4.0.46

opencv-python==4.4.0.46

ffmpeg 版本 4.2.4-1ubuntu0.1 版权所有 (c) 2000-2020 FFmpeg 开发人员 使用 gcc 9 (Ubuntu 9.3.0-10ubuntu2) 构建

我尝试了不同的fourcc来保存.mp4,但在ubuntu中使用fourcc以下的文件效果很好。

fourcc = cv2.VideoWriter_fourcc(*''mp4v'')

class ffmpegStratStreaming(threading.Thread):
    def __init__(self,input_stream=None,output_stream=None,camera=None,*args,**kwargs):
        self.input_stream = input_stream
        self.output_stream = output_stream
        self.camera = camera
        super().__init__(*args,**kwargs)

    def run(self):
        try:vs = cv2.VideoCapture(self.input_stream)
            fps_rate = int(vs.get(cv2.CAP_PROP_FPS))
            ##############################
            ##############################  
            # ~ print(''fps rate-->'',fps_rate,''camera id-->'',str(self.camera.id))
            # ~ vs.set(cv2.CAP_PROP_POS_FRAMES,50)  #Set the frame number to be obtained
            # ~ print(''fps rate-->'',str(self.camera.id),'' ####### '')
            
            # initialize the video writer (we''ll instantiate later if need be)
            writer = None

            # initialize the frame dimensions (we''ll set them as soon as we read
            # the first frame from the video)
            W = None
            H = None    
            # start the frames per second throughput estimator
            fps = FPS().start()

            #  saving frame in avi video format
            video_file_count = 0
            start_time = time.time()

            while True:
                try:
                    # grab the next frame and handle if we are reading from either
                    # VideoCapture or VideoStream
                    
                    frame_init = vs.read()
                    frame = frame_init[1] if self.input_stream else frame_init
                    
                    # if frame is can''t read correctly ret is False
                    while frame_init[0] == False:
                        print("Can''t receive frame. retrying ...")
                        vs.release()
                        vs = cv2.VideoCapture(self.input_stream)                                                                              
                        frame_init = vs.read()
                        frame = frame_init[1] if self.input_stream else frame_init

                    # if we are viewing a video and we did not grab a frame then we
                    # have reached the end of the video
                    if self.input_stream is not None and frame is None:
                        break

                    # resize the frame to have a maximum width of 500 pixels (the
                    # less data we have,the faster we can process it),then convert
                    # the frame from BGR to RGB for dlib
                    frame = imutils.resize(frame,width=500)        
                    
                    
                    #<---------------------- Start of  writing a video to disk ------------------------->                   
                    minute = 1
                    second  = 60
                    minite_to_save_video = int(minute) * int(second)

                
                    # if we are supposed to be writing a video to disk,initialize
                    if time.time() - start_time >= minite_to_save_video or  video_file_count == 0 :
                        ## where H = heigth,W = width,C = channel 
                        H,W,C = frame.shape
                        video_file_count += 1
                        start_time = time.time()
                        output_save_directory = self.output_stream+str(video_file_count)+''.mp4''
                        # fourcc = cv2.VideoWriter_fourcc(*"MJPG")
                        # fourcc = cv2.VideoWriter_fourcc(*''XVID'')
                        # fourcc = cv2.VideoWriter_fourcc(*''X264'')
                        # fourcc = cv2.VideoWriter_fourcc(*''MP4V'')

                        
                        # fourcc = cv2.VideoWriter_fourcc(*''FMP4'')

                        # fourcc = cv2.VideoWriter_fourcc(*''avc1'')


                        # fourcc = cv2.VideoWriter_fourcc(''M'',''J'',''P'',''G'')

                        fourcc = cv2.VideoWriter_fourcc(*''mp4v'')
                        # fourcc = cv2.VideoWriter_fourcc(*''mp3v'')
                        # fourcc = 0x00000021
                        print(fourcc,type(fourcc),''ffffffff'')
                        # a = int(vs.get(cv2.CAP_PROP_FOURCC))
                        # print(a,type(a),''  aaaaaaaa'' )

                        # writer = skvideo.io.FFmpegWriter(output_save_directory,outputdict={
                        #   ''-vcodec'': ''libx264'',''-b'': ''300000000''
                        # })
                        
                        # writer = skvideo.io.FFmpegWriter(self.output_stream,outputdict={''-r'': ''120'',''-c:v'': ''libx264'',''-crf'': ''0'',''-preset'': ''ultrafast'',''-pix_fmt'': ''yuv444p''})
                        
                        writer = cv2.VideoWriter(output_save_directory,fourcc,20.0,( int(W),int(H) ),True)
                        
                        
                        # ~ The cv2.VideoWriter requires five parameters:    

                    # check to see if we should write the frame to disk
                    if writer is not None:                          
                        try:
                            writer.write(frame)
                        except Exception as e:
                            print(''Error in writing video output---> '',e)
                            
                    #<---------------------- end of  writing a video to disk ------------------------->

                    # show the output frame
                    # cv2.imshow("Frame",frame)
                    # key = cv2.waitKey(1) & 0xFF

                    # if the `q` key was pressed,break from the loop
                    # if key == ord("q"):
                    #   break

                    # increment the total number of frames processed thus far and
                    # then update the FPS counter
                    totalFrames += 1
                    fps.update()
                except Exception as e:
                    print(''Error in main while loop--> '',e)

            # stop the timer and display FPS information
            fps.stop()

            # check to see if we need to release the video writer pointer
            # if writer is not None:
            #   writer.release()

            # if we are not using a video file,stop the camera video stream
            # if not self.input_stream:
            #   vs.stop()

            # otherwise,release the video file pointer
            # else:
            #   vs.release()

            # close any open windows
            # cv2.destroyAllWindows()
        except Exception as e:
            print(e,''333333333333333333333333333'')

我的 Django 模板代码

{% block main %}
<div>
  {% if folders|length == 0 %}
    <div>
      <h6>There are no files in this directory.</h6>
    </div>
  {% else %}
    {% for folder in folders %}
      <div>
          <div>
            <video id="my_video_{{forloop.counter}}"controls preload="auto"  muted data-setup=''{ "controls": true,"autoplay": false,"preload": "auto","seek": true  }'' />
                <source src="{% get_media_prefix %}camera-Feed/video-saved/{{pk}}/{{parent}}/{{folder}}" type="video/mp4">
            </video>
            <h6>{{folder}}</h6>
          </div>
      </div>
    {% endfor %}
  {% endif %}
</div>
{% endblock %}

view.py 中的函数,用于查看 Django 模板中保存的 .mp4 视频。视频保存在本地文件夹中。

def Cameravideos(request,pk,folder):
    dirpath = settings.MEDIA_ROOT + ''/camera-Feed/video-saved/'' + str(pk) + ''/'' + folder
    folders = sorted(Path(dirpath).iterdir(),key=os.path.getmtime)
    data = []
    for file in folders:
        if not file.name.startswith(''.''):
            data.append(file.name)
    return render(request,"home/camera_video.html",{''folders'': data,''pk'': pk,''parent'': folder})

Android 如何播放 mov 格式的视频文件?

Android 如何播放 mov 格式的视频文件?

mov 格式的文件时苹果公司发明的一种视频文件格式的标准,如何在 android 下播放 mov 文件呢?有没有第三方的包什么的,主要是能让 android 上播放这种文件 (mov)

Bootstrap 3 - 响应式 mp4 视频 - Bootstrap 3 - Responsive mp4-video

Bootstrap 3 - 响应式 mp4 视频 - Bootstrap 3 - Responsive mp4-video

问题:

I tried to find a good solution on the bootstrap site but I didn''t get an answer to this yet. 我试图在 bootstrap 网站上找到一个很好的解决方案,但我还没有得到答案。 I think I can''t be the only one struggling with this, but I couldn''t find anything that helped me. 我想我不可能是唯一一个与此斗争的人,但我找不到任何帮助我的东西。

I''m trying to embed an mp4-video on my website. 我正在尝试在我的网站上嵌入一个 mp4 视频。 The problem is, that if I use an iframe-tag I can''t use autoplay and loop. 问题是,如果我使用 iframe-tag,我就不能使用自动播放和循环。 Because of that I would like to solve it with a video tag (or something else that supports autoplay and loop). 因此,我想用视频标签(或其他支持自动播放和循环的东西)来解决它。 After that I tried to make my video responsive with an object-tag but this didn''t work. 之后,我尝试使用对象标签响应视频,但这不起作用。 Even though I let it in my code (to show you) which you can see below: 即使我在我的代码(告诉你)中让它,你可以在下面看到:

<div align="center">
   <object class="embed-responsive-item">
     <video autoplay loop >
       <source src="file.mp4" />
     </video>
   </object>
 </div>

I hope anyone of you can help me fix this. 我希望你们中的任何人都可以帮我解决这个问题。


解决方案:

参考: https://stackoom.com/en/question/1lGEC

CentOs 8 + PHP 下载视频 .mp4

CentOs 8 + PHP 下载视频 .mp4

如何解决CentOs 8 + PHP 下载视频 .mp4

我有问题。我想创建一个 PHP 代码,给定一个链接到我的服务器上的视频,下载该 .mp4 视频,而不必每次都创建一个 .zip 文件然后下载它。我能怎么做?我在网上找到了这段代码,但它不起作用。

$file_url = ''http://myfile.it/GG.mp4'';
header(''Content-Type: video/mp4'');
header("Content-transfer-encoding: Binary");
header("Content-disposition: attachment; filename=\\"" . basename($file_url) . "\\"");
readfile($file_url);

我尝试了几个网上找到的代码,但没有一个有效。唯一一个似乎下载了一些东西的是这个,但它下载了一个“假”的 .mp4 文件,它不是完整的视频。有谁知道如何从我的 cent os 7 服务器下载 .mp4 文件而无需创建 .zip 文件并打开它?

今天关于PHP、golang 如何播放 mp4 文件golang解析php的介绍到此结束,谢谢您的阅读,有关.mp4 文件未在 Django 模板和 FireFox 或 Chrome 中播放 我正在不同的 Ubuntu PC 上实现此代码我尝试了不同的fourcc来保存.mp4,但在ubuntu中使用fourcc以下的文件效果很好、Android 如何播放 mov 格式的视频文件?、Bootstrap 3 - 响应式 mp4 视频 - Bootstrap 3 - Responsive mp4-video、CentOs 8 + PHP 下载视频 .mp4等更多相关知识的信息可以在本站进行查询。

本文标签: