[英]How to grab ffmpeg's output as binary and write it to a file on the fly such that video players can play it in real time?
[英]FFmpeg How to write video to a file
我想要的是
1. Get video packet from stream source
2. Decode it
3. And write that decoded data as video file(avi, mpeg etc)
我可以從文件中獲取視頻數據包(如AVPacket),也可以解碼並保存為圖像。(原始)(FFmpeg教程顯示如何操作)。 但我不能 (不知道) 將視頻數據寫入可由媒體播放器(如VLC)播放的文件 (其他)。
最好的祝願
Ps:如果可能的話,真正的代碼樣本會很棒......
現在我用av_interleaved_write進行測試,但我得到了奇怪的錯誤“非單調時間戳”(我無法控制媒體源的pts值)
一些額外的信息
在FFmpeg,我必須
我需要讀者和作家。 我可以讀取媒體源文件(甚至根據給定的格式對數據包進行編碼)。 但是我不能寫文件......(任何玩家都可以玩)
還有一些偽代碼
File myFile("MyTestFile.avi");
while ( source ->hasVideoPackets)
{
packet = source->GetNextVideoPacket();
Frame decodedFrame = Decode(packet);
VideoPacket encodedPacket = Encode( decodedFrame);
myFile.WriteFile(encodedPacket);
}
或者只是編寫沒有編碼解碼的原始文件
File myFile("MyTestFile.avi");
while ( source ->hasVideoPackets)
{
packet = source->GetNextVideoPacket();
myFile.WriteFile(packet);
}
然后
I can able to open MyTest.avi file with a player.
現在,在FFmpeg trunk的doc / examples / transcoding.c中有一個新的視頻轉碼示例 ,它完全符合您的需求: 解復用,解碼,過濾,編碼和復用的API示例。
這是針對當前的ffmpeg 2.4.4
您需要編寫一個編碼器來將原始數據轉換為所需的視頻格式
我在某些時候使用libx264和vorbis做了類似的事情。
一個代碼示例。 https://github.com/Themaister/SSNES/blob/master/record/ffemu.c
基本思想是,當您想對其進行編碼時,必須自己在AVFrame
設置時間戳。 然后你可以獲取該數據包並使用av_interleaved_write()
編寫它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.