• 请不要在回答技术问题时复制粘贴 AI 生成的内容
linbingqinag
V2EX  ›  程序员

視頻處理,

  •  
  •   linbingqinag · Aug 8, 2019 · 1866 views
    This topic created in 2481 days ago, the information mentioned may be changed or developed.

    如題, 想讀取一個視頻文件, 但是發現讀取出來不能播放了, 有同學可以看看什麼問題嗎? 以前沒有做過視頻處理

    
    
    package main
    
    import (
    	"bufio"
    	"os"
    )
    
    func checkError(err error) {
    	if err != nil {
    		panic(err)
    	}
    }
    func main() {
    	path := "/e22ca3cbcbb30eb2b39461602e8ff2ac.mp4"
    	outfile, err := os.Create("test.mp4")
    	checkError(err)
    	defer outfile.Close()
    
    	inFile, err := os.Open(path)
    	checkError(err)
    	defer inFile.Close()
    
    	scanner := bufio.NewScanner(inFile)
    	buf := make([]byte, 0, 1024*1024)
    	scanner.Buffer(buf, 10*1024*1024)
    
    	writer := bufio.NewWriter(outfile)
    
    	for scanner.Scan() {
    		print(scanner.Bytes())
    		_, res := writer.Write(scanner.Bytes())
    		checkError(res)
    	}
    }
    
    
    
    
    
    
    aliipay
        1
    aliipay  
       Aug 8, 2019
    这个和视频处理什么关系? 你这就读写文件,比较下两个文件是否一致就好了。
    很有可能是没有 close 文件导致没完全写入磁盘。
    a7a2a7a2
        2
    a7a2a7a2  
       Aug 8, 2019
    应该不是同行。。。

    建议去 github 搜索一下相关,例如如果是 h265 的,就找到他的解码 https://github.com/rainliu/GoHM
    其他类似。

    这个 https://github.com/adrg/libvlc-go 更适合你
    Oz2011
        3
    Oz2011  
       Aug 9, 2019
    你这段就是 copy 一个文件啊,如果源文件能放,copy 过去的不能放,比较两个文件是不是一样就是了。
    mp4 文件的 index 默认放在后面,确实有可能没有完全拷贝导致 index 没拷过去播放不了
    linbingqinag
        4
    linbingqinag  
    OP
       Aug 9, 2019
    solved
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1015 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 50ms · UTC 22:59 · PVG 06:59 · LAX 15:59 · JFK 18:59
    ♥ Do have faith in what you're doing.