Jump to content
Josezkaos

FFMPEG with QSV Decoding and Encoding Live Streams

Recommended Posts

Josezkaos

As I commented this issue in another thread dedicated to NVIDIA transcoding, I'll create a new one for this as I think is interesting.

 

I've recorded a short clip from a DVB-T stream with DVBViewer:

 

http://www.mediafire.com/?aoe7406d87h3k

 

If QSV Decoder would work with live streams, this would be enought:

Quote

 

ffmpeg -hwaccel qsv -vcodec h264_qsv -i dvbt_Stream.ts -vcodec h264_qsv -vf deinterlace_qsv -y test.ts


 

 

 

But that fails.

 

Somehow, if the stream is copied and piped into another ffmpeg ... it works:

Quote

 

ffmpeg -i dvbt_Stream.ts -vcodec copy -acodec copy -f mpegts -| ffmpeg -hwaccel qsv -vcodec h264_qsv -f mpegts -i pipe: -vcodec h264_qsv -vf deinterlace_qsv -y test.ts


 

 

 

Stream is copied, decoded with H264_QSV and then encoded with H264_QSV, all under HW Acceleration.

 

But this workaround is not valid for Recording Services:

Quote

 

Cmd=-i "{infile}" -vcodec copy -acodec copy -f mpegts -| ffmpeg -hwaccel qsv -vcodec h264_qsv -f mpegts -i pipe: -vcodec h264_qsv -vf deinterlace_qsv -y "{outfile}"


 

 

 

Seems the pipe lunches another instance which can't reach RS output pipe ({outfile}).

 

Why use QSV on Decoder and Encoder for transcoding live streams?

 

1. Decoded frames are in Video Memory, not in System Memory this way, so Encoding runs way more faster saving time moving those decoded frames between memories.

2. Deinterlacing with QSV avoids using CPU, once again faster and saving CPU for other processes running.

 

Does anyone know how to get RS to transcode live streams using QSV for Decoding and Encoding?

 

Thanks in advance (specially to Griga and majstang who replied in the other thread).

Share this post


Link to post
majstang
Posted (edited)

Hi Josezkaos,

 

although the FFMPEG stuff is kind of a blank area for me (not much testing done in my case) my question is how are you trying to launch it through RS? Via a task? If so the right placeholders has to be used.

 

Christian tells us:

Quote

{DVBVIEWER_PATH} can be used as placeholder for the DVBViewer / Recording Service installation path (including the trailing backslash) in the task filename, working directory and in parameters, e. g. {DVBVIEWER_PATH}ffmpeg.exe. Please note that placeholders must be uppercase!

 also the right placeholder for the infile is {SOURCE_FILE}. Outfile I dont know. 

 

Also search for Transcoded Streaming in this thread http://www.DVBViewer.tv/forum/topic/19629-recording-service-beta/?do=findComment&comment=431016

Edited by majstang

Share this post


Link to post
Josezkaos

The ffmpegpref.ini is used on live streams:

 

Quote

[PIPE TEST]

Cmd=-i "{infile}" -vcodec copy -acodec copy -f mpegts -| ffmpeg -hwaccel qsv -vcodec h264_qsv -f mpegts -i pipe: -vcodec h264_qsv -vf deinterlace_qsv -y "{outfile}"

maxWidth=1920
maxHeight=1080
MimeType=video/mpeg
Ext=.ts
Delay=2000

 

I'm using VLC as player, and in FFMPEGPREF.INI the {infile} and {outfile} are used in all prefs available by default in RS.

 

The other examples are adapted for the recording uploaded to mediafire, but the result is the same as using a live stream from RS ("http://localhost:1212/upnp/channelstream/3713217958821953687%7ClaSexta%20HD%20%28spa%29.ts").

 

 

Share this post


Link to post
majstang

Ok, check out this german thread

Share this post


Link to post
Josezkaos

I figured out what's the real reason why this command is not working in RS:

 

Quote

 

ffmpeg -i dvbt_Stream.ts -vcodec copy -acodec copy -f mpegts -| ffmpeg -hwaccel qsv -vcodec h264_qsv -f mpegts -i pipe: -vcodec h264_qsv -vf deinterlace_qsv -y test.ts


 


It's not (only) about the pipe, it's the HWACCEL option.

 

FFMPEG supports hardware acceleration, but when it comes to QSV it needs to render a DirectX device first.

 

As RS is running in a Windows Service context, DirectX is not available (DirectX 11 does under some limitations, but FFMPEG does not use it to access QSV devices) and therefore FFMPEG cannot create an instance of DirectX QSV Devices to decode video when called from RS.

 

In short, what we need is to fix the live stream so H264_QSV decoder can handle it (that's solved using the "-vcodec copy -acodec copy" or "-c copy" and a pipe to another FFMPEG instance), and to find a context where FFMPEG can render a DirectX QSV Device and use it instead of Windows Service Context.

 

I'm developing a simple Java app which performes like man in the middle, launching FFMPEG from Windows User Context so FFMPEG can access to DirectX QSV Devices ... it seems to work, but it still needs some fixes and tunning.

 

By the momment, I'm able to decode, deinterlace and encode using only QSV hardware acceleration as well as inject it into RS.

 

I'll keep you all up with news.

 

 

Share this post


Link to post
majstang

Yeah, the MS introduced Service context security limitations is a huge PITA! Im using a named pipe solution running scripts unrestricted for 8 years now. Have been suggested that solution being built into the RS/DMS equally as long, but no luck so far. I can understand it cuz its not the cleanest of solutions;) Although MS has API instructions/documentation themselves how to do something like it. Good luck to you and your nifty endeavours (they are very interesting and fun to follow):bye:

Share this post


Link to post
Josezkaos

Here it is a little comparaison...

 

This one is using RS default transcoding WEBM HD 3600Kbps (aka: 720p, 25fps):

 

9833TpZ

 

CPU using 70-80%, GPU at 0%, 

 

This one is using my http server (which calls FFMPEG using QSV) at 3M (aka: 1080p, 50fps):

g82VCeV

 

CPU doesn't change activity (stays at 33%), GPU jumps to 40-60%.

 

Video stream plays flawlessly (w00t)

Share this post


Link to post
janee

Hi Josezkaos,

nice project!!! This is very interessting.

I never got it working. Maybe you can share  the commandline for ffmpeg. I use a Kaby Lake CPU with Iris Plus Graphics 640.

Thanks!

 

e.g If I try this:

ffmpeg -analyzeduration 1500k  -i "http://127.0.0.1:7522/upnp/channelstream/transcode/2359890582721931325%7CDas%20Erste%20HD.ts" -vcodec copy -acodec copy -f mpegts -| ffmpeg -hwaccel qsv -vcodec h264_qsv -f mpegts -i pipe: -vcodec h264_qsv -vf deinterlace_qsv -y "c:\temp\output.ts"

 

I got errors.

Spoiler

[NULL @ 0000023965c9cc40] missing picture in access unit with size 3
Past duration 0.987221 too large
[NULL @ 0000023965c9cc40] missing picture in access unit with size 3
    Last message repeated 1 times
Past duration 0.987221 too large
[NULL @ 0000023965c9cc40] missing picture in access unit with size 3
Past duration 0.987221 too large
    Last message repeated 1 times
[NULL @ 0000023965c9cc40] missing picture in access unit with size 3
Past duration 0.987221 too large
Error while filtering: Cannot allocate memory
Failed to inject frame into filter network: Cannot allocate memory
Error while processing the decoded data for stream #0:0
Conversion failed!
av_interleaved_write_frame(): Broken pipe
Error writing trailer of pipe:: Broken pipe
frame=  654 fps= 56 q=-1.0 Lsize=   12471kB time=00:00:14.41 bitrate=7089.4kbits/s speed=1.22x
video:12102kB audio:416kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

 

 

Share this post


Link to post
Josezkaos

Thanks!

 

Anyway, it is a very simple project .... actually, it just generates the FFMPEG call out of Windows Service Context (whis is the one uses RS) and returns the encoded video to RS.

 

That means, it adds some seconds of delay... But in the other hand, you get efficent HW encoding/decoding/deinterlacing/scaling.

 

My Intel HD Graphics 6000 seems not to support deint+scaling (runs of memmory ... but both works if used alone).

 

To use this project you need:

1 - a new FFMPEGPREF for RS

Quote

[FFMPEGSERVER 3M H264 DEINT]
Cmd=-re -f mpegts -i http://localhost:5566/RSFfmpeg?inputstream={infile}&ffmpegpref=3MDeintH264 -c copy -f mpegts -y "{outfile}"
maxWidth=1920
maxHeight=1080
MimeType=video/mpeg
Ext=.ts
Delay=1
 

2 - Configure the HTTPServer (don't panic, just to indicate a port number, FFMPEG path, and a new properties file path)

 

I've attached the jar, a properties file and even a .Bat to make it launch on windows startup (up to you).

 

You have to keep in mind just one thing: To decode using FFMPEG and QSV, it's needed to use the QSV decoder ... so the FFMPEG call, has a QSV codec.... If you want to use it with MPEG2, H264 and HEVC channels you'll need to create 3 different prefs into the NEW propperties file and use h264_qsv, hevc_qsv, mpeg2_qsv and the RS FFMPEGPref file.

 

Hope it helps!!!

RSFFMPEGServer.zip

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Similar Content

    • mague
      By mague
      Hi,
       
      ich bin ja vor einer Weile umgestiegen auf ein board mit HEVC decoding. Ich habe, neben HTPC, einen kleinen Server mit Atom CPU der sowohl als Recording Service wie auch als virtueller Linuxserver und auch als Fileserver dient. Den wollte ich abschalten weil ich in Zukunft weder das Linux noch den Fileserver in der Form brauche und ich so mindestens 350kWh im Jahr sparen kann.
       
      Da mein HTPC Intelboard nur noch einen PCIe Slot hat aber meine PCI Karte noch tadellos funktioniert habe ich diesen Adapter versucht. Was soll ich sagen, funktioniert perfekt. Passt vielleicht nicht in jedes Gehäuse, aber rein elektrisch war es mit Win10 kein Problem. Treiber waren nicht nötig. RS habe ich jetzt keinen mehr, ich nehme kaum auf und die Technotrend S2 3200 und der DVBSky 330 T2 USB Stick versorgen den DVBViewer jetzt direkt mit Daten 
    • noraccire
      By noraccire
      Dear Team
      any idea on how to troubleshoot it ? ( fyi it was the same issue with the previous version of the media server )
       
      I am struggling with the media server live stream ..
      getting access to the web interface via my laptop or via my iPhone is working fine, browsing the available channels is ok ( I am using TS streams from IPTV m3u list) , play in web browser is ok , however only one channel is playing( always the same , the first from my favorite playlist) .. trying to switch to other channels , the logo and channel name are displayed but the video content do not switch and remains to  the first from my favorite playlist.  The same issue occurs when trying from the Local network or  internet connection to the media server.
       
      support.zip
    • Jackie78
      By Jackie78

        Hallo, ich besitze einen DVB-S2 Adapter DVBSky S960, und bekomme heute ein Synology NAS vom Typ DS216J. Vorab interessiert mich, ob diese Kombination funktioniert, also ob das NAS in der Lage ist, den DVBSky zu erkennen und einzubinden. Gibt es hierzu Erfahrungswerte, oder praktische Tipps? Danke  
    • Perlbo
      By Perlbo
      Hi,
       
      neuerdings wird mein Rechner so träge und da habe ich im Taskmananger (Win10 64bit) mal geguckt was da so los ist. Was mir aufgefallen ist, dass mehrer Instanzen von ffmpeg.exe gestartet werden. Wir reden hier von 10+.
       
      Das ist doch nicht normal oder ? Zu dem Zeitpunkt greif auch kein andere Rechner auf den Mediaserver zu. Er wird auch nur genutzt um das TV plugin für Kodi zu nutzen und Aufnahmen zu tätigen. 
       
      Ich werde das nach einem Neustart nochmal beobachten. Aber vielleicht kann mir ja schon jemand einen Tip geben, zumindest habe ich ffmpeg nochmal über den DVBViewer link heruntergeladen und die exe im DVBViewer Ordner aktualisiert (richtig?). 
       
    • allanlee
      By allanlee
      Updated to DVBViewer Pro 6.0.4, DMS 2.0.4 and TrandEdit 4.2.1
       
      If there's an ongoing recording in DMS , it will "grab" the tuner from DMS without any warning or notification.
       
      At the meantime however, DMS "Status" tab still displays as normal (except for data rate decreasing and file size remaining the same). Seems that it does not even know the tuner what "robbed" away by TransEdit.
       
      See this behavior in 2 of my PCs. Is it a new - "feature" - of the new version? In previous versions TransEdit will tell me something like "Initialize device failed" or "No hardware available".
×