簡介與其他資料:
http://www.mobile01.com/topicdetail.php?f=510&t=3734550
其他範例:
http://www.mobile01.com/topicdetail.php?f=510&t=4487462
介紹
當你需要使用兩種或多種工具來處理影音時,例如 qaac 不支援 MKV 輸入,可以先使用 FFmpeg 轉換輸出為 WAV 檔案,然後將此輸出 WAV 檔案給 qaac 讀取來重新編碼輸出。但這個方法需要建立一個 WAV 暫存檔,如果你不想要建立暫存檔可以使用管道 (Pipe) 將 FFmpeg 輸出的 WAV 傳給 qaac 讀取。這方法既節省時間又節省儲存空間。
管道輸出
如果要使用 FFmpeg 輸出視音訊串流至管道 (Pipe),
你必須使用 -f 選項來指定 Muxer / 輸出檔案格式,輸出使用 '-'。
CMD:
ffmpeg -i INPUT -f FORMAT - | ......
範例:
FFmpeg → WAV:
ffmpeg -i input.m2ts -vn -async 1 -f wav - | qaac -o output.m4a -
FFmpeg → YUV4MPEG:
ffmpeg -i input.m2ts -an -f yuv4mpegpipe - | x265 -o output.mkv - --y4m
FFmpeg → MKV:
ffmpeg -i input.m2ts -c:v rawvideo -c:a pcm_s16le -f matroska - | ffmpeg -i - output.mp4
如果輸出格式是 Raw video,必須在讀取管道端的工具手動指定輸入格式、解析度、畫格速率。如果輸出格式是 PCM audio,則必須在讀取管道端的工具手動指定輸入格式、聲道數、頻率。
管道輸入
如果要使用 FFmpeg 從管道 (Pipe) 讀取視音訊串流,
你必須使用 "-i -" 選項來設定管道輸入。
CMD:
...... | ffmpeg -i - ......
範例:
WAV → FFmpeg:
ffmpeg -i input.m2ts -vn -async 1 -f wav - | ffmpeg -i - output.flac
YUV4MPEG → FFmpeg:
ffmpeg -i input.m2ts -an -f yuv4mpegpipe - | ffmpeg -i - output.mp4
MKV → FFmpeg:
ffmpeg -i input.m2ts -c:v rawvideo -c:a pcm_s16le -f matroska - | ffmpeg -i - output.mp4
如果輸入格式是 Raw video,必須在 FFmpeg 手動指定輸入格式 (-f)、解析度(-s)、畫格速率(-r)。如果輸出格式是 PCM audio,則必須在 FFmpeg 手動指定輸入格式 (-f)、聲道數(-ac)、頻率(-ar)。注意,輸入選項必須位於 -i 選項之前。
CMD:
PCM audio:
...... | ffmpeg -f FORMAT -ac CHANNELS -ar RATE -i - ......
RAW video:
...... | ffmpeg -f FORMAT -r FRAMERATE -s SIZE -i - ......
範例:
S16LE (PCM) → FFmpeg:
ffmpeg -i input.m2ts -vn -async 1 -ac 2 -ar 48000 -f s16le - | ffmpeg -f s16le -ac 2 -ar 48000 -i - output.flac
Raw video → FFmpeg:
ffmpeg -i input.m2ts -an -vsync cfr -r 24000/1001 -s 1280x720 -c:v rawvideo -f rawvideo - | ffmpeg -f rawvideo -r 24000/1001 -s 1280x720 -i - output.mp4