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

ffmpeg segment_times options #387

Open
mo-han opened this issue Mar 31, 2024 · 4 comments
Open

ffmpeg segment_times options #387

mo-han opened this issue Mar 31, 2024 · 4 comments

Comments

@mo-han
Copy link

mo-han commented Mar 31, 2024

Problem/Use Case
splitting without transcoding results in segments overlaping at begining and ending.

Solutions

ffmpeg segment_times option

segment_times times

    Specify a list of split points. times contains a list of comma separated duration specifications, in increasing order. See also the segment_time option.

Proposed Implementation:

scenedetect just provide those split points, and let ffmpeg do the segment job.

Alternatives:

List any alternative solutions or related ideas you've considered.

Examples:

Attach or link to any relevant videos or images that are relevant.

@Breakthrough
Copy link
Owner

Breakthrough commented Mar 31, 2024

Without transcoding, isn't this the same as running ffmpeg several times with -c:v copy -c:a copy?

That being said I am curious if this might be a possible cause of #159

@mo-han
Copy link
Author

mo-han commented Apr 1, 2024

I've no idea about #159


running ffmpeg several times with -c:v copy -c:a copy

I assume you are refering to extracting one segment. IIRC it's different from segment.

Seeking while doing a codec copy

Using -ss as input/output option together with -c:v copy might not be accurate since ffmpeg is forced to only use/split on i-frames. Though it will—if possible—adjust the start time of the stream to a negative value to compensate for that. Basically, if you specify "second 157" and there is no key frame until second 159, it will include two seconds of audio (with no video) at the start, then will start from the first key frame. So be careful when splitting and doing codec copy.

https://stackoverflow.com/questions/43814119/split-a-video-with-overlap-between-segments

FFmpeg has a segment muxer which can segment the file in one command but it does not create overlapping segments so not suitable here.

I'm a noob about ffmpeg, since it's so complicated. But I'm sure the segment muxer won't output overlapping segments.

@Breakthrough
Copy link
Owner

Breakthrough commented Apr 1, 2024

I'm a noob about ffmpeg, since it's so complicated. But I'm sure the segment muxer won't output overlapping segments.

Likewise, could definitely use some guidance on the proper way to go about this. That being said, I think you can use list-scenes -n in your command, and the last line of the output should be the list of split points you need. It should be possible to use that as the arg to ffmpeg segments.

Can you try that, and let me know if that works? And if so, what command line arguments you are using?

I might opt to not switch how codec-copy mode works as it would break how output filenames are formatted. PySceneDetect supports much more formatting options for filenames than ffmpeg currently supports. That being said, it would be pretty easy to add or hack the code as this is similar to how mkvmerge splitting works. If the above works, I can look into adding a config file option for this.

@mo-han
Copy link
Author

mo-han commented Apr 3, 2024

Can you try that, and let me know if that works? And if so, what command line arguments you are using?

I'd love to, but not now, maybe a fews days later.


What do you think about this:

If you cut with stream copy (-c copy) you need to use the -avoid_negative_ts 1 option if you want to use that segment with the ​concat demuxer .

(https://trac.ffmpeg.org/wiki/Seeking#Cuttingsmallsections)

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

No branches or pull requests

2 participants