mpv icon indicating copy to clipboard operation
mpv copied to clipboard

Videos trimmed by Quicktime fail to play properly

Open low-batt opened this issue 2 years ago • 4 comments

Important Information

Provide following Information:

  • mpv version: 0.34.1
  • macOS Version: 12.4
  • Source of the mpv binary or bundle: stolendata
  • If known which version of mpv introduced the problem: unknown
  • Possible screenshot or video of visual glitches

The visual glitch is that shortly after playback starts the video freezes for a while before continuing to play. One aspect of the problem can be seen in this screenshot taken before playback has started by using the --pause option. Notice the current playback position timestamp in the on screen controller is negative: low-batt-mpv-quicktime-trim-issue

Shouldn't this option, which is enabled by default, have insured the start time is 0?:

--rebase-start-time=<yes|no> Whether to move the file start time to 00:00:00 (default: yes). This is less awkward for files which start at a random timestamp, such as transport streams. On the other hand, if there are timestamp resets, the resulting behavior can be rather weird. For this reason, and in case you are actually interested in the real timestamps, this behavior can be disabled with no.

Reproduction steps

Merely play the linked video in the sample files section below. The video will start playing without audio. Then the video will freeze. At that point the audio will start playing. Eventually video playback will resume.

The origin of this issue is IINA issue https://github.com/iina/iina/issues/3848. The reporter of that issue has been using Quicktime on a Mac to trim videos. The resulting videos play fine using Quicktime or VLC, but exhibit the undesirable behavior when starting playback if played under IINA or mpv.

The playback behavior experienced in this issue matches the behavior reported in issue https://github.com/mpv-player/mpv/issues/8876. However that issue concerns videos cut by FFmpeg running under Linux and as pointed out in that issue there are other ways to cut files using FFmpeg, for example using the avoid_negative_ts option. This issue with videos trimmed by Quicktime is more of a problem as Quicktime does not provide Mac users any options on how videos are trimmed.

As in https://github.com/mpv-player/mpv/issues/8876 mpv is reporting A/V desynchronization when playing the file created by Quicktime:

[  21.895][w][cplayer] Audio/Video desynchronisation detected! Possible reasons include too slow

To create a video that demonstrates this problem:

  • Pick a video that has large gaps between I-frames
  • Open the video on a Mac with using Quicktime
  • Use the Quicktime trim feature to trim away some of the start of the video
  • Save the trimmed video
  • Play the trimmed video using mpv looking for glitches when playback begins

How severe the playback glitch is depends upon where the video is cut in relation to I-frames.

Expected behavior

Mac users trimming a file using Quicktime expect the resulting file will play without glitches using IINA, mpv, Quicktime or VLC.

Actual behavior

The video starts playing without audio. Then the video freezes and the audio starts playing. Eventually the video resumes playing.

Log file

https://0x0.st/oQj7.log

The log file was generated by running mpv like so:

low-batt@gag quicktime-issue$ /Applications/mpv.app/Contents/MacOS/mpv -no-config -v -v --log-file=low-batt-mpv-quicktime-trim-issue.log --pause --script-opts=osc-visibility=always low-batt-mpv-quicktime-trim-issue.mp4 

Sample files

https://0x0.st/oQjF.mp4

This is the video low-batt-mpv-quicktime-trim-issue.mp4 created by using the Quicktime trim function.

low-batt avatar Jul 05 '22 04:07 low-batt

on my end with --video-sync=display-resample at least the glitch is gone. audio still starts late or rather the video starts too early compared to vlc or quicktime.

what i observed vlc and quicktime start the video at a later point of time, mpv on the other hand shows ~3sec more video at the beginning (the reason why the audio is probably missing). which suggests the video is wrongly 'trimmed'/'offset' within mpv internally, eg it might need to ignore those early video frames(?).

vlc isn't completely glitch free here either. it sometimes shows the first frame (the same as on mpv) and sometimes doesn't and is also 'stuck' for a little bit in some cases at the beginning.

to demonstrate what i mean. Screenshot 2022-07-05 at 11 36 09

i am not sure if this is a decode, demuxer oder metadata problem. this problem should not be mac specific, maybe someone can confirm? i would remove the mac label in that case.

Akemi avatar Jul 05 '22 09:07 Akemi

Yeah this happens on linux too.

Dudemanguy avatar Jul 05 '22 13:07 Dudemanguy

Anyone know if the MPEG standard has anything to say about how a compliant player should behave given this file?

FFprobe shows the file has several seconds of video before audio starts.

FFprobe Output:
low-batt@gag quicktime-issue$ ffprobe -of compact -show_packets -show_entries packet=codec_type,pts_time low-batt-mpv-quicktime-trim-issue.mp4
ffprobe version 5.0.1 Copyright (c) 2007-2022 the FFmpeg developers
  built with Apple clang version 13.1.6 (clang-1316.0.21.2)
  configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0.1 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon
  libavutil      57. 17.100 / 57. 17.100
  libavcodec     59. 18.100 / 59. 18.100
  libavformat    59. 16.100 / 59. 16.100
  libavdevice    59.  4.100 / 59.  4.100
  libavfilter     8. 24.100 /  8. 24.100
  libswscale      6.  4.100 /  6.  4.100
  libswresample   4.  3.100 /  4.  3.100
  libpostproc    56.  3.100 / 56.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'low-batt-mpv-quicktime-trim-issue.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf59.16.100
  Duration: 00:00:15.05, start: 0.000000, bitrate: 2727 kb/s
  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 1953 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
    Metadata:
      handler_name    : Core Media Video
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp, 341 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
      vendor_id       : [0][0][0][0]
packet|codec_type=video|pts_time=-3.233333
packet|codec_type=video|pts_time=-3.166667
packet|codec_type=video|pts_time=-3.200000
packet|codec_type=video|pts_time=-3.216667
packet|codec_type=video|pts_time=-3.183333
packet|codec_type=video|pts_time=-3.100000
packet|codec_type=video|pts_time=-3.133333
packet|codec_type=video|pts_time=-3.150000
packet|codec_type=video|pts_time=-3.116667
packet|codec_type=video|pts_time=-3.033333
packet|codec_type=video|pts_time=-3.066667
packet|codec_type=video|pts_time=-3.083333
packet|codec_type=video|pts_time=-3.050000
packet|codec_type=video|pts_time=-2.966667
packet|codec_type=video|pts_time=-3.000000
packet|codec_type=video|pts_time=-3.016667
packet|codec_type=video|pts_time=-2.983333
packet|codec_type=video|pts_time=-2.900000
packet|codec_type=video|pts_time=-2.933333
packet|codec_type=video|pts_time=-2.950000
packet|codec_type=video|pts_time=-2.916667
packet|codec_type=video|pts_time=-2.833333
packet|codec_type=video|pts_time=-2.866667
packet|codec_type=video|pts_time=-2.883333
packet|codec_type=video|pts_time=-2.850000
packet|codec_type=video|pts_time=-2.766667
packet|codec_type=video|pts_time=-2.800000
packet|codec_type=video|pts_time=-2.816667
packet|codec_type=video|pts_time=-2.783333
packet|codec_type=video|pts_time=-2.700000
packet|codec_type=video|pts_time=-2.733333
packet|codec_type=video|pts_time=-2.750000
packet|codec_type=video|pts_time=-2.716667
packet|codec_type=video|pts_time=-2.633333
packet|codec_type=video|pts_time=-2.666667
packet|codec_type=video|pts_time=-2.683333
packet|codec_type=video|pts_time=-2.650000
packet|codec_type=video|pts_time=-2.566667
packet|codec_type=video|pts_time=-2.600000
packet|codec_type=video|pts_time=-2.616667
packet|codec_type=video|pts_time=-2.583333
packet|codec_type=video|pts_time=-2.500000
packet|codec_type=video|pts_time=-2.533333
packet|codec_type=video|pts_time=-2.550000
packet|codec_type=video|pts_time=-2.516667
packet|codec_type=video|pts_time=-2.433333
packet|codec_type=video|pts_time=-2.466667
packet|codec_type=video|pts_time=-2.483333
packet|codec_type=video|pts_time=-2.450000
packet|codec_type=video|pts_time=-2.366667
packet|codec_type=video|pts_time=-2.400000
packet|codec_type=video|pts_time=-2.416667
packet|codec_type=video|pts_time=-2.383333
packet|codec_type=video|pts_time=-2.300000
packet|codec_type=video|pts_time=-2.333333
packet|codec_type=video|pts_time=-2.350000
packet|codec_type=video|pts_time=-2.316667
packet|codec_type=video|pts_time=-2.233333
packet|codec_type=video|pts_time=-2.266667
packet|codec_type=video|pts_time=-2.283333
packet|codec_type=video|pts_time=-2.250000
packet|codec_type=video|pts_time=-2.166667
packet|codec_type=video|pts_time=-2.200000
packet|codec_type=video|pts_time=-2.216667
packet|codec_type=video|pts_time=-2.183333
packet|codec_type=video|pts_time=-2.100000
packet|codec_type=video|pts_time=-2.133333
packet|codec_type=video|pts_time=-2.150000
packet|codec_type=video|pts_time=-2.116667
packet|codec_type=video|pts_time=-2.033333
packet|codec_type=video|pts_time=-2.066667
packet|codec_type=video|pts_time=-2.083333
packet|codec_type=video|pts_time=-2.050000
packet|codec_type=video|pts_time=-1.966667
packet|codec_type=video|pts_time=-2.000000
packet|codec_type=video|pts_time=-2.016667
packet|codec_type=video|pts_time=-1.983333
packet|codec_type=video|pts_time=-1.900000
packet|codec_type=video|pts_time=-1.933333
packet|codec_type=video|pts_time=-1.950000
packet|codec_type=video|pts_time=-1.916667
packet|codec_type=video|pts_time=-1.833333
packet|codec_type=video|pts_time=-1.866667
packet|codec_type=video|pts_time=-1.883333
packet|codec_type=video|pts_time=-1.850000
packet|codec_type=video|pts_time=-1.766667
packet|codec_type=video|pts_time=-1.800000
packet|codec_type=video|pts_time=-1.816667
packet|codec_type=video|pts_time=-1.783333
packet|codec_type=video|pts_time=-1.700000
packet|codec_type=video|pts_time=-1.733333
packet|codec_type=video|pts_time=-1.750000
packet|codec_type=video|pts_time=-1.716667
packet|codec_type=video|pts_time=-1.633333
packet|codec_type=video|pts_time=-1.666667
packet|codec_type=video|pts_time=-1.683333
packet|codec_type=video|pts_time=-1.650000
packet|codec_type=video|pts_time=-1.566667
packet|codec_type=video|pts_time=-1.600000
packet|codec_type=video|pts_time=-1.616667
packet|codec_type=video|pts_time=-1.583333
packet|codec_type=video|pts_time=-1.500000
packet|codec_type=video|pts_time=-1.533333
packet|codec_type=video|pts_time=-1.550000
packet|codec_type=video|pts_time=-1.516667
packet|codec_type=video|pts_time=-1.433333
packet|codec_type=video|pts_time=-1.466667
packet|codec_type=video|pts_time=-1.483333
packet|codec_type=video|pts_time=-1.450000
packet|codec_type=video|pts_time=-1.366667
packet|codec_type=video|pts_time=-1.400000
packet|codec_type=video|pts_time=-1.416667
packet|codec_type=video|pts_time=-1.383333
packet|codec_type=video|pts_time=-1.300000
packet|codec_type=video|pts_time=-1.333333
packet|codec_type=video|pts_time=-1.350000
packet|codec_type=video|pts_time=-1.316667
packet|codec_type=video|pts_time=-1.233333
packet|codec_type=video|pts_time=-1.266667
packet|codec_type=video|pts_time=-1.283333
packet|codec_type=video|pts_time=-1.250000
packet|codec_type=video|pts_time=-1.166667
packet|codec_type=video|pts_time=-1.200000
packet|codec_type=video|pts_time=-1.216667
packet|codec_type=video|pts_time=-1.183333
packet|codec_type=video|pts_time=-1.100000
packet|codec_type=video|pts_time=-1.133333
packet|codec_type=video|pts_time=-1.150000
packet|codec_type=video|pts_time=-1.116667
packet|codec_type=video|pts_time=-1.033333
packet|codec_type=video|pts_time=-1.066667
packet|codec_type=video|pts_time=-1.083333
packet|codec_type=video|pts_time=-1.050000
packet|codec_type=video|pts_time=-0.966667
packet|codec_type=video|pts_time=-1.000000
packet|codec_type=video|pts_time=-1.016667
packet|codec_type=video|pts_time=-0.983333
packet|codec_type=video|pts_time=-0.900000
packet|codec_type=video|pts_time=-0.933333
packet|codec_type=video|pts_time=-0.950000
packet|codec_type=video|pts_time=-0.916667
packet|codec_type=video|pts_time=-0.833333
packet|codec_type=video|pts_time=-0.866667
packet|codec_type=video|pts_time=-0.883333
packet|codec_type=video|pts_time=-0.850000
packet|codec_type=video|pts_time=-0.766667
packet|codec_type=video|pts_time=-0.800000
packet|codec_type=video|pts_time=-0.816667
packet|codec_type=video|pts_time=-0.783333
packet|codec_type=video|pts_time=-0.700000
packet|codec_type=video|pts_time=-0.733333
packet|codec_type=video|pts_time=-0.750000
packet|codec_type=video|pts_time=-0.716667
packet|codec_type=video|pts_time=-0.633333
packet|codec_type=video|pts_time=-0.666667
packet|codec_type=video|pts_time=-0.683333
packet|codec_type=video|pts_time=-0.650000
packet|codec_type=video|pts_time=-0.566667
packet|codec_type=video|pts_time=-0.600000
packet|codec_type=video|pts_time=-0.616667
packet|codec_type=video|pts_time=-0.583333
packet|codec_type=video|pts_time=-0.500000
packet|codec_type=video|pts_time=-0.533333
packet|codec_type=video|pts_time=-0.550000
packet|codec_type=video|pts_time=-0.516667
packet|codec_type=video|pts_time=-0.433333
packet|codec_type=video|pts_time=-0.466667
packet|codec_type=video|pts_time=-0.483333
packet|codec_type=video|pts_time=-0.450000
packet|codec_type=video|pts_time=-0.366667
packet|codec_type=video|pts_time=-0.400000
packet|codec_type=video|pts_time=-0.416667
packet|codec_type=video|pts_time=-0.383333
packet|codec_type=video|pts_time=-0.300000
packet|codec_type=video|pts_time=-0.333333
packet|codec_type=video|pts_time=-0.350000
packet|codec_type=video|pts_time=-0.316667
packet|codec_type=video|pts_time=-0.233333
packet|codec_type=video|pts_time=-0.266667
packet|codec_type=video|pts_time=-0.283333
packet|codec_type=video|pts_time=-0.250000
packet|codec_type=video|pts_time=-0.166667
packet|codec_type=video|pts_time=-0.200000
packet|codec_type=video|pts_time=-0.216667
packet|codec_type=video|pts_time=-0.183333
packet|codec_type=video|pts_time=-0.100000
packet|codec_type=video|pts_time=-0.133333
packet|codec_type=video|pts_time=-0.150000
packet|codec_type=video|pts_time=-0.116667
packet|codec_type=video|pts_time=-0.033333
packet|codec_type=video|pts_time=-0.066667
packet|codec_type=video|pts_time=-0.083333
packet|codec_type=video|pts_time=-0.050000
packet|codec_type=video|pts_time=0.033333
packet|codec_type=audio|pts_time=-0.039229|side_data|side_data_type=Skip Samples|skip_samples=1883|discard_padding=0|skip_reason=0|discard_reason=0

packet|codec_type=video|pts_time=0.000000
packet|codec_type=audio|pts_time=-0.017896
packet|codec_type=video|pts_time=-0.016667
packet|codec_type=video|pts_time=0.016667
packet|codec_type=audio|pts_time=0.003438
packet|codec_type=video|pts_time=0.100000
packet|codec_type=audio|pts_time=0.024771
packet|codec_type=video|pts_time=0.066667
packet|codec_type=audio|pts_time=0.046104
packet|codec_type=video|pts_time=0.050000
packet|codec_type=video|pts_time=0.083333
packet|codec_type=audio|pts_time=0.067437
packet|codec_type=video|pts_time=0.166667
packet|codec_type=audio|pts_time=0.088771
packet|codec_type=video|pts_time=0.133333
packet|codec_type=audio|pts_time=0.110104
packet|codec_type=video|pts_time=0.116667
packet|codec_type=audio|pts_time=0.131437

Playing with VLC some more I was able to see a small glitch at startup. Pausing VLC and backing it up shows it does initially show the same frame as mpv, but then quickly skips to the point where audio starts. low-batt-mpv-quicktime-trim-issue-vlc

low-batt avatar Jul 05 '22 13:07 low-batt

Shouldn't this option, which is enabled by default, have insured the start time is 0?:

That is not true for mp4 files, just checked for 10 second positive video from Apple TV+, mpv prints 09 seconds for audio, for video and same 10 seconds (you cannot force 9 seconds) for audio (audio is still at 9 seconds)+video. Instead of doing gapless audio for AAC and EAC3 as everyone else (using an editlist for track 2 (audio track)), they just put audio timestamps before video, while video timestamps start at 10 perfectly.

Same happens here.

There is also an editlist with strange value in media time for track 1 (video). In fact VLC corrupts the video.

ZaquL avatar Aug 10 '22 21:08 ZaquL