
我產生的 mkv 容器(包含 h265 影片)缺少影片長度。有沒有辦法在管道輸入關閉之前設定它?
Input #0, matroska,webm, from 'camera01-20190815-203646.mkv':
Metadata:
ENCODER : Lavf58.20.100
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: hevc (Main), yuv420p(tv), 2048x1536, 1 fps, 1 tbr, 1k tbn, 1 tbc (default)
當前文件是使用以下命令建立的。 (謝謝吉安幫助解決這個問題):
ffmpeg \
-hide_banner \
-loglevel error \
-nostdin \
-nostats \
-xerror \
-stimeout 5000000 \
-thread_queue_size 2048 \
-reorder_queue_size 16000 \
-rtsp_transport tcp \
-i rtsp://xxx \
-c:v copy -an -sn -dn \
-bsf:v hevc_metadata=tick_rate=1 \
-f hevc - \
| \
ffmpeg \
-hide_banner \
-loglevel info \
-nostats \
-nostdin \
-xerror \
-f hevc \
-i - \
-c copy \
-f segment \
-segment_time 3600 \
-segment_format matroska \
-segment_format_options live=1:reserve_index_space=100k \
-strftime 1 \
"/srv/video/netcams/archive/recordall/camera01-%%Y%%m%%d-%%H%%M%%S.mkv"
有沒有簡單的方法可以在 mkv 寫入期間指定檔案長度或讓 ffmpeg 在關閉檔案段之前插入它?
答案1
因此,現在更接近解決方案:(
ffmpeg -f hevc -i - -c copy -f segment -segment_time 30 -segment_format matroska -strftime 1 camera01-%Y%m%d-%H%M%S.mkv
刪除了 Reserve_index_space 選項)。
向文件提供持續時間資料。然而,這並不是在每個片段開始時重置——而是每個片段的持續時間包括先前片段的持續時間。
find . -exec ffmpeg -hide_banner -i {} -f ffmetadata \; > /tmp/out.txt
Input #0, matroska,webm, from './camera01-20190819-212041.mkv':
Metadata:
ENCODER : Lavf58.20.100
Duration: 00:00:32.00, start: 0.000000, bitrate: 694 kb/s
Stream #0:0: Video: hevc (Main), yuv420p(tv), 2048x1536, 1 fps, 1 tbr, 1k tbn, 1 tbc (default)
Metadata:
DURATION : 00:00:32.000000000
Input #0, matroska,webm, from './camera01-20190819-212102.mkv':
Metadata:
ENCODER : Lavf58.20.100
Duration: 00:01:00.00, start: 32.000000, bitrate: 401 kb/s
Stream #0:0: Video: hevc (Main), yuv420p(tv), 2048x1536, 1 fps, 1 tbr, 1k tbn, 1 tbc (default)
Metadata:
DURATION : 00:01:00.000000000
Input #0, matroska,webm, from './camera01-20190819-212130.mkv':
Metadata:
ENCODER : Lavf58.20.100
Duration: 00:01:32.00, start: 60.000000, bitrate: 287 kb/s
Stream #0:0: Video: hevc (Main), yuv420p(tv), 2048x1536, 1 fps, 1 tbr, 1k tbn, 1 tbc (default)
Metadata:
DURATION : 00:01:32.000000000
我想知道是否有相當於“重置每個文件的計時資料”標誌......或同等標誌?
就在這裡。最終命令如下圖所示:
ffmpeg \
-hide_banner \
-loglevel info \
-nostats \
-nostdin \
-xerror \
-f hevc \
-i - \
-c copy \
-f segment \
-reset_timestamps 1 \
-segment_time 30 \
-segment_format matroska \
-strftime 1 \
"/srv/video/netcams/archive/recordall/camera01-%%Y%%m%%d-%%H%%M%%S.mkv"
(仍然看到虛假[segment @ 0x5652b57e1500] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
警告,我從未弄清楚如何刪除這些警告,但至少尋找有效持續時間的服務現在可以看到它。