【问题标题】:HTML video tag giving different results on different videos, may I know what is the issue?HTML视频标签在不同的视频上给出不同的结果,我可以知道是什么问题吗?
【发布时间】:2021-11-23 07:54:51
【问题描述】:

工作视频正常播放并具有常规的“控件”外观,而非工作视频不播放,甚至不显示缩略图并且具有不同的“控件”外观。

我已确认两个视频都存在,没有文件未找到错误,它们是正确的 mime_type "video/mp4"。

工作部分:

// if only 1 image
if (reply.mediaDirs.length == 1){
    console.log(`only 1 image for id:${reply.id}`)
    // Each file name
    reply.mediaDirs.forEach((dir,idx) =>{
        if (idx == 0){
            html += `<div class="carousel-item active" style="width:100%;height:30vh;overflow:hidden;">`
        }
        else{
            html += `<div class="carousel-item" style="width:100%;height:30vh;overflow:hidden;">`
        }
        // Check if image
        if (dir.toLowerCase().endsWith('.jpg')){
            html += `
                        <img src="/static/${dir}" class="d-block w-100 card-img-top border-top border-left border-right bg-blur-image" style="border-radius:8px 8px 8px 8px !important; width:100%;height:100%;object-fit:contain;background-image:url('/static/${dir}');">`
        }
        // Check if video
        else if (dir.toLowerCase().endsWith('.mp4')){
            html += `
                        <video controls class="d-block w-100 card-img-top border-top border-left border-right bg-blur-image" style="border-radius:8px 8px 8px 8px !important; width:100%;height:100%;object-fit:contain;">
                            <source src="/static/${dir}" type="video/mp4" >
                        </video>`
        }
        html += `   
                    </div>
                </div>`
    })
}

非工作部分:

// if more than 1 image
else if (reply.mediaDirs.length > 1){
    console.log(`more than 1 image for id:${reply.id}`)
    // Each file name
    reply.mediaDirs.forEach((dir,idx) =>{
        if (idx == 0){
            html += `<div class="carousel-item active" style="width:100%;height:50vh;overflow:hidden;">`
        }
        else{
            html += `<div class="carousel-item" style="width:100%;height:50vh;overflow:hidden;">`
        }
        // Check if image
        if (dir.toLowerCase().endsWith('.jpg')){
            html += `
                        <img src="/static/${dir}" class="d-block w-100 card-img-top border-top border-left border-right bg-blur-image" style="border-radius:8px 8px 8px 8px !important; width:100%;height:100%;object-fit:contain;background-image:url('/static/${dir}');">`
        }
        // Check if video
        else if (dir.toLowerCase().endsWith('.mp4')){
            html += `
                        <video controls class="d-block w-100 card-img-top border-top border-left border-right bg-blur-image" style="border-radius:8px 8px 8px 8px !important; width:100%;height:100%;object-fit:contain;">
                            <source src="/static/${dir}" type="video/mp4" >
                        </video>`
        }
        html += `   
                    </div>`

我所做的基本上是附加到 html,如果重要的话,我正在使用 Django 和 Bootstrap。

编辑: 不可能是由于 html 格式错误,关闭标签等似乎已经到位。 Inspect element of the non-working vid

编辑 2: 视频有问题吗?我只是尝试将视频源硬编码为另一个视频,它有效吗?!这是否意味着 html 对视频采用了一些标准? (例如,最小视频长度,最小视频大小......等)(无效的视频是:4 秒长,406+kb 大) Video Codec Info

【问题讨论】:

  • 因为两段代码(对于 1 或多于 1)使用相同的 reply.mediaDirs.forEach() 你需要第二段代码吗?我能看到的唯一区别是第二个缺少结束 &lt;/div&gt; 标记,所以它可能是错误的?!
  • 嗨@ProfessorAbronsius 感谢您的回复!如更新的问题中所见,它似乎不是格式错误的 html。关于重复的 forEach(),唯一的区别在于 style="height:"
  • 在您所说的代码段中有 2 个打开和 1 个关闭 div 标记是 Non-working part: - 我会留给您确定这是否意味着它的格式不正确在我看来,这似乎很有可能

标签: javascript html css


【解决方案1】:

感谢@JurgenRutten 为我指明了正确的方向。

问题在于浏览器不支持编解码器H265,如另一篇文章所述:

  1. Why won't some MP4 files play via HTML5?
  2. H.265/HEVC web browser support

简而言之:您应该使用 FFMPEG 将其转换为支持的编解码器,例如 H264

【讨论】:

    【解决方案2】:

    在: &lt;div class="carousel-item" style="width:100%;height:30vh;overflow:hidden;"&gt;

    我可以看到,在上面你有 30vh,在底部有 50vh;但我看不出有什么不同,你试过用不同的视频吗?可能是浏览器无法正常加载第二个视频。

    我使用我拥有的视频运行了你的代码,一切似乎都运行良好。

    【讨论】:

    • 是的,我感觉它与特定视频有关,但我不知道为什么。也许有一些我不知道的事情,例如。视频必须有一定的秒长,视频必须至少有一定的大小,等等。编辑:我试图硬编码并放置一个不同的视频,它有效???这意味着与导致此问题的其他视频有关
    • 能否在桌面上手动运行windows或linux中的视频?它是什么格式,您的所有视频都使用什么格式?
    • 是的,我可以正常播放视频,它只是任何其他 .mp4 视频。
    • 编解码器信息已更新到帖子!非常感谢:)
    • 真的......真的很奇怪的问题......因为当我查看自己的文件时,我也找不到任何特别之处,但我注意到当我将 .wmv 文件重命名为 .mp4 时,它会运行在 Windows 中也很好......但可能是浏览器无法识别编解码器。您是否尝试过更改后缀并进行转换?只是为了验证任何有缺陷的法典。
    猜你喜欢
    • 2021-10-02
    • 2021-08-30
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多