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 .. 4 5 6 7 8 > >> (Page 6 of 8)
  • normaal

    normaal - 2012-04-07

    Changing lines 1127 and 1128 (after patching) made a trick for me :)
    mkv remuxing formking now for panasonic Viera too.

    char *tmp_dlna_buf = "DLNA.ORG_OP=00;DLNA.ORG_CI=1;"
    "DLNA.ORG_FLAGS=01200000000000000000000000000000";

     
  • normaal

    normaal - 2012-04-07

    aa, yes.. was talking about upnpsoap.c file.

     
  • hiero

    hiero - 2012-04-07

    Hello normaal、

    I think panasonic Viera trusts "DLNA.ORG_PN=MPEG_PS_PAL".
    It is different from transcoded stream in this case.

    hiero

     
  • normaal

    normaal - 2012-04-08

    Hi Hiero

    I recompiled and you You were correct: removing DLNA.ORG_PN=MPEG_PS_PAL was enought for Pana.
    No need change DLNA.ORG_FLAGS=....

    working like a charm ....

    br'
    Normaal

     
  • Anonymous

    Anonymous - 2012-05-05

    I'm having a problem with this - But I'm completely at a loss as of what to do now.

    I compiled this and it seemed to work fine, and the miniDLNA itsself works.
    I then found this thread :https://sourceforge.net/projects/minidlna/forums/forum/879956/topic/4644111
    And used the transcoder.sh from it. I tried it on my TV, and it worked bar a small sound sync issue. So I tried changing a few options in the script, but now my TV just doesn't load the media. It can see it, but if I start playing it it just pauses and doesn't play.

    So I copied the transcode script that I initially downloaded back over, and STILL it won't work. I can't figure out what the problem is - is there any way that I can check to see if its the transcoder or the TV's fault?

    Thanks

     

    Last edit: Anonymous 2014-03-13
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2012-09-06

    I decided to try my luck with transcoding. It can be found at:
    https://bitbucket.org/stativ/minidlna-transcode

    So far there is only video transcode support, but I plan to implement audio and image transcoding, too. It also contains various small changes that should fix playback of some files that doesn't need to be transcoded.

    It works a bit differently from the Hiero's patch. The DLNA PN and MIME type are not hardcoded when transcoding but instead they are determined from the transcoder output. Also, it doesn't use any kind of auto detection of what needs to be transcoded (I think Hiero's patch tries to do that, it broke some playback of some files for me). Instead, the user specifies which codecs/containers needs to be transcoded in the config file.

    It contains lot of Hiero's code. He did a great job on the transcode support and I'm really thankful for that. During the early stages of development I found out that Hiero did a lot of things the same way as I wanted to, so I used his code instead of wasting time on things that were already implemented.

     
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2012-09-19

    I forgot to note that I've pushed support for audio and image transcoding to the minidlna-transcode. The image transcoding uses ImageMagick so it supports camera RAW images thanks to the ImageMagick delegates.

     
  • goro69

    goro69 - 2012-09-29

    Hi everybody,
    are we can, when transcode video, add subtitles in picture if they are whit same name like a video file. If we can - how? Thanks.
    Sorry about my english.

     
  • Leon Botha

    Leon Botha - 2012-09-29

    Hi gorata

    All my subtitles - .srt files only, are located in the same folder as the movie with exactly the same name as the movie. They work 100%
    As i have a Samsung, embedded subtitles do not work, i have to extract them and convert to .srt

    Z69

     
  • goro69

    goro69 - 2012-09-29

    My old Toshiba do not support subtitles and mpeg4 files, only MPEG2/AC3, and I transcode video so I want to add there subtitles. Transcoders support that option

     
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2012-09-29

    gorata: I'm not sure if I answer your question, but I'll try to.

    The subtitles handling depends on the client.

    MiniDLNA support automatic loading of srt subtitles. For this to work they must have the same name as the video file, but with .srt extension. Some clients (eg. Samsung TV's) also supports subtitles embedded in mkv files.

    It may be possible that the client doesn't support external subtitles, nor the embedded subtitles. In that case, it is possible to hardcode subtitles into the movie. For this to work, you need to use my minidlna-transcode fork (see my earlier comments) and edit the minidlna.conf to contain:
    transcode_video_containers=all
    and change the
    transcode_video_transcoder=/path/to/transcode_video-hardcodesub
    to point to the "transcode_video-hardcodesub" script that can be found in the sources in "transcodescripts" directory. Also this requires mencoder to be installed.

     
  • kalosh

    kalosh - 2012-10-19

    Hi.
    I am new in decoding/encoding audio and video. My TV does not support DTS audio. Is there possibility to configure that patch or stativ's branch to convert DTS audio to MP3 or AAC on the fly?
    Best regards, Dawid.

     
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2012-10-20

    kalosh: it is possible with minidlna-transcode branch. The easy way is to force transcoding for all video files by setting "transcode_video_containers=all".

    The clean way is to use ffprobe on a movie to find out the audio codec name (for DTS it's probably going to be "dts"). Then use this name for the transcode_audio_codecs option in minidlna.conf, eg:
    transcode_audio_codecs=dts

    Now you need to set an appropriate transcode_video_transcoder. There are some example scripts in sources in the transcodescripts directory. These scripts transcode movies to the DVD PAL format (mpeg2 video, AC3 audio), but you are free to edit the script to suit your needs. The only important thing with is to use output to stdout (for ffmpeg it is achieved using pipe:1, see the example scripts) and to disable any verbose output.

    Eg. if you want to have mp3 audio, but leave the video stream as is, you can try the following ffmpeg command in the script (not tested, may need some tweaks):

    ffmpeg -ss $2 -t $3 -i "$1" -loglevel quiet -threads 4 -async 2 -vcodec copy -acodec mp3 -ab 192k -f mpegts pipe:1

     
  • kalosh

    kalosh - 2012-10-20

    Thanks stativ for the answer. I have some progress but I am stuck. My config:
    transcode_audio_codecs=dca #properly takes only DTS files for transcoding, rest is filtered out
    transcode_audio_transcoder=#here I have problem.
    If I run from commandline:
    ffmpeg -ss 1 -t 80 -vbsf h264_mp4toannexb -i dtsMovie.mkv -loglevel verbose -threads 2 -async 2 -vcodec copy -acodec ac3 -ab 192k -f mpegts pipe:1
    I get many characters displayed (like this: ▒▒01扟▒▒▒▒Z<'@G
    X-▒m▒Y~
    ▒7▒▒▒Tr{▒▒▒v▒▒{▒rF▒▒▒▒▒ˋD▒▒▒▒▒?{Ɉ▒▒▒l▒@▒mJ▒-▒^}5▒▒V▒▒▒▒▒k▒▒▒▒▒qљЏ▒▒▒▒▒Y▒▒▒▒#▒ ▒x▒▒}8▒:▒▒▒:=▒▒▒*▒▒▒▒▒▒▒▒▒▒) so I believe command is working (correct me if I am wrong).
    Unfortunately if I put it in configuration:
    transcode_video_transcoder=ffmpeg -ss $2 -t $3 -vbsf h264_mp4toannexb -i "$1" -loglevel quiet -threads 2 -async 2 -vcodec copy -acodec copy -ab 192k -f mpegts pipe:1
    on TV is not working (file is corrupted - TV says, and even time is not properly recognised - it shows 111 hours). I have added -vbsf h264_mp4toannexb because on commandline was error and ffmpeg advised me to add that (without the option commandline and minidlnad does not either).
    This may help: I am using for DTS to AC3 conversion following command:
    avidemux2_cli --load "input.mkv" --audio-process --audio-codec "AC3" --audio-bitrate 640 --output-format MATROSKA --save "output.mkv"
    Thank for your time.

     
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2012-10-20

    kolash: you are right that your ffmpeg command works (or at least it seems to work, I'm not able to read these characters ;-)).

    Anyway, I was probably not entirely clear. Do not paste your ffmpeg command directly into the minidlna.conf. Instead create a shell script containing this command, ie. create an executable script and call it, let's say /usr/bin/transcodevideo:

    #!/bin/sh
    ffmpeg -ss $2 -t $3 -vbsf h264_mp4toannexb -i "$1" -loglevel quiet -threads 2 -async 2 -vcodec copy -acodec copy -ab 192k -f mpegts pipe:1

    Now set:
    transcode_video_transcoder=/usr/bin/transcodevideo

    I hope this helps. You can also try the example scripts, these are tested and they should work on most systems (well, on NTSC it is necessary to change target to ntsc-dvd obviously).

    Regarding the time – it is possible that the time won't be correct and the seeking won't work even if the playing of a transcoded stream works. That's because many clients don't support the time based seeking which is required for the transcoded media.

     
  • kalosh

    kalosh - 2012-10-20

    Ok. I have few improvements.
    config (all other options transcode* are commented out):
    transcode_audio_codecs=dca
    transcode_video(audio)_transcoder=/etc/transcode_audio
    file with command:
    avconv -ss $2 -t $3 -i "$1" -loglevel quiet -threads 2 -async 2 -vcodec libx264 -acodec ac3 -ab 192k -f mpegts pipe:1
    And I am receiving:
    [2012/10/20 23:51:09] upnphttp.c:2327: warn: Prepared to send data, transcode: 1!
    [2012/10/20 23:51:09] upnphttp.c:1412: info: start transcode and send data
    [2012/10/20 23:51:09] upnphttp.c:1432: info: Starting poll
    exec_transcode execvp(): Access denied (File or directory not found)
    [2012/10/20 23:51:09] upnphttp.c:1444: info: reached to EOF in PID:15863
    TV does not recognises the audio and video but the time is correctly displayed. Configuration with the copy of audio and video gives the same results.

    I have found the error message in code but I am not able to read that and fix it (https://bitbucket.org/stativ/minidlna-transcode/src/8889bd6ee0b8/transcode.c line 71). Could you please take a look at this?
    I hope I am close:)

     
  • kalosh

    kalosh - 2012-10-20

    Ok. I have few improvements.
    config (all other options transcode* are commented out):
    transcode_audio_codecs=dca
    transcode_video(audio)_transcoder=/etc/transcode_audio
    file with command:
    avconv -ss $2 -t $3 -i "$1" -loglevel quiet -threads 2 -async 2 -vcodec libx264 -acodec ac3 -ab 192k -f mpegts pipe:1
    And I am receiving:
    [2012/10/20 23:51:09] upnphttp.c:2327: warn: Prepared to send data, transcode: 1!
    [2012/10/20 23:51:09] upnphttp.c:1412: info: start transcode and send data
    [2012/10/20 23:51:09] upnphttp.c:1432: info: Starting poll
    exec_transcode execvp(): Access denied (File or directory not found)
    [2012/10/20 23:51:09] upnphttp.c:1444: info: reached to EOF in PID:15863
    TV does not recognises the audio and video but the time is correctly displayed. Configuration with the copy of audio and video gives the same results.

    I have found the error message in code but I am not able to read that and fix it (https://bitbucket.org/stativ/minidlna-transcode/src/8889bd6ee0b8/transcode.c line 71). Could you please take a look at this?
    I hope I am close:)
    Edit:
    I have forgotten about chmod on transcode_audio file (that is why access denied was occurred). After fixing that rookie mistake I am receiving as following:
    Seems stream 0 codec frame rate differs from container frame rate: 47.95 (5000000/104271) -> 23.98 (24000/1001)
    Stream mapping:
    Stream #0.0 -> #0.0
    Stream #0.1 -> #0.1
    Press ctrl-c to stop encoding
    frame= 0 fps= 0 q=-1.0 Lsize= 0kB time=10000000000.00 bitrate= 0.0kbits/s
    video:0kB audio:0kB global headers:0kB muxing overhead -nan%
    [2012/10/21 00:32:52] upnphttp.c:1444: info: reached to EOF in PID:16609
    Stream mapping:
    Stream #0.0 -> #0.0
    Stream #0.1 -> #0.1
    Press ctrl-c to stop encoding
    frame= 0 fps= 0 q=-1.0 Lsize= 0kB time=10000000000.00 bitrate= 0.0kbits/s
    video:0kB audio:0kB global headers:0kB muxing overhead -nan%
    [2012/10/21 00:32:52] upnphttp.c:1444: info: reached to EOF in PID:16610
    ... and no audio and video. Any advices?

     
  • kalosh

    kalosh - 2012-10-20

    Additional info: while digging through the console output I have read as following:
    [2012/10/21 00:38:58] transcode.c:260: warn: Opening /mnt/sda5/library/Movies/The.Bourne.Collection/The.Bourne.Identity.2002.HDDVD.1080p.DTS.x264.dxva-EuReKA.[SAMPLE].mkv
    [matroska,webm @ 0x236e9a0] Estimating duration from bitrate, this may be inaccurate
    [2012/10/21 00:38:59] transcode.c:270: warn: DONE
    [2012/10/21 00:38:59] upnphttp.c:2077: debug: Executing transcode
    [2012/10/21 00:38:59] upnphttp.c:2100: debug: Obtaining metadata
    [2012/10/21 00:38:59] dlnameta.c:306: warn: Opening pipe:14
    [2012/10/21 00:38:59] dlnameta.c:313: warn: Opening pipe:14 failed! [Invalid data found when processing input]

     
  • kalosh

    kalosh - 2012-10-20

    Just to be sure. I want to have video not touched but only audio processed. Should I use transcode_video_transcoder or *audio* property in the config? If I use audio I am still getting exec_transcode execvp(): File or directory not found.

     
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2012-10-21

    There seems to be some problem with the avconv, because it detects exactly double bitrate. As a result, it prints out some debug output which is picked up by minidlna and then sent as a video stream to the TV. I think the problem may be caused by combination of "-vcodec libx264" and "-f mpegts", because mpegts is for MPEG 2 while x264 is MPEG 4 AVC.

    When debugging this issue I'd start by testing the command using standard output file and using default settings for loglevel, eg.:

    avconv -i some/testing/file -threads 2 -async 2 -vcodec libx264 -acodec ac3 -ab 192k -f mpegts out.mpg

    and check its output for errors/warnings. Then I'd try to to get rid of these problems. After polishing the options, I would add the "-loglevel quiet" to disable any output (because this outputs breaks streaming), output to pipe:1 and try to play it using avplay:

    avconv -i some/testing/file -loglevel quiet -threads 2 -async 2 -vcodec libx264 -acodec ac3 -ab 192k -f mpegts pipe:1 | avplay -

    If all of this works, then there is either bug in minidlna-transcode, or the combination of codecs is not supported by the client (eg. TV).

    Regarding the config settings, I think it would be best if I explained how the code that handles transcoding of video files works in this regard.

    Before minidlna-transcode serves a movie to the client, it first checks if there is "transcode_video_containers=all". In that case transcoding is always executed. Then it checks the audio codec of the video file against the "transcode_audio_codecs" settings. After that, it checks the transcode_video_containers for containers that needs to be transcoded. Finally, it checks the "transcode_video_codecs" setting. When any of these settings matches, the video is always sent to the script defined in "transcode_video_transcoder"

    Also, if you want the video to be left untouched, while transcoding audio, use the "-vcodec copy"

     
  • kalosh

    kalosh - 2012-10-21

    Ok, thank you very much for the rumpimg up me:) I will need some time for polishing and inform you (I hope) soon:))

     
  • jonesal2

    jonesal2 - 2012-10-27

    Please can you give me an idea how I would apply this patch to the miniDLNA package I have installed from the ubuntu 10.04 repo?

    Also, is it possible to transcode and stream at different bit rates for different devices?? For example all of my audio files are in uncompressed flac format so for my android device I would like an 128kbs mp3 bit for the XBMC PC I do not need any transcoding and for my laptop I would like 256kbs mp3.

    Thanks

     
  • Lukas Jirkovsky

    Lukas Jirkovsky - 2012-10-31

    jonesal2:
    To use the hiero's patch, download the sources for minidlna 1.0.24 and the patch minidlna_transcode_1.0.24-5.tar.gz. After unpacking the sources patch them using the patch command (there are tons of examples on the Internet on how to apply patches) and then compile it. It cannot be applied against a binary package.

    To use the minidlna-transcode branch, download the sources using mercurial from the bitbucket and compile them as usual.

    Regarding the different transcode setting:
    It's certainly not possible with the minidlna-transcode branch and I don't think it's possible with Hiero's patch either. You may want to check Serviio and PS3 Media Server. Both of them presents some settings depending on a client, but I don't recall any of them having an option to change the transcoding settings depending on the client. I think it's possible with MediaTomb, but the setup is rather painful and it seems to be a dead project.

     
  • BooLE

    BooLE - 2012-11-28

    Hi,

    can someone please post a patch for latest minidlna 1.0.25? Thanks.

     
  • Kaloyan Kolev

    Kaloyan Kolev - 2013-01-01

    Hi there,

    Happy new year to all of you!

    I managed to run minidlna-transcode with default config, i.e.
    transcode_audio_codecs=
    transcode_audio_transcoder=
    transcode_video_containers=
    transcode_video_codecs=vp8/theora/flv/flv1/svq3
    transcode_video_transcoder=

    However I am getting the following error for some of the avi videos:
    scanner.c:488: warn: Unsuccessful getting details for /home/kkolev/Downloads/Pitch.Perfect.2012.720p.BRRiP.XViD.AC3-LEGi0N.avi!

    I don't receive this with the minidlna 1.0.24 branch. I wanted to play around with transcoding this file, but minidlna-transcode is not able to index it.

    avconv version 0.8.4-4:0.8.4-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
    built on Nov 6 2012 16:50:25 with gcc 4.6.3
    Input #0, avi, from 'Pitch.Perfect.2012.720p.BRRiP.XViD.AC3-LEGi0N.avi':
    Metadata:
    encoder : VirtualDubMod 1.5.10.2 (build 2540/release)
    Duration: 01:52:07.38, start: 0.000000, bitrate: 4445 kb/s
    Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 1280x688 [PAR 1:1 DAR 80:43], 23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 640 kb/s
    At least one output file must be specified

    the following is getting recognized though, and even plays fine on the TV with above default config:
    scanner.c:690: info: Scanning /home/kkolev/Downloads/Ice.Age.A.Mammoth.Christmas.DVDRip.XviD-3LT0N
    metadata.c:665: debug: Container: 'avi' [Ice.Age.A.Mammoth.Christmas.DVDRip.XviD-3LT0N.avi]
    dlnameta.c:451: debug: Container: 'avi' [Ice.Age.A.Mammoth.Christmas.DVDRip.XviD-3LT0N.avi]

    avconv version 0.8.4-4:0.8.4-0ubuntu0.12.04.1, Copyright (c) 2000-2012 the Libav developers
    built on Nov 6 2012 16:50:25 with gcc 4.6.3
    [mpeg4 @ 0x95f3980] Invalid and inefficient vfw-avi packed B frames detected
    Input #0, avi, from 'Ice.Age.A.Mammoth.Christmas.DVDRip.XviD-3LT0N/Ice.Age.A.Mammoth.Christmas.DVDRip.XviD-3LT0N.avi':
    Duration: 00:25:29.81, start: 0.000000, bitrate: 1120 kb/s
    Stream #0.0: Video: mpeg4 (Advanced Simple Profile), yuv420p, 640x352 [PAR 1:1 DAR 20:11], 23.98 tbr, 23.98 tbn, 23.98 tbc
    Stream #0.1: Audio: mp3, 48000 Hz, stereo, s16, 128 kb/s
    At least one output file must be specified

    Any help will be much appreciated.

    Thanks.

     
<< < 1 .. 4 5 6 7 8 > >> (Page 6 of 8)

Log in to post a comment.