Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using the concat protocol (for MPEG TS) #1968

Open
4 tasks done
Undercover0007 opened this issue Apr 16, 2024 · 10 comments
Open
4 tasks done

Allow using the concat protocol (for MPEG TS) #1968

Undercover0007 opened this issue Apr 16, 2024 · 10 comments

Comments

@Undercover0007
Copy link

The fewer issues I have to read, the more new features I will have time to implement, so I ask that you please try these things first

Steps to reproduce

I trim 2 files (using only "seek keyframe"), they play fine after that. Then I open first trimmed file, then open the other one, a dialog box appears, I choose "Merge/concatenate with current file", "check compatability" ok, merge operation is completed successfully, it plays fine until it comes to the point where the files were merged. The video flickers for a second and from that moment the audio is shifted a little bit.
I make many this kind of operations (trimming + merging) with the same kind of files and this is second or third time I experience the problem. Could you take a look what could be wrong? The files are quite big (2x 350MB + merged 700MB), I am not sure if I can upload them here.

Expected behavior

After merge the resulting file should play fine.

Actual behavior

The video flickers for a second and audio is shifted from that point.

Provide an error report

No error message.

Share the file

No response

Share log from developer tools

No response

@mifi
Copy link
Owner

mifi commented Apr 21, 2024

Hard to say. Sometimes merging some files simply doesn't work due to limitation in the ffmpeg concat implentation. you could check FAQ and try to disable tracks and see if it makes a difference

@Undercover0007
Copy link
Author

Thank you for answer. Meanwhile I have gained some clues. First, I noticed the issue occurs in VLC Media Player, but does not occur in Windows Media Player. Second, when I make trimming and concatenating by ffmpeg (from command line), the issue does not occur, I mean VLC plays it properly (at least flickering is much shorter if at all and I don't feel any audio shift).
So for now I had to drop LosslessCut and switched to ffmpeg. I really like your application, naturally it is more convenient, especially when cutting many fragments of one video, but with audio shift it becomes useless.
If you like to find out what parameters I use to edit files with ffmpeg, etc. to improve your application I will be glad to provide all the details including all the video files.

@mifi
Copy link
Owner

mifi commented Apr 25, 2024

If you managed to losslessly concatenate using ffmpeg directly, mind to share which commands that produced a correct results?

@Undercover0007
Copy link
Author

Certainly, though I am sure you know them if I know them :) Without analyzing / comparing of the videos the commands probably will not be much of a help. I used this command for a few concatenating operations and got good results:
ffmpeg -f concat -safe 0 -i FileListToMerge.txt -c copy output.ts

I was happy with it until yesterday when concatenated three videos with the above command and from the weld between second and third one I got audio shift :(
I tried one more command today:
ffmpeg -i "concat:file01.ts|file02.ts|file03.ts" -c copy output.ts
but I haven't played it yet. I will do it probably tomorrow. I noticed I have to play the output file from the beginning to know it is ok, because if I rewind it the audio shift does not occur.

I am a novice about ffpmeg, just try what I find in Internet, so if you have any suggestions (switches) I could try just let me know here and I will be testing them.

@mifi
Copy link
Owner

mifi commented Apr 26, 2024

ffmpeg -f concat -safe 0 -i FileListToMerge.txt -c copy output.ts

This looks very similar to what losslesscut is already doing. So i'm not sure why it's working from the command line but not from losslesscut. PS losslesscut prints out the commands that it has run. "Tools -> last ffmpeg commands"

ffmpeg -i "concat:file01.ts|file02.ts|file03.ts" -c copy output.ts

interesting. this is the concat protocol, it is very simple in that it just concatenates the raw file data without demuxing (it's like simply concatenating the binary data of the files together). therefore it only works for some formats like MPEGTS which doesn't have any header at the beginning of the file.

@Undercover0007
Copy link
Author

Undercover0007 commented Apr 26, 2024

Thank you for your tips. They are really helpful. I made some more research and it looks you are absolutely right about the command

ffmpeg -f concat -safe 0 -i FileListToMerge.txt -c copy output.ts

The output generated by LosslessCut and ffmpeg is the same ("FC: no differences encountered"). The source of the issue with flickering and audio shift lays before merging. It lays during cut operation. This is my first conclusion. The second is that when I used

ffmpeg -i "concat:file01.ts|file02.ts" -c copy output.ts

command to concatenate the same two files the output comes with the flickering issue, but without audio shift issue.

I wonder if "seek keyframe" function in LosslessCut applies at MPEGTS files, because when I use

ffmpeg -ss 00:04:54.20 -to 00:33:08.60 -i ...

command to trim video defining fractions of a second it looks to cut precisely at that point without seeking and shifting back or forth to any keyframe. Does the TS format have keyframes? Am I able to definitely know if a file has keyframes?
The issue seems to be very subtle. Maybe it is enough to cut one frame back or forth to avoid the whole problem.
Maybe I should report that issue to VLC developer, because when I play the concatenated files in Windows Media Player it plays them smoothly without any flickering nor audio shift.
I will make more research about it and let you know. I would appreciate your tip about the keyframes mentioned above.

@mifi
Copy link
Owner

mifi commented May 3, 2024

Does the TS format have keyframes?

yes it does

Am I able to definitely know if a file has keyframes?

they should show up as dark lines on the timeline when you enable the keyframes button in losslesscut.

it's hard to say what's the problem exactly. it often take some experimenting to get the right output when losslessly cutting/merging.

@Undercover0007
Copy link
Author

Undercover0007 commented May 7, 2024

A few updates.

  1. Yes, you are right. I had the option enabled and when I disabled and enabled again I got a message to zoom the timeline to see the lines. It works. I also used ffmpeg to show and extract the keyframes. Yes, my TS files contain keyframes. Nevertheless, when I trim the files using the command

ffmpeg -ss 00:05:48.60 -to 00:25:47.20 -i "TVne01.ts" -c copy TVtr01.ts

I can do it very precisely, probably with accuracy to a single frame.

  1. I trim, concatenate files almost every day, because I record a series of videos from a tv channel, so I have an opportunity to experiment a lot. I can say the command

ffmpeg -i "concat:file01.ts|file02.ts" -c copy output.ts

works better. It still sometimes flickers at the weld on VLC, but no audio shift. At least for now.
So if you would like to improve LosslessCut I would recommend to use the command for merging MPEGTS files instead or give users a choice (checkbox?), though maybe it's an issue for VLC only.

  1. I still don't know how what to do to avoid the video flickering. For some cuts/merges it flickers, for some don't. No matter if I cut at keyframes or not. I don't know what is at the weld causing the flickering on VLC. I am not so good to analyze it.

That's all for now.

@mifi
Copy link
Owner

mifi commented May 8, 2024

Ok so to summarize, you'd like to be able to use the concat protocol instead of the concat demuxer which losslesscut currently uses.

e.g.ffmpeg -i "concat:file01.ts|file02.ts" -c copy output.ts

I will leave this as a feature request.

@mifi mifi changed the title Audio shift and video flicker after merging 2 files Allow using the concat protocol May 8, 2024
@mifi mifi changed the title Allow using the concat protocol Allow using the concat protocol (for MPEG TS) May 8, 2024
@Undercover0007
Copy link
Author

Undercover0007 commented May 9, 2024

For me it is less important, because I can do it purely by ffmpeg for the operations I am performing at the moment (trimming tv streams and merging some of them). However for many people using commands in command prompt is quite a big challenge. Maybe adding a radio button giving them 2 options (concat demuxer, concat protocol as you described them) with short proper floating description just for MPEGTS files would be good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants