mifi / lossless-cut

The swiss army knife of lossless video/audio editing
https://losslesscut.app/
GNU General Public License v2.0
25.93k stars 1.25k forks source link

Cutting and/or merging a file with subtitles causes corrupted output #1245

Open slrslr opened 2 years ago

slrslr commented 2 years ago

I have a lot of issues to go through, so in order to make it easier for me to help you, I ask that you please try these things first

Steps to reproduce

Hello, 3.46.2 AppImage on Debian stable.

### I suggest to skip these reproduction steps and follow my next post below where is also the source video file. Issue is also at trac.ffmpeg.org

I have drag & drop mp4 file, then .srt file, then click Export in aim to merge the subtitles with the video. MOV faststart ENABLED Leave MP4 metadata ENABLED Now i drag&drop resulting video (here downloadable sample of first 60 seconds - sample made by ffmpeg -ss "0" -t "60" -c:v copy -c:a copy) to LC and set two fragments (using key button to jump to key frames) in the first 2 minutes of the video. Click export, MOV faststart ENABLED (fails also when is DISABLED) Leave MP4 metadata ENABLED (fails also when is DISABLED) Keyframe cut Merge fragments Play the merged video (here uploaded) using VLC 3.0.17.4 (seems to be latest stable, is from flatpak https://www.videolan.org/vlc/#download ) and it is stuck for many seconds between the fragments, but then resume anyway.

when video freezes, this appear:

[00007fc52c04ee30] main filter warning: dropping pictures
[00007fc52c04ee30] main filter warning: dropping pictures
pulse audio output debug: underflow

then when it "resume" playback, it shows:

[0000556e012e2ed0] main audio output warning: playback way too early (-36128098): playing silence
[00007fc53404bf20] main video output warning: picture is too late to be displayed (missing 34889 ms)
[0000556e012e2ed0] main audio output debug: inserting 1734148 zeroes
[00007fc53404bf20] main video output warning: picture is too late to be displayed (missing 34764 ms)
[00007fc52c04ee30] main filter warning: dropping pictures

MPV player does not play the file correctly too (no freeze, but second fragment not played entirely) and shows:

[statusline] AV: 00:00:08 / 00:01:11 (11%) A-V:  0.000
[ad] Invalid audio PTS: 8.277333 -> 44.377000
[cplayer]                                                                                                                                                                                                                                   
[cplayer] Audio/Video desynchronisation detected! Possible reasons include too slow                                                                                                                                                         
[cplayer] hardware, temporary CPU spikes, broken drivers, and broken files. Audio                                                                                                                                                           
[cplayer] position will not match to the video (see A-V status field).                                                                                                                                                                      
[cplayer]                                                                                                                                                                                                                                   
[statusline] AV: 00:00:08 / 00:01:11 (11%) A-V: 36.100
[cplayer] Reset playback due to audio timestamp reset.
[vo/gpu/x11] Enabling screensaver.
[ffmpeg/video] h264: co located POCs unavailable
[ffmpeg/video] h264: co located POCs unavailable                                                                                                                                                                                            
[lavf] EOF reached.
[vd] Decoder format: 720x360 yuv420p auto/auto/auto/auto/auto CL=mpeg2/4/h264                                                                                                                                                               
[vd] Using container aspect ratio.                                                                                                                                                                                                          
[statusline] (...) AV: 00:00:00 / 00:01:11 (0%) A-V:  0.000
[cplayer] first video frame after restart shown
[cplayer] audio sync: sync_to_video=1, offset=-3.377000                                                      

ffplay plays it correctly after converting merged file to .mkv using ffmpeg (no extra parameters), mpv plays correctly and show only:

[ad] Invalid audio PTS: 8.283000 -> 44.383000
[cplayer] Reset playback due to audio timestamp reset.                                                                                                                                                                                      
[ffmpeg/video] h264: Missing reference picture, default is 0
[ffmpeg/video] h264: co located POCs unavailable

Is this something to be fixed please? Any idea on ffmpeg command that would encode file again and fix it as a workaround?

UPDATE - WORKAROUND:

It may help to first remux the file using MKVToolNix, meaning drag and drop video and external subtitle file/s to it and Multiplex (no re-encoding) into a new single video file. Then this resulting file cut in LosslessCut. It should work unlike when ext. subs are added into a LC.

Expected behavior

no freeze/pause playback

Actual behavior

freezes/pauses playback for many seconds then resumes

Provide an error report

https://bin.disroot.org/?59ddb152669bdff4#Bw4tzpCHHVU4ZzYHF65RqBkZok4agNU2KZ6opbPsr8uf

Share the file

source: https://drive.proton.me/urls/3DTPXCC724#LDbmx6W8cjPe resulting merged file with playback errors: https://drive.proton.me/urls/ARZQD2XVA8#B77D6jQefcop

Share log

-

mifi commented 1 year ago

Hi! Sorry for the delay here. I tried to download your source file, and cut/merge it according to your error report (two segments 00:00:09.259 - 00:00:17.434 and 00:00:26.068 - 00:00:29.404)

And the output file does play back successfully for me. Have you tried to experiment with the different settings? Here are mine:

Screenshot 2022-10-14 at 21 38 37
slrslr commented 1 year ago

When i set cut points same as yours, then it also plays good for me.

Here is my second attempt so you can quickly reproduce the issue. Please extract this 7z archive containing source file and .llc file and details how to export and play in VLC player (i have up to date package from Debian 11 - stable repository). Thank you

mifi commented 1 year ago

Thanks for sharing. I managed to reproduce the problem. I managed to fix the problem by disabling the 3rd track mov_text tx3g. When I disable that track it works:

Screenshot 2022-10-19 at 17 40 52

For some reason ffmpeg isn't able to correctly cut the subtitle track. I've updated troubleshooting docs to make this more clear.

cunlem commented 1 year ago

I've had identical problem with the subtitle track type embedded in MP4 file. It's the format used when downloading youtube video with yt-dlp and using --embed-subs option.

mifi commented 1 year ago

@cunlem does it work if you disable the subtitle track like I described?

cunlem commented 1 year ago

Yes excluding the subtitle track from export produces file without errors

mifi commented 1 year ago

Ok, then I think this is a bug in ffmpeg, and I don't know what I can do in losslesscut other than maybe warning the user that cutting/merging files with subtitles might not work and suggest them to disable subtitles.