[FFmpeg-trac] #10065(ffmpeg:new): Gap in video by -c copy in mkv opus

FFmpeg trac at avcodec.org
Wed Nov 23 14:03:01 EET 2022


#10065: Gap in video by -c copy in mkv opus
--------------------------------+--------------------------------------
             Reporter:  yumu    |                     Type:  defect
               Status:  new     |                 Priority:  normal
            Component:  ffmpeg  |                  Version:  git-master
             Keywords:          |               Blocked By:
             Blocking:          |  Reproduced by developer:  0
Analyzed by developer:  0       |
--------------------------------+--------------------------------------
 Summary of the bug:
 Each time I copy the mkv container containing opus with -c copy, the video
 is out of sync with the audio.
 So every time I set metadata or attach a file, the video shifts. This is
 unreasonable.

 How to reproduce:
 1. Make a video (maybe even an existing one)
 {{{
 ffmpeg -f lavfi -i smptehdbars=1920x1080:d=10 -f lavfi -i
 sine=frequency=1000:d=10 "a.mp4"
 }}}

 2. Convert audio to opus and store in mkv container
 {{{
 ffmpeg -i "a.mp4" -c:v copy -c:a libopus "a_opus.mkv"
 }}}

 3. Copy
 {{{
 ffmpeg -i "a_opus.mkv" -c copy "a_opus_copy.mkv"
 }}}

 Comparing a_opus.mkv and a_opus_copy.mkv in ffprobe, start_pts is
 increased by +7, start_time by +0.007, and TAG:DURATION by +0.007.
 {{{
 > ffprobe -hide_banner -show_streams a_opus.mkv
 Input #0, matroska,webm, from 'a_opus.mkv':
   Metadata:
     COMPATIBLE_BRANDS: isomiso2avc1mp41
     MAJOR_BRAND     : isom
     MINOR_VERSION   : 512
     ENCODER         : Lavf59.34.101
   Duration: 00:00:10.02, start: -0.007000, bitrate: 114 kb/s
   Stream #0:0: Video: h264 (High), yuv420p(tv, bt709/unknown/unknown,
 progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn
 (default)
     Metadata:
       HANDLER_NAME    : VideoHandler
       VENDOR_ID       : [0][0][0][0]
       ENCODER         : Lavc59.54.100 libx264
       DURATION        : 00:00:10.000000000
   Stream #0:1: Audio: opus, 48000 Hz, mono, fltp (default)
     Metadata:
       HANDLER_NAME    : SoundHandler
       VENDOR_ID       : [0][0][0][0]
       ENCODER         : Lavc59.54.100 libopus
       DURATION        : 00:00:10.015000000
 [STREAM]
 index=0
 codec_name=h264
 codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
 profile=High
 codec_type=video
 codec_tag_string=[0][0][0][0]
 codec_tag=0x0000
 width=1920
 height=1080
 coded_width=1920
 coded_height=1080
 closed_captions=0
 film_grain=0
 has_b_frames=2
 sample_aspect_ratio=1:1
 display_aspect_ratio=16:9
 pix_fmt=yuv420p
 level=40
 color_range=tv
 color_space=bt709
 color_transfer=unknown
 color_primaries=unknown
 chroma_location=left
 field_order=progressive
 refs=1
 is_avc=true
 nal_length_size=4
 id=N/A
 r_frame_rate=25/1
 avg_frame_rate=25/1
 time_base=1/1000
 start_pts=0
 start_time=0.000000
 duration_ts=N/A
 duration=N/A
 bit_rate=N/A
 max_bit_rate=N/A
 bits_per_raw_sample=8
 nb_frames=N/A
 nb_read_frames=N/A
 nb_read_packets=N/A
 extradata_size=51
 DISPOSITION:default=1
 DISPOSITION:dub=0
 DISPOSITION:original=0
 DISPOSITION:comment=0
 DISPOSITION:lyrics=0
 DISPOSITION:karaoke=0
 DISPOSITION:forced=0
 DISPOSITION:hearing_impaired=0
 DISPOSITION:visual_impaired=0
 DISPOSITION:clean_effects=0
 DISPOSITION:attached_pic=0
 DISPOSITION:timed_thumbnails=0
 DISPOSITION:captions=0
 DISPOSITION:descriptions=0
 DISPOSITION:metadata=0
 DISPOSITION:dependent=0
 DISPOSITION:still_image=0
 TAG:HANDLER_NAME=VideoHandler
 TAG:VENDOR_ID=[0][0][0][0]
 TAG:ENCODER=Lavc59.54.100 libx264
 TAG:DURATION=00:00:10.000000000
 [/STREAM]
 [STREAM]
 index=1
 codec_name=opus
 codec_long_name=Opus (Opus Interactive Audio Codec)
 profile=unknown
 codec_type=audio
 codec_tag_string=[0][0][0][0]
 codec_tag=0x0000
 sample_fmt=fltp
 sample_rate=48000
 channels=1
 channel_layout=mono
 bits_per_sample=0
 initial_padding=312
 id=N/A
 r_frame_rate=0/0
 avg_frame_rate=0/0
 time_base=1/1000
 start_pts=-7
 start_time=-0.007000
 duration_ts=N/A
 duration=N/A
 bit_rate=N/A
 max_bit_rate=N/A
 bits_per_raw_sample=N/A
 nb_frames=N/A
 nb_read_frames=N/A
 nb_read_packets=N/A
 extradata_size=19
 DISPOSITION:default=1
 DISPOSITION:dub=0
 DISPOSITION:original=0
 DISPOSITION:comment=0
 DISPOSITION:lyrics=0
 DISPOSITION:karaoke=0
 DISPOSITION:forced=0
 DISPOSITION:hearing_impaired=0
 DISPOSITION:visual_impaired=0
 DISPOSITION:clean_effects=0
 DISPOSITION:attached_pic=0
 DISPOSITION:timed_thumbnails=0
 DISPOSITION:captions=0
 DISPOSITION:descriptions=0
 DISPOSITION:metadata=0
 DISPOSITION:dependent=0
 DISPOSITION:still_image=0
 TAG:HANDLER_NAME=SoundHandler
 TAG:VENDOR_ID=[0][0][0][0]
 TAG:ENCODER=Lavc59.54.100 libopus
 TAG:DURATION=00:00:10.015000000
 [/STREAM]
 }}}

 {{{
 > ffprobe -hide_banner -show_streams a_opus_copy.mkv
 Input #0, matroska,webm, from 'a_opus_copy.mkv':
   Metadata:
     MINOR_VERSION   : 512
     COMPATIBLE_BRANDS: isomiso2avc1mp41
     MAJOR_BRAND     : isom
     ENCODER         : Lavf59.34.101
   Duration: 00:00:10.03, start: 0.000000, bitrate: 114 kb/s
   Stream #0:0: Video: h264 (High), yuv420p(tv, bt709/unknown/unknown,
 progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn
 (default)
     Metadata:
       HANDLER_NAME    : VideoHandler
       VENDOR_ID       : [0][0][0][0]
       ENCODER         : Lavc59.54.100 libx264
       DURATION        : 00:00:10.007000000
   Stream #0:1: Audio: opus, 48000 Hz, mono, fltp (default)
     Metadata:
       HANDLER_NAME    : SoundHandler
       VENDOR_ID       : [0][0][0][0]
       ENCODER         : Lavc59.54.100 libopus
       DURATION        : 00:00:10.028000000
 [STREAM]
 index=0
 codec_name=h264
 codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
 profile=High
 codec_type=video
 codec_tag_string=[0][0][0][0]
 codec_tag=0x0000
 width=1920
 height=1080
 coded_width=1920
 coded_height=1080
 closed_captions=0
 film_grain=0
 has_b_frames=2
 sample_aspect_ratio=1:1
 display_aspect_ratio=16:9
 pix_fmt=yuv420p
 level=40
 color_range=tv
 color_space=bt709
 color_transfer=unknown
 color_primaries=unknown
 chroma_location=left
 field_order=progressive
 refs=1
 is_avc=true
 nal_length_size=4
 id=N/A
 r_frame_rate=25/1
 avg_frame_rate=25/1
 time_base=1/1000
 start_pts=7
 start_time=0.007000
 duration_ts=N/A
 duration=N/A
 bit_rate=N/A
 max_bit_rate=N/A
 bits_per_raw_sample=8
 nb_frames=N/A
 nb_read_frames=N/A
 nb_read_packets=N/A
 extradata_size=51
 DISPOSITION:default=1
 DISPOSITION:dub=0
 DISPOSITION:original=0
 DISPOSITION:comment=0
 DISPOSITION:lyrics=0
 DISPOSITION:karaoke=0
 DISPOSITION:forced=0
 DISPOSITION:hearing_impaired=0
 DISPOSITION:visual_impaired=0
 DISPOSITION:clean_effects=0
 DISPOSITION:attached_pic=0
 DISPOSITION:timed_thumbnails=0
 DISPOSITION:captions=0
 DISPOSITION:descriptions=0
 DISPOSITION:metadata=0
 DISPOSITION:dependent=0
 DISPOSITION:still_image=0
 TAG:HANDLER_NAME=VideoHandler
 TAG:VENDOR_ID=[0][0][0][0]
 TAG:ENCODER=Lavc59.54.100 libx264
 TAG:DURATION=00:00:10.007000000
 [/STREAM]
 [STREAM]
 index=1
 codec_name=opus
 codec_long_name=Opus (Opus Interactive Audio Codec)
 profile=unknown
 codec_type=audio
 codec_tag_string=[0][0][0][0]
 codec_tag=0x0000
 sample_fmt=fltp
 sample_rate=48000
 channels=1
 channel_layout=mono
 bits_per_sample=0
 initial_padding=312
 id=N/A
 r_frame_rate=0/0
 avg_frame_rate=0/0
 time_base=1/1000
 start_pts=0
 start_time=0.000000
 duration_ts=N/A
 duration=N/A
 bit_rate=N/A
 max_bit_rate=N/A
 bits_per_raw_sample=N/A
 nb_frames=N/A
 nb_read_frames=N/A
 nb_read_packets=N/A
 extradata_size=19
 DISPOSITION:default=1
 DISPOSITION:dub=0
 DISPOSITION:original=0
 DISPOSITION:comment=0
 DISPOSITION:lyrics=0
 DISPOSITION:karaoke=0
 DISPOSITION:forced=0
 DISPOSITION:hearing_impaired=0
 DISPOSITION:visual_impaired=0
 DISPOSITION:clean_effects=0
 DISPOSITION:attached_pic=0
 DISPOSITION:timed_thumbnails=0
 DISPOSITION:captions=0
 DISPOSITION:descriptions=0
 DISPOSITION:metadata=0
 DISPOSITION:dependent=0
 DISPOSITION:still_image=0
 TAG:HANDLER_NAME=SoundHandler
 TAG:VENDOR_ID=[0][0][0][0]
 TAG:ENCODER=Lavc59.54.100 libopus
 TAG:DURATION=00:00:10.028000000
 [/STREAM]
 }}}

 Each time I repeated the copy in step 3, the video shifted in the same
 way, and VLC played the video later than the audio.

 Perhaps the following three conditions are necessary.
 - Video and audio streams are included.
 - The audio stream is opus (did not reproduce with mp3, aac, vorbis)
 - Container is mkv or webm (did not reproduce with ogg)

 Version of ffmpeg (on Windows) (downloaded from https://github.com/BtbN
 /FFmpeg-
 Builds/releases/download/autobuild-2022-11-22-12-40/ffmpeg-N-109165-g9f5a9a7499-win64-gpl.zip)
 {{{
 > ffmpeg -version
 ffmpeg version N-109165-g9f5a9a7499-20221122 Copyright (c) 2000-2022 the
 FFmpeg developers
 built with gcc 12.2.0 (crosstool-NG 1.25.0.90_cf9beb1)
 configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-
 config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64
 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug
 --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2
 --enable-zlib --enable-libfreetype --enable-libfribidi --enable-gmp
 --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl
 --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib
 --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth
 --enable-chromaprint --enable-libdav1d --enable-libdavs2 --disable-libfdk-
 aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme
 --enable-libkvazaar --enable-libass --enable-libbluray --enable-libjxl
 --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh
 --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2
 --disable-libmfx --enable-libvpl --enable-openal --enable-libopencore-
 amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg
 --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-
 schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1
 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi
 --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-
 libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-
 libxvid --enable-libzimg --enable-libzvbi --extra-
 cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread
 --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20221122
 libavutil      57. 43.100 / 57. 43.100
 libavcodec     59. 54.100 / 59. 54.100
 libavformat    59. 34.101 / 59. 34.101
 libavdevice    59.  8.101 / 59.  8.101
 libavfilter     8. 50.101 /  8. 50.101
 libswscale      6.  8.112 /  6.  8.112
 libswresample   4.  9.100 /  4.  9.100
 libpostproc    56.  7.100 / 56.  7.100
 }}}

 Also reproduced on Ubuntu 20.04.5 (7:4.2.7-0ubuntu0.1).
-- 
Ticket URL: <https://trac.ffmpeg.org/ticket/10065>
FFmpeg <https://ffmpeg.org>
FFmpeg issue tracker


More information about the FFmpeg-trac mailing list