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

Regression in ffmpeg 6 #57

Open
m1k1o opened this issue Dec 31, 2024 · 3 comments
Open

Regression in ffmpeg 6 #57

m1k1o opened this issue Dec 31, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@m1k1o
Copy link
Owner

m1k1o commented Dec 31, 2024

There is a regression since ffmpeg 6 that breaks the segmenting.

Test script:

# Generate test file of 20 sec, with keyframes every 2sec
ffmpeg -loglevel warning -fflags +genpts \
    -f lavfi -i testsrc=duration=20:size=1280x720:rate=30 \
    -f lavfi -i sine=frequency=1000:duration=20 \
    -c:v libx264 -g 60 \
    -c:a aac -b:a 192k \
    -f mp4 -y -movflags +faststart /tmp/test.mp4;

# Seek to 10 sec and create three 2s segments (at 12,14,16)
ffmpeg -loglevel warning -ss 10 -i /tmp/test.mp4 -to 16 -copyts -c copy \
    -f segment \
    -segment_time_delta 0.2 \
    -segment_format mpegts \
    -segment_times 12,14,16 \
    -segment_start_number 5 \
    -segment_list_type csv \
    -segment_list pipe:1 /tmp/test_%03d.ts;

We can set up a simple dockerfile:

ARG VERSION=3.22
FROM alpine:${VERSION}
RUN apk add --no-cache ffmpeg
ENTRYPOINT [ "ffmpeg" ]

And then run scripts above with different versions.

docker build --build-arg VERSION=3.14 -t alpine-ffmpeg:3.14 .
docker run --rm alpine-ffmpeg:3.14 -version

Versions prior 6

ffmpeg version 4.2.4 (from alpine:3.11)
ffmpeg version 4.3.1 (from alpine:3.12)
ffmpeg version 4.3.3 (from alpine:3.13)
ffmpeg version 4.4.1 (from alpine:3.14)
ffmpeg version 5.0.3 (from alpine:3.16)
ffmpeg version 5.1.4 (from alpine:3.17)

test_005.ts,0.000000,12.000000
test_006.ts,12.000000,14.000000
test_007.ts,14.000000,16.000000
test_008.ts,16.000000,16.166667

Versions after 6

ffmpeg version 6.0.1 (from alpine:3.18)
ffmpeg version 6.1.1 (from alpine:3.19)
ffmpeg version 6.1.2 (from alpine:3.21)

test_005.ts,0.000000,16.166667

It seems that it requires now relative offet to the seeked time in segment_times instead of the absolute time.

Modified segmenter script:

ffmpeg -loglevel warning -ss 10 -i /tmp/test.mp4 -to 16 -copyts -c copy \
    -f segment \
    -segment_time_delta 0.2 \
    -segment_format mpegts \
    -segment_times 2,4,6 \
    -segment_start_number 5 \
    -segment_list_type csv \
    -segment_list pipe:1 /tmp/test_%03d.ts;

New output:

test_005.ts,0.000000,12.000000
test_006.ts,12.000000,14.000000
test_007.ts,14.000000,16.000000
test_008.ts,16.000000,16.166667
@m1k1o m1k1o added the bug Something isn't working label Dec 31, 2024
@m1k1o
Copy link
Owner Author

m1k1o commented Dec 31, 2024

Hotfix in a4b556b

@m1k1o
Copy link
Owner Author

m1k1o commented Jan 1, 2025

Additionally, sincle v6 in ffprobe's frame output pkt_pts_time was renamed to pts_time:

ffprobe /tmp/test.mp4 -skip_frame nokey -show_entries frame -select_streams v -of json

Before:

{
    "media_type": "video",
    "stream_index": 0,
    "key_frame": 1,
    "pkt_pts": 0,
    "pkt_pts_time": "0.000000",
    "pkt_dts": 60416,
    "pkt_dts_time": "3.933333",
    "best_effort_timestamp": 0,
    "best_effort_timestamp_time": "0.000000",
    "pkt_duration": 512,
    "pkt_duration_time": "0.033333",
    "pkt_pos": "23057",
    "pkt_size": "7976",
    "width": 1280,
    "height": 720,
    "pix_fmt": "yuv444p",
    "sample_aspect_ratio": "1:1",
    "pict_type": "I",
    "coded_picture_number": 0,
    "display_picture_number": 0,
    "interlaced_frame": 0,
    "top_field_first": 0,
    "repeat_pict": 0,
    "chroma_location": "left",
    "side_data_list": [
        {
            "side_data_type": "H.26[45] User Data Unregistered SEI message"
        }
    ]
}

After:

{
    "media_type": "video",
    "stream_index": 0,
    "key_frame": 1,
    "pts": 0,
    "pts_time": "0.000000",
    "pkt_dts": 60416,
    "pkt_dts_time": "3.933333",
    "best_effort_timestamp": 0,
    "best_effort_timestamp_time": "0.000000",
    "pkt_duration": 512,
    "pkt_duration_time": "0.033333",
    "duration": 512,
    "duration_time": "0.033333",
    "pkt_pos": "23057",
    "pkt_size": "7990",
    "width": 1280,
    "height": 720,
    "crop_top": 0,
    "crop_bottom": 0,
    "crop_left": 0,
    "crop_right": 0,
    "pix_fmt": "yuv444p",
    "sample_aspect_ratio": "1:1",
    "pict_type": "I",
    "coded_picture_number": 0,
    "display_picture_number": 0,
    "interlaced_frame": 0,
    "top_field_first": 0,
    "repeat_pict": 0,
    "chroma_location": "left",
    "side_data_list": [
        {
            "side_data_type": "H.26[45] User Data Unregistered SEI message"
        }
    ]
}

@m1k1o
Copy link
Owner Author

m1k1o commented Jan 1, 2025

According to docs:

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

According to this, following code should return two segments, one 2sec long and another 4sec long:

ffmpeg -loglevel warning -ss 10 -i /tmp/test.mp4 -to 16 -copyts -c copy \
    -f segment \
    -segment_time_delta 0.2 \
    -segment_format mpegts \
    -segment_times 2,4 \
    -segment_start_number 5 \
    -segment_list_type csv \
    -segment_list pipe:1 /tmp/test_%03d.ts;

But in reality we get two three ~2s segments:

test_005.ts,0.000000,12.000000
test_006.ts,12.000000,14.000000
test_007.ts,14.000000,16.166667

It seems like it is not skipping keyframes in the video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant