Menu

#32 support transcode Video and Audio

open
nobody
None
5
2023-08-16
2011-02-26
hiero
No

Hello,
This patch supports transcoding for both Video and Audio using mencoder/ffmpeg as transcoder.
This uses multiple <res> elements. It means minidlna present multiple media format for one stream.
For example, in case source stream is H.264/AAC, minidlna presents both H.264/AAC and MPEG2/AC3.
If a client (TV) supports only MPEG2/AC3, it select MPEG2/AC3 stream.
All the Video stream can be transcoded to MPEG2/AC3 (DVD) stream.
All the Audio stream can be transcoded to LPCM stream.

mencoder/ffmpeg is required to be installed.

I tested on Ubunts 10.04 and Fedora 12.

I hope this patch is helpful to the users who's TV only supports MPEG2 and LPCM.

This patch is for minidlna_1.0.18_src.tar.gz.
This patch also support Toshiba TV.

heiro

Discussion

<< < 1 .. 6 7 8 (Page 8 of 8)
  • Jruuu

    Jruuu - 2013-06-22

    Yes, my conf file only lists one folder. All of my files are organized in subfolders. I tried running minidlna -d, and I also tried creating a FORCETRANSCODE folder.

    When I choose to play the file in the FORCETRANSCODE folder, minidlna skips the file and goes on to stream the first file in the next subfolder. Here is the output:

    [2013/06/22 13:20:37] upnpevents.c:422: debug: upnpevents_selectfds: 0x12a3f0 2 9
    [2013/06/22 13:21:01] upnpevents.c:457: debug: upnpevents_processfds: 0x12a3f0 2 9 0 0
    [2013/06/22 13:21:01] minidlna.c:1401: debug: HTTP connection from 192.168.7.50:3196
    [2013/06/22 13:21:01] upnpevents.c:422: debug: upnpevents_selectfds: 0x12a3f0 2 9
    [2013/06/22 13:21:01] upnpevents.c:457: debug: upnpevents_processfds: 0x12a3f0 2 9 0 0
    [2013/06/22 13:21:01] upnphttp.c:295: debug: Range Start-End: 0 - -1
    [2013/06/22 13:21:01] upnphttp.c:999: debug: HTTP REQUEST: GET /MediaItems/TranscodeVideo/NTSC/20.mp4 HTTP/1.1
    Host: 192.168.7.53:8200
    User-Agent: VLC/2.0.5 LibVLC/2.0.5
    Range: bytes=0-
    Connection: close
    Icy-MetaData: 1

    [2013/06/22 13:21:01] upnphttp.c:2406: info: TranscodeVideo/NTSC/20.mp4 is selected
    [2013/06/22 13:21:01] upnpevents.c:422: debug: upnpevents_selectfds: 0x12a3f0 2 9
    [2013/06/22 13:21:01] upnphttp.c:2599: info: Serving DetailID: 20 [/home/user/dlna/FORCETRANSCODE/engine-rebuild.mp4]
    [2013/06/22 13:21:01] upnphttp.c:2825: info: Following is the response
    HTTP/1.1 206 OK
    Content-Type: video/mpeg
    X-AvailableSeekRange : 1 npt=0.0-85033.757
    TimeSeekRange.dlna.org : npt=0.0-85033.757/236.986
    transferMode.dlna.org: Streaming
    Accept-Ranges: none
    Connection: close
    Date: Sat, 22 Jun 2013 17:21:01 GMT
    EXT:
    realTimeInfo.dlna.org: DLNA.ORG_TLAG=*
    contentFeatures.dlna.org: DLNA.ORG_PN=MPEG_PS_NTSC;DLNA.ORG_OP=10;DLNA.ORG_CI=1
    Server: Debian/7.1 DLNADOC/1.50 UPnP/1.0 MiniDLNA/1.0.25

    [2013/06/22 13:21:01] upnphttp.c:2838: info: last_file.mime=video/mp4
    [2013/06/22 13:21:01] upnphttp.c:1811: info: start transcode and send data
    [2013/06/22 13:21:01] upnphttp.c:1813: info: fork/exec MENCODER/FFMPEG, PPID=2881, PID=2883
    [2013/06/22 13:21:01] upnphttp.c:1667: debug: streaming from: /home/user/dlna/FORCETRANSCODE/engine-rebuild.mp4
    [2013/06/22 13:21:01] upnphttp.c:1730: info: exec mencoder as follows:
    mencoder -ss 0.0 -endpos 85033.758 -msglevel all=-1 -really-quiet -oac lavc -of mpeg -mpegopts format=mpeg2:muxrate=8000:vbuf_size=1194:abuf_size=64 -vf scale=720:480,harddup -ovc lavc -channels 2 -lavdopts debug=0 -lavcopts autoaspect=1:vcodec=mpeg2video:vbitrate=8000:acodec=ac3:abitrate=128:keyint=18:vqscale=1:vqmin=2 -subdelay 20000 -ofps 30000/1001 -mc 0 -noskip -af lavcresample=48000 -srate 48000 -o - "/home/user/dlna/FORCETRANSCODE/engine-rebuild.mp4"
    [2013/06/22 13:21:02] upnphttp.c:1840: info: reached to EOF in PID:2883
    [2013/06/22 13:21:02] upnphttp.c:1874: info: kill PID(2884) : No child processes
    [2013/06/22 13:21:02] upnphttp.c:1883: info: total bytes : read=0, send=0
    [2013/06/22 13:21:02] upnpevents.c:457: debug: upnpevents_processfds: 0x12a3f0 2 9 0 0
    [2013/06/22 13:21:02] minidlna.c:1401: debug: HTTP connection from 192.168.7.50:3199
    [2013/06/22 13:21:02] upnpevents.c:422: debug: upnpevents_selectfds: 0x12a3f0 2 9
    [2013/06/22 13:21:02] upnpevents.c:457: debug: upnpevents_processfds: 0x12a3f0 2 9 0 0
    [2013/06/22 13:21:02] upnphttp.c:295: debug: Range Start-End: 0 - -1
    [2013/06/22 13:21:02] upnphttp.c:999: debug: HTTP REQUEST: GET /MediaItems/25.avi HTTP/1.1
    Host: 192.168.7.53:8200
    User-Agent: VLC/2.0.5 LibVLC/2.0.5
    Range: bytes=0-
    Connection: close
    Icy-MetaData: 1

     

    Last edit: Jruuu 2013-06-22
  • hiero

    hiero - 2013-06-23

    It seems mencoder does not transcode correctly.
    Would you execulte mencoder as follows.

    mencoder -ss 0.0 -endpos 85033.758 -oac lavc -of mpeg -mpegopts format=mpeg2:muxrate=8000:vbuf_size=1194:abuf_size=64 -vf scale=720:480,harddup -ovc lavc -channels 2 -lavdopts debug=0 -lavcopts autoaspect=1:vcodec=mpeg2video:vbitrate=8000:acodec=ac3:abitrate=128:keyint=18:vqscale=1:vqmin=2 -subdelay 20000 -ofps 30000/1001 -mc 0 -noskip -af lavcresample=48000 -srate 48000 -o test.mpg "/home/user/dlna/FORCETRANSCODE/engine-rebuild.mp4"

    If no error occured and "test.mpg" was output, try to playback it by vlc.

    Hiero

     
  • Nunnsy

    Nunnsy - 2013-06-26

    Hi there,

    first of all thanks for all the work you've put into this.

    I've run miniDlna in debug mode and it stops when it says there's no data in the pipe. I'm guessing that's because CPU enocoding of mpeg2 is too slow. I'm not sure if I need to purchase the mpeg2 license for encoding to work on the GPU. (This is on an ARM based board)

    This is the debug output:
    [2013/06/27 08:07:12] upnphttp.c:2320: info: TranscodeVideo/NTSC/7921.mkv is selected
    [2013/06/27 08:07:12] upnphttp.c:2515: info: Serving DetailID: 7921 [/mnt/usb2/media/TV Shows/Sherlock/FORCETRANSCODE/Pilot.mkv]
    [2013/06/27 08:07:12] upnphttp.c:2761: info: Following is the response
    HTTP/1.1 206 OK
    Content-Type: video/mpeg
    X-AvailableSeekRange : 1 npt=0.0-3314.599
    TimeSeekRange.dlna.org : npt=0.0-3314.599/3314.600
    transferMode.dlna.org: Streaming
    Accept-Ranges: none
    Connection: close
    Date: Wed, 26 Jun 2013 22:07:12 GMT
    EXT:
    realTimeInfo.dlna.org: DLNA.ORG_TLAG=*
    contentFeatures.dlna.org: DLNA.ORG_PN=MPEG_PS_NTSC;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01500000000000000000000000000000
    Server: 3.6.11+ DLNADOC/1.50 UPnP/1.0 MiniDLNA/1.1.0

    [2013/06/27 08:07:12] upnphttp.c:2774: info: last_file.mime=video/x-matroska
    [2013/06/27 08:07:12] upnphttp.c:1723: info: start transcode and send data
    [2013/06/27 08:07:12] upnphttp.c:1725: info: fork/exec MENCODER/FFMPEG, PPID=3084, PID=3088
    [2013/06/27 08:07:12] upnphttp.c:1549: debug: streaming from: /mnt/usb2/media/TV Shows/Sherlock/FORCETRANSCODE/Pilot.mkv
    [2013/06/27 08:07:12] upnphttp.c:1612: info: exec mencoder as follows:
    mencoder -ss 0.0 -endpos 3314.600 -msglevel all=-1 -really-quiet -oac lavc -of mpeg -mpegopts format=mpeg2:muxrate=8000:vbuf_size=1194:abuf_size=64 -vf scale=720:480,harddup -ovc lavc -channels 2 -lavdopts debug=0 -lavcopts autoaspect=1:vcodec=mpeg2video:vbitrate=8000:acodec=ac3:abitrate=128:keyint=18:vqscale=1:vqmin=2 -subdelay 20000 -ofps 30000/1001 -mc 0 -noskip -af lavcresample=48000 -srate 48000 -o - "/mnt/usb2/media/TV Shows/Sherlock/FORCETRANSCODE/Pilot.mkv"
    [2013/06/27 08:07:16] upnphttp.c:1746: debug: poll error : No data in Pipe
    [2013/06/27 08:07:16] upnphttp.c:1792: info: kill PID(3089) : No child processes
    [2013/06/27 08:07:16] upnphttp.c:1797: info: total bytes : read=2048, send=2048
    ^C[2013/06/27 08:07:29] minidlna.c:158: warn: received signal 2, good-bye

    Thanks,
    - Nunnsy

     

    Last edit: Nunnsy 2013-06-26
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2013-06-27

    Hey guys, I've decided to pop in to tell you that my minidlna-transcode project has been moved & renamed (according to upstream) to:

    https://bitbucket.org/stativ/readymedia-transcode

    The transcoding support resides in the transcode branch.

    When it comes to changes from the last time, it is finally possible to have different settings for different clients (more info is in minidlna.conf) and the example transcoding scripts are installed in /usr/share/minidlna/scripts.

     
  • hiero

    hiero - 2013-06-29

    Hello Nunnsy,

    The log says only 2048 was output from mencoder. It is too small data.
    Some error might occur in mencoder. Do you try to encode manually as follows.
    Something can be read in mencoder log message.

    mencoder -ss 0.0 -endpos 3314.600 -oac lavc -of mpeg -mpegopts format=mpeg2:muxrate=8000:vbuf_size=1194:abuf_size=64 -vf scale=720:480,harddup -ovc lavc -channels 2 -lavdopts debug=0 -lavcopts autoaspect=1:vcodec=mpeg2video:vbitrate=8000:acodec=ac3:abitrate=128:keyint=18:vqscale=1:vqmin=2 -subdelay 20000 -ofps 30000/1001 -mc 0 -noskip -af lavcresample=48000 -srate 48000 -o a.mpg "/mnt/usb2/media/TV Shows/Sherlock/FORCETRANSCODE/Pilot.mkv"

    Hiero

     
    • Nunnsy

      Nunnsy - 2013-06-29

      Ahh thank you. It only renders at around 3 to 4 frames per second so that's really useful. I've been trying to minimise the resources required to transcode but obviously it seems it needs more. I'm not sure whether mEncoder is using the GPU though, as I thought it would be running quite smoothly. Hmm, interesting.

      I'm trying to do this on the Raspberry Pi, and I'm not sure if it's possible but I'm giving it a shot. I've found another transcode library, omxtx, which seems to have some good reports running on the Pi. The machine has a powerful enough GPU to transcode all the video real time, it's just I'm having trouble figuring out if I need to pay for an MPEG-2 license for the GPU to transcode, rather than the CPU.

      UPDATE: I purchased the license keys. No luck for harnessing the GPU. The Pi can transcode the video to h264 at around 150 fps at a resolution of the source file being around 700x400, which most of them are. The transcode was using omxtx and was able to quickly convert the video file. Any suggestions would be greatly appreciated.

      Thanks for the time and support,
      - Nunnsy

       

      Last edit: Nunnsy 2013-06-30
  • vonmatrices

    vonmatrices - 2013-07-08

    I've just built miniDLNA with transcoding support from

    https://bitbucket.org/stativ/readymedia-transcode

    Everything is working fine - for video I have the options set so it will transcode avi containers using FFMPEG. The script I am using is the default transcode-video script provided with the above implmentation.

    I am using VLC on Debian (wheezy) to watch the videos, but when transcoding with FFMPEG, it is impossible to fast forward, rewind, or skip ahead by time (pausing works fine). Is there any options I can pass to ffmpeg to provide this functionality? This is the current script:

    !/bin/sh

    SOURCE=$1
    STARTPOSITION=$2
    DURATION=$3

    ffmpeg -ss $STARTPOSITION -t $DURATION -i "$SOURCE" -loglevel quiet -threads auto -async 2 -target pal-dvd pipe:1

     
  • hiero

    hiero - 2013-07-11

    In order to support FF, REW and SEEK for transcoded stream on DLNA, it is required to support "time based seek" functionality by the player. But, it does not seem VLC support it.

     
  • travis

    travis - 2013-11-19

    I've been having some weird trouble with the 1.1.0 patch and Shoutcast transcoding. According to the log it's running ffmpeg -i "ffmpeg -i"

    [2013/11/19 17:48:48] upnphttp.c:2838: info: last_file.mime=audio/mpeg
    [2013/11/19 17:48:48] upnphttp.c:1811: info: start transcode and send data
    [2013/11/19 17:48:48] upnphttp.c:1813: info: fork/exec MENCODER/FFMPEG, PPID=20759, PID=21163
    [2013/11/19 17:48:48] upnphttp.c:1667: debug: streaming from: http://ca.ah.fm:443
    [2013/11/19 17:48:48] upnphttp.c:1730: info: exec ffmpeg as follows:
    ffmpeg -i "ffmpeg -i " -t 86400 -v 0 -loglevel quiet -f mp3 -vn -acodec libmp3lame -ab 256k pipe:1
    [2013/11/19 17:48:49] upnphttp.c:1840: info: reached to EOF in PID:21163
    [2013/11/19 17:48:49] upnphttp.c:1874: info: kill PID(21164) : No child processes
    [2013/11/19 17:48:49] upnphttp.c:1883: info: total bytes : read=0, send=0

    Not sure what's causing this to happen. Any ideas?

    minidlna.conf: https://gist.github.com/exiva/7549595
    ffmpeg version info: https://gist.github.com/exiva/7549595#file-gistfile2-txt
    test playlist file: https://gist.github.com/exiva/7549595#file-gistfile3-txt

     
  • hiero

    hiero - 2013-12-08

    I found a bug which appears on gcc 4.8.
    This makes "ffmpeg -i " as source to access streaming as shoutcast.
    This bug is fixed in the transcode patch for minidlna-1.1.1.

     
  • hiero

    hiero - 2013-12-08

    support transcode Video and Audio patch against 1.1.1 support Linux and Cygwin

    I made a mistake to create the patch.
    The patch file was replaced with "minidlna_transcode-1.1.1.tar.gz".

     

    Last edit: hiero 2013-12-14
  • hiero

    hiero - 2014-01-11

    support transcode Video and Audio patch against 1.1.1 support Linux and Cygwin

    also worked on FreeBSD and MAC OSx

    add to support "Don't require a configured network interface to start up, and add network interface monitoring support" for Cygwin
    and fixed some minor bugs

     

    Last edit: hiero 2014-01-12
  • Krzychu

    Krzychu - 2014-02-04

    Hi, sorry for my English. I have a problem with my NAS Zyxel NSA 310. I install ffpstick 0.7 and then minidlna 1.1.0. It's working ok but it doesn't transcode to mpeg2. I have TV Sony Bravia W655a which have problem which play this videos. Can I get installed this patch on my NAS via putty? If yes what can I do it? Please for help.

     
  • Jaume Sabater

    Jaume Sabater - 2019-02-12

    Does anybody have a version of this fantastic patch (and all the updates it has received so far in this very long thread) for the current version 1.2.1 of MiniDLNA?

    Also, does anybody know why it was never included in the main branch? Or if it was rejected? I never got to find a response by the main developer about it.

    Thanks.

     
    • Logan007

      Logan007 - 2019-02-16

      This -> https://bitbucket.org/stativ/readymedia-transcode <- seems to be based on 1.1.4. Chances are that a diff between 1.1.4 and the bitbucket-transcode topped with some manual adjustements may help to get it applied on 1.2.1.

       
  • hiero

    hiero - 2019-03-03

    It's been ages.

    This is support transcode Video and Audio patch against 1.2.1 support Linux and Cygwin.

    I did quick test on Ubuntu 18.04 and it works.

     
    👍
    1
    • Jaume Sabater

      Jaume Sabater - 2019-03-03

      Thanks for the patch, Hiero. Would you create a pull request with it? Does anyone know if the maintainer has any plans to accept such pull request so that this becomes a feature of MiniDLNA?

       
      • Shrimpkin

        Shrimpkin - 2019-05-30

        Does anyone know if the maintainer has any plans to accept such pull request so that this becomes a feature of MiniDLNA?

        No idea. ReadyMedia is developed for ReadyNAS devices. There already seems to be a competing media server that supports transcoding available for ReadyNAS - Plex. Check out the sandbox:
        https://www.netgear.com/landing/readynas-sandbox.aspx

         
    • Piotr

      Piotr - 2020-03-17

      Hi,

      at first I would like to thank you for the patch, that gave me some hope to resolve my problems.
      I am new in all the linux stuff, still learing... ;) I would like to ask you for some help here.

      I have Ubuntu with minidlna setup, its mostly working fine everywere PC, Android and partially on TV, and with TV I have problem...

      On TV I can browse my DLNA store, open & watch MKV videos, but it won't open AVI files at all (Samsung 7/J Series is not opening DivX/Xvid even from USB)

      So my idea was to add on-the-fly transcoding of the avi files to mkv using ffmpeg, I checked with some static files using below:

      ffmpeg -fflags +genpts -i input.avi -c:v copy -c:a copy output.mkv
      

      the file was quickly converted to MKV without any lack of quality, and it was successfully opened on my TV.

      Could you please help me implement your patch with above conversion for AVI files? :)

       

      Last edit: Piotr 2020-03-17
  • Tony

    Tony - 2021-06-01

    hello and thank you for this patch! Is it possible to stop, resume and seek with the seekbar while playing the video on the fly? My 2 samsung tv restart the movie immediately.
    Thanks

    my script;

    !/bin/sh

    SOURCE=$1
    STARTPOSITION=$2
    DURATION=$3

    ffmpeg -ss $STARTPOSITION -t $DURATION -i "$SOURCE" -c:v copy -c:s copy -c:a mp3 -b:a 128k -f matroska pipe:1

     

    Last edit: Tony 2021-06-01
  • hiero

    hiero - 2021-06-14

    hello,

    stop/resume/seek functionality is done by player(TV).
    DLNA server start reading file and sending it from the start point which is specified by the player(TV).

     
  • hiero

    hiero - 2021-06-14

    This is transcode Video and Audio patch against 1.3.0 support on Linux and Cygwin.
    I did quick test on Ubuntu 20.04 and Cygwin 3.2.0. It works.

    DVD ISO file support is added on this patch.
    Because extraction of DVD ISO is done using MPlayer,
    MPlayer is required to support DVD ISO file.
    On Ubuntu,
    $ sudo apt install mplayer

     
  • Tony

    Tony - 2021-06-14

    Hiero thank you for this patch. Now i switched to the dlna server serviio it supports the start stop and seek commands while tratranscod and the metadata, thumbnails are amazing.

     

    Last edit: Tony 2021-06-14
  • paul

    paul - 2023-08-16

    2 years later

    Has anyone compiled this patch against current ffmpeg, on current Linux systems?

    XY question endpoint - I'd like to play BBC streams on my Revo Axis XS now that the BBC has stopped supporting SHOUTcast - the Axis supports DLNA and it looks like this patch can "transcode" HLS streams to DNLA.

    On Fedora 38, with ffmpeg 6.0.15 I'm struggling to get out of the starting blocks.

    The first problem is that, after applying the patch (which gave no errors) I can run configure but trying to do a build re-runs automake which ends with the error

    checking for id3_file_open in -lid3tag -lz... yes
    configure: error: Could not find libid3tag

    needless to say that I do have the right version of libid3tag installed and "vanilla" configure has no problems.

    To be fair this is not actually caused by this patch - getting anywhere near autogen/autoconf/automake gives the same error but the patch modifies configure.ac so the make system tries to rebuild the auto scripts. I've never been a fan of the auto tools to be honest but including both Cygwin support and transcode support in the same patch is not very clean - it looks like configure.ac is only modified because of the Cygwin stuff.

    If I restore configure.ac from 1.3.0 things get a little further but hit

    metadata.c: In function getParamOfISO_DVDBD:
    metadata.c:214:2: error: invalid preprocessing directive #elae; did you mean #else?
      214 | #elae // __CYGWIN__
          |  ^~~~
          |  else
    

    I mean, this is just a basic syntax error in the patch which should not have got through.

    Fixing this still trips up with

    metadata.c:1438:32: error: AVFormatContext has no member named filename
     1438 |                 if (strncmp(ctx->filename, "DVDISO", sizeof("DVDISO")-1))
          | 
    

    No problem, I'm sure that there's a solution to this missing struct member, clearly AVFormatContext has changed a bit since 2021 - but I'm currently asking myself what I'm going to trip up on after that?

    Lukas' code on https://bitbucket.org/stativ/readymedia-transcode is cleaner, compiles, looks to be tracking the main development better and doesn't include the Cygwin support but critically for me doesn't include the SHOUTcast/HLS code either so I would like to get this patch up and running so I can have a good look at how that bit is implemented. I don't especially need transcode (though turning DTS audio into something my newer Samsung TV understands might be worthwhile) but I would like to avoid turning my two Revo radios into e-waste, and this code looks like it might just be capable of doing that - but I don't want to waste time doing work that is already done just getting it up and running.

     
<< < 1 .. 6 7 8 (Page 8 of 8)

Log in to post a comment.