0

My generated mkv containers (containing h265 video) are missing the video length. Is there a way to set this before the piped input is closed?

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)

Currently files are created using the following command(s). (thanks to Gyan for helping with this):

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"

Is there a simple way to either specify the file length during the mkv writing or to have ffmpeg insert it before closing the file segment?

3
  • Add -report to both commands, run till 2-3 segments are created and share those files.
    – Gyan
    Aug 17, 2019 at 16:40
  • drive.google.com/drive/folders/…
    – Imaginator
    Aug 17, 2019 at 20:48
  • interestingly running ffprobe on the files shows the Duration and start times confused: Input #0, matroska,webm, from './camera01-20190819-211618.mkv': Metadata: Duration: 00:00:33.00, start: 0.000000, bitrate: 716 kb/s ... Metadata: DURATION : 00:00:33.000000000 Input #0, matroska,webm, from './camera01-20190819-211640.mkv': Metadata: Duration: 00:01:01.00, start: 33.000000, bitrate: 391 kb/s ```
    – Imaginator
    Aug 19, 2019 at 19:21

1 Answer 1

0

So getting somewhat closer to a solution now:
ffmpeg -f hevc -i - -c copy -f segment -segment_time 30 -segment_format matroska -strftime 1 camera01-%Y%m%d-%H%M%S.mkv (removed the reserve_index_space option).

gives duration data to the file. However this is not resetting at the beginning of each segment - instead each segment's duration includes the previous segments' duration.

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

I'm wondering if there is an equivalent of "reset timing data for each file" flag.... or equivalent?

Yes there is. The final command looks like this:

    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"

(Still seeing spurious [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 warnings which I've never worked out how to remove but at least services that look for a valid duration are now seeing it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .