diff mbox

[FFmpeg-devel] (for discussion): ffmpeg_filter: initialize cuvid for filter_complex

Message ID 58A0B4EE.30204@email.cz
State Superseded
Headers show

Commit Message

Miroslav Slugeň Feb. 12, 2017, 7:18 p.m. UTC
This patch is for discussion only, not ready to commit yet.

We were facing issue when using -hwaccel cuvid, then we were unable to 
use -filter_complex filters for video streams, this hack fixed it, but i 
am sure that it is not ready to commit, because it is dirty/ugly fix.

Comments

Timo Rothenpieler Feb. 12, 2017, 7:25 p.m. UTC | #1
On 2/12/2017 8:18 PM, Miroslav Slugeň wrote:
> This patch is for discussion only, not ready to commit yet.
> 
> We were facing issue when using -hwaccel cuvid, then we were unable to
> use -filter_complex filters for video streams, this hack fixed it, but i
> am sure that it is not ready to commit, because it is dirty/ugly fix.

This collides with the merges and is probably obsolete once they happen.
Miroslav Slugeň Feb. 12, 2017, 7:53 p.m. UTC | #2
Dne 12.2.2017 v 20:25 Timo Rothenpieler napsal(a):
> On 2/12/2017 8:18 PM, Miroslav Slugeň wrote:
>> This patch is for discussion only, not ready to commit yet.
>>
>> We were facing issue when using -hwaccel cuvid, then we were unable to
>> use -filter_complex filters for video streams, this hack fixed it, but i
>> am sure that it is not ready to commit, because it is dirty/ugly fix.
> This collides with the merges and is probably obsolete once they happen.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Thx, i am glad that someone is working on fixing this issue. We need to 
have it working year ago, so i created this patch.

M.
Timo Rothenpieler Feb. 12, 2017, 7:59 p.m. UTC | #3
On 2/12/2017 8:53 PM, Miroslav Slugeň wrote:
> Dne 12.2.2017 v 20:25 Timo Rothenpieler napsal(a):
>> On 2/12/2017 8:18 PM, Miroslav Slugeň wrote:
>>> This patch is for discussion only, not ready to commit yet.
>>>
>>> We were facing issue when using -hwaccel cuvid, then we were unable to
>>> use -filter_complex filters for video streams, this hack fixed it, but i
>>> am sure that it is not ready to commit, because it is dirty/ugly fix.
>> This collides with the merges and is probably obsolete once they happen.
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> Thx, i am glad that someone is working on fixing this issue. We need to
> have it working year ago, so i created this patch.

I wasn't aware there is any kind of issue.
You can try https://github.com/BtbN/FFmpeg/tree/filter-merge if you want
to test the current state of the merges.

There is some very weird issue with cuvid->nvenc hwaccel transcoding,
which I wasn't able to figure out yet, as nvenc just reports being out
of memory when encoding a frame.
Miroslav Slugeň Feb. 12, 2017, 8:42 p.m. UTC | #4
Dne 12.2.2017 v 20:59 Timo Rothenpieler napsal(a):
> On 2/12/2017 8:53 PM, Miroslav Slugeň wrote:
>> Dne 12.2.2017 v 20:25 Timo Rothenpieler napsal(a):
>>> On 2/12/2017 8:18 PM, Miroslav Slugeň wrote:
>>>> This patch is for discussion only, not ready to commit yet.
>>>>
>>>> We were facing issue when using -hwaccel cuvid, then we were unable to
>>>> use -filter_complex filters for video streams, this hack fixed it, but i
>>>> am sure that it is not ready to commit, because it is dirty/ugly fix.
>>> This collides with the merges and is probably obsolete once they happen.
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel@ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> Thx, i am glad that someone is working on fixing this issue. We need to
>> have it working year ago, so i created this patch.
> I wasn't aware there is any kind of issue.
> You can try https://github.com/BtbN/FFmpeg/tree/filter-merge if you want
> to test the current state of the merges.
>
> There is some very weird issue with cuvid->nvenc hwaccel transcoding,
> which I wasn't able to figure out yet, as nvenc just reports being out
> of memory when encoding a frame.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

I have seen those patches in mailing list. Have you tried it on QUADRO 
cards which are not limited to only 2 streams per system? It could be 
related to protection in NVIDIA drivers for NON-PRO cards.

M.
Timo Rothenpieler Feb. 12, 2017, 9:06 p.m. UTC | #5
> I have seen those patches in mailing list. Have you tried it on QUADRO
> cards which are not limited to only 2 streams per system? It could be
> related to protection in NVIDIA drivers for NON-PRO cards.

It it definitely not related to that limitation, that fails way ealier
and with a somewhat proper error code.
We are currently suspecting that it's some weird initialization order
issue, or some value is not passed correctly, like frame dimensions, but
from all my poking, everything looks perfectly in order.
Miroslav Slugeň Feb. 12, 2017, 9:11 p.m. UTC | #6
Dne 12.2.2017 v 22:06 Timo Rothenpieler napsal(a):
>> I have seen those patches in mailing list. Have you tried it on QUADRO
>> cards which are not limited to only 2 streams per system? It could be
>> related to protection in NVIDIA drivers for NON-PRO cards.
> It it definitely not related to that limitation, that fails way ealier
> and with a somewhat proper error code.
> We are currently suspecting that it's some weird initialization order
> issue, or some value is not passed correctly, like frame dimensions, but
> from all my poking, everything looks perfectly in order.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
I just tried your build with this cmd line:

ffmpeg -hwaccel cuvid -c:v h264_cuvid -i simpson_1920p_h264.mp4 -y -c:v 
hevc_nvenc -an -b:v 512K -qmin 5 -qmax 50 -preset slow 
out_1920p_1920p_hq.mp4

And everything works well, do you have not working example?

I have GTX 1060 3GB with current stable drivers.

M.
Timo Rothenpieler Feb. 12, 2017, 10:27 p.m. UTC | #7
> I just tried your build with this cmd line:
> 
> ffmpeg -hwaccel cuvid -c:v h264_cuvid -i simpson_1920p_h264.mp4 -y -c:v
> hevc_nvenc -an -b:v 512K -qmin 5 -qmax 50 -preset slow
> out_1920p_1920p_hq.mp4
> 
> And everything works well, do you have not working example?
> 
> I have GTX 1060 3GB with current stable drivers.
> 
> M.

That's what it looks like for me:
https://bpaste.net/show/890855410dac

Happens on two independend machines, on both Windows using MSVC and
Linux with gcc.
Both machines are definitely nowehre near out of memory, on either
system or device memory.
Miroslav Slugeň Feb. 13, 2017, 8:48 a.m. UTC | #8
Dne 12.2.2017 v 23:27 Timo Rothenpieler napsal(a):
>> I just tried your build with this cmd line:
>>
>> ffmpeg -hwaccel cuvid -c:v h264_cuvid -i simpson_1920p_h264.mp4 -y -c:v
>> hevc_nvenc -an -b:v 512K -qmin 5 -qmax 50 -preset slow
>> out_1920p_1920p_hq.mp4
>>
>> And everything works well, do you have not working example?
>>
>> I have GTX 1060 3GB with current stable drivers.
>>
>> M.
> That's what it looks like for me:
> https://bpaste.net/show/890855410dac
>
> Happens on two independend machines, on both Windows using MSVC and
> Linux with gcc.
> Both machines are definitely nowehre near out of memory, on either
> system or device memory.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Can't reproduce it on two my systems with same sample and same command line.

First 1000 lines:
375.26: https://bpaste.net/show/bed97b3e0287
378.09: https://bpaste.net/show/912c042036cd

Configuration1:
Debian Jessie Linux desktop 4.8.0-0.bpo.2-amd64 #1 SMP Debian 
4.8.15-2~bpo8+2 (2017-01-17) x86_64 GNU/Linux
GeForce GTX 1060, drivers 375.26

Configuration2:
Debian Jessie Linux pascal 4.7.0-0.bpo.1-amd64 #1 SMP Debian 
4.7.8-1~bpo8+1 (2016-10-19) x86_64 GNU/Linux
GeForce GTX 1080, drivers 378.09

M.
Timo Rothenpieler Feb. 13, 2017, 10:18 a.m. UTC | #9
>> That's what it looks like for me:
>> https://bpaste.net/show/890855410dac
>>
>> Happens on two independend machines, on both Windows using MSVC and
>> Linux with gcc.
>> Both machines are definitely nowehre near out of memory, on either
>> system or device memory.
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> Can't reproduce it on two my systems with same sample and same command
> line.
> 
> First 1000 lines:
> 375.26: https://bpaste.net/show/bed97b3e0287
> 378.09: https://bpaste.net/show/912c042036cd
> 
> Configuration1:
> Debian Jessie Linux desktop 4.8.0-0.bpo.2-amd64 #1 SMP Debian
> 4.8.15-2~bpo8+2 (2017-01-17) x86_64 GNU/Linux
> GeForce GTX 1060, drivers 375.26
> 
> Configuration2:
> Debian Jessie Linux pascal 4.7.0-0.bpo.1-amd64 #1 SMP Debian
> 4.7.8-1~bpo8+1 (2016-10-19) x86_64 GNU/Linux
> GeForce GTX 1080, drivers 378.09

That's not built from the right branch.
Most notably: On the filter-merge branch, the cuvid pfnSequenceCallback
happens before the "Nvenc initialized successfully", on your log Nvenc
still gets initialized first.
diff mbox

Patch

From 569a2c69e799d5fed364fbe55de2a49e2bbeab06 Mon Sep 17 00:00:00 2001
From: Miroslav Slugen <thunder.m@email.cz>
Date: Sun, 12 Feb 2017 20:15:13 +0100
Subject: [PATCH 1/1] ffmpeg_filter: initialize cuvid for filter_complex

---
 ffmpeg_filter.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/ffmpeg_filter.c b/ffmpeg_filter.c
index f13f523..1eb75b6 100644
--- a/ffmpeg_filter.c
+++ b/ffmpeg_filter.c
@@ -1026,6 +1026,26 @@  int configure_filtergraph(FilterGraph *fg)
         fg->graph->nb_threads = filter_complex_nbthreads;
     }
 
+#if CONFIG_CUVID
+    if (!simple) {
+        for (i = 0; i < fg->nb_outputs; i++) {
+            OutputFilter *ofilter = fg->outputs[i];
+            int source_index;
+            if (!ofilter->ost || ofilter->ost->source_index >= 0)
+                continue;
+            if (fg->nb_inputs != 1)
+                continue;
+            for (source_index = nb_input_streams-1; source_index >= 0; source_index--)
+                if (fg->inputs[0]->ist == input_streams[source_index])
+                    break;
+            ofilter->ost->source_index = source_index;
+
+            if (cuvid_transcode_init(ofilter->ost))
+                exit_program(1);
+        }
+    }
+#endif
+
     if ((ret = avfilter_graph_parse2(fg->graph, graph_desc, &inputs, &outputs)) < 0)
         return ret;
 
-- 
2.1.4