mifi / lossless-cut

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

Inaccurate cuts with both keyframe and normal cutting #1087

Closed AdamSaketume26 closed 2 years ago

AdamSaketume26 commented 2 years ago

Share information to help me understand The file I am working with is a YouTube video, https://www.youtube.com/watch?v=R9At2ICm4LQ. You can use yt-dlp to work with the file if you choose to as well. In the following issue I will be describing the issue with regards to the 1080p version.

Best quality, 4k webm (currently) ~300 MB: yt-dlp https://www.youtube.com/watch?v=R9At2ICm4LQ 1080p mp4 ~100 MB: yt-dlp -f 137 https://www.youtube.com/watch?v=R9At2ICm4LQ

Describe the bug The main issue I am facing is that no matter how I choose to export my segments, there is an issue. To start, I was originally working with the webm 4k version and doing keyframe cuts. This did not follow my segmented keyframes and made the duration of the segments much longer. I tried normal cuts and at times it made the durations much shorter... assuming they properly rendered out in the first place. Doing this normal cut on the 4k footage made more than 50% of the clips corrupted (a few examples: all of the intro segments except for "Intro Part 1" and all of the "Wendy" segments).

Using the 1080p mp4 version with keyframe cutting was a better experience, but it was still exporting incorrect segments. For example, in "Intro Part 1" the segment starts as the flower effect is over, but the exported segment starts during that flower effect. Again, the duration is incorrect. The segment duration is at around 12.1 seconds, but the exported segment resulted in ~13.6 seconds.

I didn't bother looking into 1080p mp4 version with normal cutting in depth because it was wrong and corrupted too. In the same example, the "Intro Part 1" exported segment now starts later into what the segment should be and extends it as well. Additionally, it seems corrupted. The exported segment stops playing at 8 seconds of the 12 second clip, on one keyframe exactly after where I set the segment to end. Again, I didn't bother looking into this more because this result was more confusing to me than the previous 1080p keyframe cutting issues.

To Reproduce Steps to reproduce the behavior: Use the YT video I linked above with either version you want. I have attached the exact segments I am exporting to this issue. In order to have done so, I had to append txt to the files extension. If you choose to follow along to reproduce my problems, please rename the Lossless Cut Project file to remove txt from the end.

Red Velvet - Feel My Rhythm MV Main Timestamps 1080p.llc.txt or https://gist.github.com/AdamSaketume26/ddec5d641519b6eec7a8e41d156f4440

Afterwards, simply export with the following settings: image

Expected behavior I expect the exported segments to start from the respective cut-start and cut-end positions as indicated in the segments.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context

Problem Report Summary ``` No error { "state": { "filePath": "E:\\Kpop\\Red Velvet\\Feel My Rhythm\\Red Velvet 레드벨벳 'Feel My Rhythm' MV [R9At2ICm4LQ].mp4", "fileFormat": "mp4", "mainStreams": [ { "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": "avc1", "codec_tag": "0x31637661", "width": 1920, "height": 1080, "coded_width": 1920, "coded_height": 1080, "closed_captions": 0, "has_b_frames": 1, "sample_aspect_ratio": "1:1", "display_aspect_ratio": "16:9", "pix_fmt": "yuv420p", "level": 40, "color_range": "tv", "color_space": "bt709", "color_transfer": "bt709", "color_primaries": "bt709", "chroma_location": "left", "field_order": "progressive", "refs": 1, "is_avc": "true", "nal_length_size": "4", "r_frame_rate": "24000/1001", "avg_frame_rate": "24000/1001", "time_base": "1/24000", "start_pts": 0, "start_time": "0.000000", "duration_ts": 5694689, "duration": "237.278708", "bit_rate": "91502", "bits_per_raw_sample": "8", "disposition": { "default": 1, "dub": 0, "original": 0, "comment": 0, "lyrics": 0, "karaoke": 0, "forced": 0, "hearing_impaired": 0, "visual_impaired": 0, "clean_effects": 0, "attached_pic": 0, "timed_thumbnails": 0 }, "tags": { "creation_time": "2022-03-21T09:01:49.000000Z", "language": "und", "handler_name": "ISO Media file produced by Google Inc.", "vendor_id": "[0][0][0][0]" } } ], "copyStreamIdsByFile": { "E:\\Kpop\\Red Velvet\\Feel My Rhythm\\Red Velvet 레드벨벳 'Feel My Rhythm' MV [R9At2ICm4LQ].mp4": { "0": true } }, "cutSegments": [ { "start": 17.934583333333332, "end": 19.644624999999998 }, { "start": 34.28425, "end": 35.660624999999996 }, { "start": 55.84745833333333, "end": 57.97458333333333 }, { "start": 58.975583333333326, "end": 62.10370833333333 }, { "start": 71.15441666666666, "end": 72.57249999999999 }, { "start": 72.61420833333332, "end": 74.11570833333333 }, { "start": 115.53208333333332, "end": 117.90945833333332 }, { "start": 145.1867083333333, "end": 146.89675 }, { "start": 74.15741666666666, "end": 81.37295833333333 }, { "start": 136.38625, "end": 141.76662499999998 }, { "start": 178.84533333333331, "end": 183.39154166666665 }, { "start": 161.536375, "end": 165.08158333333333 }, { "start": 11.845166666666666, "end": 23.940583333333333 }, { "start": 25.27525, "end": 27.026999999999997 }, { "start": 30.155124999999998, "end": 33.24154166666666 }, { "start": 42.125416666666666, "end": 43.71033333333333 } ], "mainFileFormatData": { "filename": "E:\\Kpop\\Red Velvet\\Feel My Rhythm\\Red Velvet 레드벨벳 'Feel My Rhythm' MV [R9At2ICm4LQ].mp4", "nb_streams": 1, "nb_programs": 0, "format_name": "mov,mp4,m4a,3gp,3g2,mj2", "format_long_name": "QuickTime / MOV", "start_time": "0.000000", "duration": "237.278708", "size": "105634978", "bit_rate": "3561549", "probe_score": 100, "tags": { "major_brand": "dash", "minor_version": "0", "compatible_brands": "iso6avc1mp41", "creation_time": "2022-03-21T09:01:49.000000Z" } }, "rotation": 360, "shortestFlag": false }, "platform": "win32", "version": "3.44.0" } ```
oliko-tk commented 2 years ago

Yo te diria que cuando descaargaste el video la codificación fue pobre..

Te recomendaria que vuelvas a codificar el video con handbreake de acuerto a los fotoogramas reales del video .. y despues vuelvas a utizar el programa de losscut ..

mifi commented 2 years ago

Hi and thanks for your thorough report. I'm trying to understand, is the behaviour you're seeing with keyframe cut different from what is described in the readme known issues and limitations ? You could also try the new experimental smart cut mode.

AdamSaketume26 commented 2 years ago

Yo te diria que cuando descaargaste el video la codificación fue pobre..

Te recomendaria que vuelvas a codificar el video con handbreake de acuerto a los fotoogramas reales del video .. y despues vuelvas a utizar el programa de losscut ..

Is the video encoding bad for the mp4 too? I will try re-encoding with handbrake or ffmpeg to see if that helps but I don't see why it will

AdamSaketume26 commented 2 years ago

Hi and thanks for your thorough report. I'm trying to understand, is the behaviour you're seeing with keyframe cut different from what is described in the readme known issues and limitations ? You could also try the new experimental smart cut mode.

For the most part, yes. I did not notice the known issues. I did try smart cut but it did not work. In the same examples above, for the "Intro Part 1" clip it seems to start at the proper start time,but the export is not correct. After 3 seconds it suddenly skips to the around 3 seconds before the segment start. Weird behavior.

AdamSaketume26 commented 2 years ago

Yo te diria que cuando descaargaste el video la codificación fue pobre.. Te recomendaria que vuelvas a codificar el video con handbreake de acuerto a los fotoogramas reales del video .. y despues vuelvas a utizar el programa de losscut ..

Is the video encoding bad for the mp4 too? I will try re-encoding with handbrake or ffmpeg to see if that helps but I don't see why it will

I tried re encoding the mp4 with ffmpeg ffmpeg -i '.\Red Velvet 레드벨벳 ''Feel My Rhythm'' MV [R9At2ICm4LQ].mp4' -crf 16 -c:v libx264 "converted-x264.mp4" and I got better results using smart cut. Some clips still didn't finish at the right keyframe but these results were better than anything else. No other problems that I noticed from a few of the segments I previewed such as artifacting or random cuts or loops

Odd that smart cut gives me problems on the 4k webm and the 1080p, both with different behaviors. The 4K webm behavior was described above. The original 1080p version taken from ytdl ended up losing lots of quality in the first second or two of the exported segments which was weird. Not sure why the original lossless x264 mp4 resulted with the pixelated frames for the first second but the re-encoded x264 mp4 did not.

iopq commented 2 years ago

I have a similar issue, I jump by keyframes, but it's off by one keyframe.

Steps:

  1. jump into the middle of video, go next keyframe until you get to the part where you want to start the segment
  2. click start the segment
  3. go to the end where you want to end the segment
  4. export with keyframe cut

it's always one keyframe off for me, it goes before the keyframe where I start

note that if the keyframe is at 1:20 I might start the current segment at 1:25 (next keyframe) in order to get a cut starting at 1:20

iopq commented 2 years ago

I noticed that this only happens with webm, the mkv doesn't exhibit this behavior, so I have to cut differently based on which format I downloaded from Youtube

mifi commented 2 years ago

@iopq thanks for the input. there's a long (unresolved) discussion about this here also: #126

mifi commented 2 years ago

closing in favor of #1216