From cc1385543d77c1e1d1b5485e8d84da5df39d07d4 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Tue, 16 May 2023 12:09:20 +0200 Subject: [PATCH] Add nopts-v1: Ignore packets with unset PTS on streamcopy --- Dockerfile.alpine | 1 + Dockerfile.alpine.rpi | 1 + Dockerfile.ubuntu.cuda | 1 + Dockerfile.ubuntu.vaapi | 1 + contrib/README.md | 139 +++++++++++++++++++------------------ contrib/ffmpeg-nopts.patch | 31 +++++++++ 6 files changed, 107 insertions(+), 67 deletions(-) create mode 100644 contrib/ffmpeg-nopts.patch diff --git a/Dockerfile.alpine b/Dockerfile.alpine index bbd88d9..a5d2a8e 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -68,6 +68,7 @@ RUN mkdir -p /dist && cd /dist && \ COPY ./contrib /contrib RUN cd /dist/ffmpeg-${FFMPEG_VERSION} && \ + patch -p1 < /contrib/ffmpeg-nopts.patch && \ patch -p1 < /contrib/ffmpeg-jsonstats.patch && \ patch -p1 < /contrib/ffmpeg-hlsbitrate.patch && \ ./configure \ diff --git a/Dockerfile.alpine.rpi b/Dockerfile.alpine.rpi index 1a77f9d..fce5e1a 100644 --- a/Dockerfile.alpine.rpi +++ b/Dockerfile.alpine.rpi @@ -76,6 +76,7 @@ RUN echo $uname RUN cd /dist/ffmpeg-${FFMPEG_VERSION} && \ apkArch="$(apk --print-arch)" && if [ $apkArch != "aarch64" ]; then MMAL_SUPPORT="--enable-mmal"; fi && \ apkArch="$(apk --print-arch)" && if [ $apkArch != "aarch64" ]; then OMX_SUPPORT="--enable-omx --enable-omx-rpi"; fi && \ + patch -p1 < /contrib/ffmpeg-nopts.patch && \ patch -p1 < /contrib/ffmpeg-jsonstats.patch && \ patch -p1 < /contrib/ffmpeg-hlsbitrate.patch && \ ./configure \ diff --git a/Dockerfile.ubuntu.cuda b/Dockerfile.ubuntu.cuda index cb9e98d..615cb0d 100644 --- a/Dockerfile.ubuntu.cuda +++ b/Dockerfile.ubuntu.cuda @@ -182,6 +182,7 @@ RUN mkdir -p /dist && cd /dist && \ COPY ./contrib /contrib RUN cd /dist/ffmpeg-${FFMPEG_VERSION} && \ + patch -p1 < /contrib/ffmpeg-nopts.patch && \ patch -p1 < /contrib/ffmpeg-jsonstats.patch && \ patch -p1 < /contrib/ffmpeg-hlsbitrate.patch && \ ./configure \ diff --git a/Dockerfile.ubuntu.vaapi b/Dockerfile.ubuntu.vaapi index 7f109e5..925a07f 100644 --- a/Dockerfile.ubuntu.vaapi +++ b/Dockerfile.ubuntu.vaapi @@ -180,6 +180,7 @@ RUN mkdir -p /dist && cd /dist && \ COPY ./contrib /contrib RUN cd /dist/ffmpeg-${FFMPEG_VERSION} && \ + patch -p1 < /contrib/ffmpeg-nopts.patch && \ patch -p1 < /contrib/ffmpeg-jsonstats.patch && \ patch -p1 < /contrib/ffmpeg-hlsbitrate.patch && \ ./configure \ diff --git a/contrib/README.md b/contrib/README.md index 9abb17b..fc7045e 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -1,12 +1,17 @@ # Patches + FFmpeg patches. +## No PTS + +Ignore packets during streamcopy that don't have a valid PTS value. ## HLS bitrate + Calculate bandwidth estimate for the hls master manifest. - ## JSON stats + This repository contains a patch for the FFmpeg program to provide detailed progress information. With this patch, FFmpeg will output the progress information in a JSON string that contains the data for each input and output stream individually. The JSON output is enabled by default. It can be enabled with the global `-jsonstats` switch on the command line. Use the `-stats` switch @@ -28,71 +33,71 @@ The same output but nicely formatted: ```json { - "bitrate_kbps": 1367.7, - "drop": 0, - "dup": 0, - "fps": 24.95, - "frame": 188, - "inputs": [ - { - "bitrate_kbps": 552960.0, - "codec": "rawvideo", - "coder": "rawvideo", - "fps": 24.95, - "frame": 188, - "height": 720, - "id": 0, - "pix_fmt": "rgb24", - "size_kb": 507600, - "stream": 0, - "type": "video", - "width": 1280 - }, - { - "bitrate_kbps": 705.6, - "codec": "pcm_u8", - "coder": "pcm_u8", - "frame": 314, - "id": 1, - "layout": "stereo", - "sampling_hz": 44100, - "size_kb": 628, - "stream": 0, - "type": "audio" - } - ], - "outputs": [ - { - "bitrate_kbps": 1365.6, - "codec": "h264", - "coder": "libx264", - "fps": 24.95, - "frame": 188, - "height": 720, - "id": 0, - "pix_fmt": "yuv420p", - "q": -1.0, - "size_kb": 1247, - "stream": 0, - "type": "video", - "width": 1280 - }, - { - "bitrate_kbps": 2.1, - "codec": "aac", - "coder": "aac", - "frame": 315, - "id": 0, - "layout": "stereo", - "sampling_hz": 44100, - "size_kb": 2, - "stream": 1, - "type": "audio" - } - ], - "q": -1.0, - "size_kb": 1249, - "speed": 0.993, - "time": "0h0m7.48s" + "bitrate_kbps": 1367.7, + "drop": 0, + "dup": 0, + "fps": 24.95, + "frame": 188, + "inputs": [ + { + "bitrate_kbps": 552960.0, + "codec": "rawvideo", + "coder": "rawvideo", + "fps": 24.95, + "frame": 188, + "height": 720, + "id": 0, + "pix_fmt": "rgb24", + "size_kb": 507600, + "stream": 0, + "type": "video", + "width": 1280 + }, + { + "bitrate_kbps": 705.6, + "codec": "pcm_u8", + "coder": "pcm_u8", + "frame": 314, + "id": 1, + "layout": "stereo", + "sampling_hz": 44100, + "size_kb": 628, + "stream": 0, + "type": "audio" + } + ], + "outputs": [ + { + "bitrate_kbps": 1365.6, + "codec": "h264", + "coder": "libx264", + "fps": 24.95, + "frame": 188, + "height": 720, + "id": 0, + "pix_fmt": "yuv420p", + "q": -1.0, + "size_kb": 1247, + "stream": 0, + "type": "video", + "width": 1280 + }, + { + "bitrate_kbps": 2.1, + "codec": "aac", + "coder": "aac", + "frame": 315, + "id": 0, + "layout": "stereo", + "sampling_hz": 44100, + "size_kb": 2, + "stream": 1, + "type": "audio" + } + ], + "q": -1.0, + "size_kb": 1249, + "speed": 0.993, + "time": "0h0m7.48s" } ``` diff --git a/contrib/ffmpeg-nopts.patch b/contrib/ffmpeg-nopts.patch new file mode 100644 index 0000000..9976ef1 --- /dev/null +++ b/contrib/ffmpeg-nopts.patch @@ -0,0 +1,31 @@ +From 357b3d157b08ca5c7b91f605136bf140a4453fe7 Mon Sep 17 00:00:00 2001 +From: Ingo Oppermann +Date: Tue, 16 May 2023 11:19:17 +0200 +Subject: [PATCH v1] Ignore packets with unset PTS on streamcopy + +--- + fftools/ffmpeg.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c +index e7384f05..3385482b 100644 +--- a/fftools/ffmpeg.c ++++ b/fftools/ffmpeg.c +@@ -1858,8 +1858,11 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p + if (av_packet_ref(opkt, pkt) < 0) + exit_program(1); + +- if (pkt->pts != AV_NOPTS_VALUE) ++ if (pkt->pts != AV_NOPTS_VALUE) { + opkt->pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time; ++ } else { ++ return; ++ } + + if (pkt->dts == AV_NOPTS_VALUE) { + opkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase); + +base-commit: 2bca71f4986725d7cf0d441e2f82a790d0a0c717 +-- +2.39.2 (Apple Git-143) +