Merge ~liushuyu-011/ubuntu/+source/dvbcut:ubuntu/devel into ubuntu/+source/dvbcut:ubuntu/devel

Proposed by Zixing Liu
Status: Merged
Merged at revision: 6f85fc1a1a70aadd303f375e674ef070dd8d4f2f
Proposed branch: ~liushuyu-011/ubuntu/+source/dvbcut:ubuntu/devel
Merge into: ubuntu/+source/dvbcut:ubuntu/devel
Diff against target: 232 lines (+201/-0)
5 files modified
debian/changelog (+7/-0)
debian/patches/0001-lavfmuxer-handle-invalid-audio-headers-at-the-beginn.patch (+70/-0)
debian/patches/0002-lavfmuxer-support-codecpar-and-prevent-core-dumps-be.patch (+69/-0)
debian/patches/1000-ffmpeg-7-api.patch (+52/-0)
debian/patches/series (+3/-0)
Reviewer Review Type Date Requested Status
Graham Inggs (community) Approve
Review via email: mp+473324@code.launchpad.net

Description of the change

This merge proposal fixes FTBFS with dvbcut. Some patches are backported from the upstream; one of the patches that adapt to FFmpeg 7 is not from the upstream.

To post a comment you must log in.
Revision history for this message
Graham Inggs (ginggs) wrote :

Looks good to me, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index dd80f51..a75ac4b 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+dvbcut (0.7.4-1ubuntu1) oracular; urgency=medium
7+
8+ * d/patches: backport upstream patches
9+ * d/p/1000-ffmpeg-7-api.patch: fix FTBFS with FFMpeg 7
10+
11+ -- Zixing Liu <zixing.liu@canonical.com> Mon, 16 Sep 2024 16:18:10 -0600
12+
13 dvbcut (0.7.4-1build4) noble; urgency=medium
14
15 * No-change rebuild for CVE-2024-3094
16diff --git a/debian/patches/0001-lavfmuxer-handle-invalid-audio-headers-at-the-beginn.patch b/debian/patches/0001-lavfmuxer-handle-invalid-audio-headers-at-the-beginn.patch
17new file mode 100644
18index 0000000..08c7e61
19--- /dev/null
20+++ b/debian/patches/0001-lavfmuxer-handle-invalid-audio-headers-at-the-beginn.patch
21@@ -0,0 +1,70 @@
22+From 3cfa00f8617e94ea41cd7c47bbc4733ab72838b7 Mon Sep 17 00:00:00 2001
23+From: cypline <124210907+cypline@users.noreply.github.com>
24+Date: Mon, 6 Feb 2023 02:17:01 +0100
25+Subject: [PATCH 1/2] lavfmuxer: handle invalid audio headers at the beginning
26+
27+This is to fix streams where the current code is not able to parse the stream and collect valid codec information as of invalid header. It tries to parse the stream until a valid packet is found and sample_rate is filled. Because if this is missing, the export crashes. If newer versions of ffmpeg are used the patch for codecpar will be needed.
28+
29+Closes: #18
30+---
31+ src/lavfmuxer.cpp | 26 +++++++++++++++++++++-----
32+ 1 file changed, 21 insertions(+), 5 deletions(-)
33+
34+diff --git a/src/lavfmuxer.cpp b/src/lavfmuxer.cpp
35+index 9e495c8..96b92fb 100644
36+--- a/src/lavfmuxer.cpp
37++++ b/src/lavfmuxer.cpp
38+@@ -61,6 +61,8 @@ lavfmuxer::lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg,
39+ s->sample_aspect_ratio = codec->sample_aspect_ratio;
40+ s->time_base = codec->time_base;
41+
42++ int avlogflags = av_log_get_flags();
43++
44+ for (int i=0;i<mpg.getaudiostreams();++i)
45+ if (audiostreammask & (1u<<i)) {
46+ int astr=audiostream(i);
47+@@ -77,7 +79,8 @@ lavfmuxer::lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg,
48+ streamhandle sh(mpg.getinitialoffset());
49+ streamdata *sd=sh.newstream(astr,mpg.getstreamtype(astr),mpg.istransportstream());
50+
51+- while (sh.fileposition < mpg.getinitialoffset()+(4<<20)) {
52++ int srerror = 0;
53++ while (sh.fileposition < mpg.getinitialoffset()+(8<<20)) {
54+ if (mpg.streamreader(sh)<=0)
55+ break;
56+
57+@@ -95,14 +98,27 @@ lavfmuxer::lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg,
58+
59+ av_packet_free(&pkt);
60+ av_frame_free(&frame);
61+- avcodec_close(codec);
62+- }
63+- break;
64+- }
65++ avcodec_close(codec);
66++ }
67++ if (codec->sample_rate == 0) {
68++ ++srerror;
69++ if (srerror == 1) {
70++ fprintf(stderr,"Error, could not determine sample rate\n");
71++ av_log_set_flags(AV_LOG_SKIP_REPEATED);
72++ }
73++ sd->pop();
74++ }
75++ else {
76++ fprintf(stdout,"Sample rate found after %d errors\n", srerror);
77++ break;
78++ }
79++ }
80+ }
81+ s->time_base = codec->time_base;
82+ }
83+
84++ av_log_set_flags(avlogflags);
85++
86+ if (!(fmt->flags & AVFMT_NOFILE)&&(avio_open(&avfc->pb, filename, AVIO_FLAG_WRITE) < 0)) {
87+ av_free(avfc);
88+ avfc=0;
89+--
90+2.43.0
91+
92diff --git a/debian/patches/0002-lavfmuxer-support-codecpar-and-prevent-core-dumps-be.patch b/debian/patches/0002-lavfmuxer-support-codecpar-and-prevent-core-dumps-be.patch
93new file mode 100644
94index 0000000..d54d3e7
95--- /dev/null
96+++ b/debian/patches/0002-lavfmuxer-support-codecpar-and-prevent-core-dumps-be.patch
97@@ -0,0 +1,69 @@
98+From 963212a31eb147c43a42143025a8f6781a75f2d3 Mon Sep 17 00:00:00 2001
99+From: cypline <124210907+cypline@users.noreply.github.com>
100+Date: Wed, 1 Feb 2023 23:34:16 +0100
101+Subject: [PATCH 2/2] lavfmuxer: support codecpar and prevent core dumps
102+ because of uninitialized parameters.
103+
104+Fix for dvbcut to support the new introduced codecpar as replacement of codec. Newer versions of ffmpeg now rely on them. If not provided export produces coredumps.
105+
106+Closes: #17
107+---
108+ src/lavfmuxer.cpp | 22 ++++++++++++++++++++--
109+ 1 file changed, 20 insertions(+), 2 deletions(-)
110+
111+diff --git a/src/lavfmuxer.cpp b/src/lavfmuxer.cpp
112+index 96b92fb..1be4344 100644
113+--- a/src/lavfmuxer.cpp
114++++ b/src/lavfmuxer.cpp
115+@@ -63,6 +63,16 @@ lavfmuxer::lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg,
116+
117+ int avlogflags = av_log_get_flags();
118+
119++ int ret = 0;
120++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 14, 0)
121++ // Use Parameters instead of Codec, necessary to get correct results, prevent crash and correct display of the output of av_dump
122++ ret = avcodec_parameters_from_context(s->codecpar, codec);
123++ if (ret < 0) {
124++ av_log(NULL, AV_LOG_ERROR, "Failed to copy encoder parameters to output stream #%u\n", s->id);
125++ return;
126++ }
127++#endif
128++
129+ for (int i=0;i<mpg.getaudiostreams();++i)
130+ if (audiostreammask & (1u<<i)) {
131+ int astr=audiostream(i);
132+@@ -115,6 +125,14 @@ lavfmuxer::lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg,
133+ }
134+ }
135+ s->time_base = codec->time_base;
136++#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 14, 0)
137++ // Use Parameters instead of Codec, necessary to get correct results, prevent crash and correct display of the output of av_dump
138++ ret = avcodec_parameters_from_context(s->codecpar, codec);
139++ if (ret < 0) {
140++ av_log(NULL, AV_LOG_ERROR, "Failed to copy encoder parameters to output stream #%u\n", s->id);
141++ return;
142++ }
143++#endif
144+ }
145+
146+ av_log_set_flags(avlogflags);
147+@@ -123,14 +141,14 @@ lavfmuxer::lavfmuxer(const char *format, uint32_t audiostreammask, mpgfile &mpg,
148+ av_free(avfc);
149+ avfc=0;
150+ return;
151+- }
152++ }
153+
154+ av_opt_set_int(avfc, "preload", (int)(.5 * AV_TIME_BASE), AV_OPT_SEARCH_CHILDREN);
155+ av_opt_set_int(avfc, "muxrate", 10080000, AV_OPT_SEARCH_CHILDREN);
156+ avfc->max_delay= (int)(.7*AV_TIME_BASE);
157+
158+ av_dump_format(avfc, 0, filename, 1);
159+- int ret = avformat_write_header(avfc, NULL);
160++ ret = avformat_write_header(avfc, NULL);
161+ if (ret < 0) {
162+ fprintf(stderr, "avformat_write_header failed ret[%d]\n", ret);
163+ return;
164+--
165+2.43.0
166+
167diff --git a/debian/patches/1000-ffmpeg-7-api.patch b/debian/patches/1000-ffmpeg-7-api.patch
168new file mode 100644
169index 0000000..ca3ba0e
170--- /dev/null
171+++ b/debian/patches/1000-ffmpeg-7-api.patch
172@@ -0,0 +1,52 @@
173+diff --git a/src/avframe.cpp b/src/avframe.cpp
174+index 19e651d..d92ce77 100644
175+--- a/src/avframe.cpp
176++++ b/src/avframe.cpp
177+@@ -61,8 +61,10 @@ avframe::avframe(AVFrame *src, AVCodecContext *ctx) : f(0),tobefreed(0)
178+
179+ f->pict_type = src->pict_type;
180+ f->quality = src->quality;
181++#if FF_API_FRAME_PICTURE_NUMBER
182+ f->coded_picture_number = src->coded_picture_number;
183+ f->display_picture_number = src->display_picture_number;
184++#endif
185+ f->pts = src->pts;
186+ f->interlaced_frame = src->interlaced_frame;
187+ f->top_field_first = src->top_field_first;
188+diff --git a/src/mpgfile.cpp b/src/mpgfile.cpp
189+index 3412552..60b4d1a 100644
190+--- a/src/mpgfile.cpp
191++++ b/src/mpgfile.cpp
192+@@ -165,8 +165,7 @@ void mpgfile::decodegop(int start, int stop, std::list<avframe*> &framelist)
193+ while (avcodec_receive_frame(S->avcc, avf) == 0)
194+ {
195+ //fprintf(stderr, "* decoded frame %5d ilace:%d typ:%d pts=%f\n", pic, avf->interlaced_frame, avf->pict_type, (double)avf->pts/90000.0);
196+- if (last_cpn!=avf->coded_picture_number) {
197+- last_cpn=avf->coded_picture_number;
198++ if (avf->flags & AV_FRAME_FLAG_KEY) {
199+ if (pic>=start) {
200+ framelist.push_back(new avframe(avf,S->avcc));
201+ }
202+@@ -191,9 +190,8 @@ void mpgfile::decodegop(int start, int stop, std::list<avframe*> &framelist)
203+ avcodec_send_packet(S->avcc, pkt);
204+ while (avcodec_receive_frame(S->avcc, avf) == 0)
205+ {
206+- if (last_cpn!=avf->coded_picture_number)
207++ if (avf->flags & AV_FRAME_FLAG_KEY)
208+ {
209+- last_cpn=avf->coded_picture_number;
210+ if (pic>=start)
211+ framelist.push_back(new avframe(avf,S->avcc));
212+ }
213+@@ -748,9 +746,11 @@ void mpgfile::recodevideo(muxer &mux, int start, int stop, pts_t offset,int save
214+ avframe &f=*framelist.front();
215+
216+ f->pts=idx[idx.indexnr(start+p)].getpts()-startpts;
217++#if FF_API_FRAME_PICTURE_NUMBER
218+ f->coded_picture_number=f->display_picture_number=p;
219+ f->key_frame=(p==0)?1:0;
220+ f->pict_type=(p==0)?AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
221++#endif
222+ avcodec_send_frame(avcc, f);
223+
224+ delete framelist.front();
225diff --git a/debian/patches/series b/debian/patches/series
226index e69de29..6955022 100644
227--- a/debian/patches/series
228+++ b/debian/patches/series
229@@ -0,0 +1,3 @@
230+0001-lavfmuxer-handle-invalid-audio-headers-at-the-beginn.patch
231+0002-lavfmuxer-support-codecpar-and-prevent-core-dumps-be.patch
232+1000-ffmpeg-7-api.patch

Subscribers

People subscribed via source and target branches

to all changes: