python - 在 GAE 上使用 Python 将 .ts 文件从 m3u8 合并到单个 mp4(无 ffmpeg)

标签 python google-app-engine video

我正在尝试在 GAE 上使用 python 下载文件列表并将其从 m3u8 list 合并到单个 mp4 视频文件。 现在我正在下载文件并按照它们在播放列表中的顺序将它们附加到同一个"new"文件。新文件可以播放,但只能与部分播放器一起播放。可能是因为大部分玩家搞不清楚文件类型——没有容器。 寻找一种将 mp4 容器元数据写入合并文件的方法。

代码是用 python 编写的,应该可以在 Google 应用引擎上运行。这就是我现在得到的(工作但没有容器标签)。

    gcs_file = cloudstorage.open(filename, 'w', content_type='video/mp4')
    response = urlfetch.fetch(link)
    base_link = link.rsplit('/', 1)[0]

    if response.content:
        lines = response.content.split('\n')
        logging.info('merge_m3u8() - got response for m3u8: %s' % response.content)
        ts_filenames = [line.rstrip() for line in lines if line.rstrip().endswith('.ts')]
        logging.info('merge_m3u8() - found %d items in playlist' % len(ts_filenames))
        for ts_file in ts_filenames:
            logging.info('merge_m3u8() - downloading file %s' % ts_file)
            response = urlfetch.fetch('%s/%s' % (base_link, ts_file))
            gcs_file.write(response.content)

        logging.info('merge_m3u8() - closing file %s' % filename)
        gcs_file.close()

最佳答案

有一个容器,这个容器就是TS。解析ts和写mp4不用ffmpeg也能搞定,但是代码量大。 (我用 C 编写了一个版本,专门设计为尽可能小,但它仍然超过 2000 SLOC)。格式非常不同,因此您不能简单地添加 mp4 元数据。你必须 demux 和 remux。但是,除了 ffmpeg 之外还有其他选项。例如 mp4box。

关于python - 在 GAE 上使用 Python 将 .ts 文件从 m3u8 合并到单个 mp4(无 ffmpeg),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31646713/

相关文章:

python - 如何从 .env 文件为 pytests 加载变量

python - 为什么 GQL 查询不匹配?

python - 使用 BeautifulSoup 在 python 中解析 Google App Engine 中的 HTML?

javascript - 使用 three.js 的 360 视频上的黑眼圈

java - 在java中将视频分割成图像帧

python - python字典中的多个赋值

python - 将数组与其差异对齐

python - 夏令时移动 1 小时时重建索引不正确

android - 如何制作基本的 App Engine Connected Android 项目?

authentication - 在生产服务器上运行 Agora 视频时出错,可在本地运行