Page 1 of 2

[Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP, MOV

PostPosted: Mon Jan 30, 2012 12:13 am
by huyz
EDIT: the audio problem with 3GP files with AMR-NB audio should be fixed in 0.6.2
EDIT: added fix for MP4 files with mpeg4 codec


I got a new profile and hacks working for my Panasonic ST30 (specifically TC-P60ST30). These solutions may also work for you if you have a Panasonic GT30, S30, X30, etc.
They fix transcoding for Panasonics that have the following problems:
    - this Panasonic doesn't natively handle AVI / DivX / Xvid
    - when transcoding AVIs with Xvid/DivX, there are video-audio sync problems.
    - this Panasonic doesn't natively handle MP4 files with mpeg4 video codec.
    - there's no sound for MOV/MP4 files with AAC audio, despite the claims from the Panasonic manual that AAC is supported.
    - there's no sound for 3GP files with AMR-NB audio.

I'm running Serviio 0.6.1 on Windows 7 64-bit.

First, let's get all the AVIs transcoded and let's get the sound working for MOV and MP4 files with AAC audio. I modified the existing Panasonic Viera profile and created a new profile as follows:
  Code:
   <Profile id="112" name="Panasonic Viera w/ AVI, MOV, MP4, 3GP (by huyz)" extendsProfileId="1">
      <ContentDirectoryMessageBuilder>org.serviio.upnp.service.contentdirectory.PacketVideoDLNAMessageBuilder</ContentDirectoryMessageBuilder>
      <SubtitlesMimeType>text/srt</SubtitlesMimeType>
      <Transcoding>
         <!-- remux DTS/FLAC/LPCM in MKV/MP4 to AC3 -->
         <Video targetContainer="mpegts" targetACodec="ac3">
            <Matches container="matroska" vCodec="h264" aCodec="dca" />
            <Matches container="matroska" vCodec="h264" aCodec="flac" />
            <Matches container="matroska" vCodec="h264" aCodec="vorbis" />
            <Matches container="matroska" vCodec="h264" aCodec="truehd" />
            <Matches container="mp4" vCodec="h264" aCodec="lpcm"/>
            <!-- huyz: ST30 manual says AAC should work (and it does for MKV) but transcoding is needed for our .mp4 (and the equivalent .mov) files -->
            <Matches container="mp4" vCodec="h264" aCodec="aac"/>
            <Matches container="3gp" vCodec="h264" />
         </Video>
         <!-- Remux all h264 video to MPEG-TS stream -->
         <Video targetContainer="mpegts">
            <Matches container="avi" vCodec="h264" />
            <Matches container="mp4" vCodec="h264" />
            <Matches container="matroska" vCodec="h264" />
            <Matches container="matroska" vCodec="mpeg2video"/>
          </Video>
         <!-- unsupported codecs will be transcoded into mpeg-ts, mpeg2 video and ac3 audio -->
         <Video targetContainer="mpegts" targetVCodec="mpeg2video" targetACodec="ac3">            
            <!-- huyz: do all AVIs, including mpeg4 (Xvid) and msmpeg4 video codecs
            <Matches container="avi" vCodec="mjpeg" />
            <Matches container="avi" vCodec="dvvideo" />
            -->
            <Matches container="avi"/>
            <Matches container="mp4" vCodec="mjpeg" />
            <Matches container="mp4" vCodec="mpeg4" /> <!-- huyz: this Panasonic doesn't support mpeg4 -->
            <Matches container="asf" />
            <Matches container="flv" />
            <Matches container="ogg" />
            <Matches container="3gp" /> 
         </Video>
         <Audio targetContainer="mp3"> 
            <Matches container="mp4" />
            <Matches container="flac" />
            <Matches container="ogg" />
            <Matches container="asf" />
            <Matches container="adts" />
         </Audio>
      </Transcoding>      
   </Profile>


Now, for me, this wasn't enough for AVIs with Xvid/DivX. The video and audio were out of sync, and we need a Step 2 for this transcoding solution. It took me a long time to figure this out, but I had to hack a wrapper for the ffmpeg transcoder, written in Perl, in order to change one argument "-r 25" to "-r 30000/1001" (i.e. 29.97 fps). I don't know why Serviio is invoking ffmpeg with an output framerate of 25 instead of 29.97 -- I'm a North American! :D (bug?)
This Perl script also contains a hack for forcing ffmpeg to transcode the AMR-NB (AMR Narrowband) audio in 3GP files; for some reason, Serviio completely disables the audio for such files (another bug?).

Here are the steps to create and invoke this Perl script:
  1. Install Perl
  2. As per http://www.serviio.org/component/content/article/21#q3, go into the C:\Program Files\Serviio\bin directory and edit ServiioService.exe.vmoptions. On a new line, add the following (change perl64 to perl if you're running a 32-bit version of Perl):
      Code:
    -Dffmpeg.location="c:\perl64\bin\perl.exe c:\progra~1\Serviio\serviio-ffmpeg.pl"
  3. In the C:\Program Files\Serviio directory, create a file called serviio-ffmpeg.pl (customized from viewtopic.php?f=7&t=4711) that says:
      Code:
    #!perl
    # See http://forum.serviio.org/viewtopic.php?f=7&t=4711
    # and http://forum.serviio.org/viewtopic.php?f=11&t=2956&start=30

    use strict;

    my $args = '';

    foreach my $arg (@ARGV) {
      $args .= "\"$arg\" ";
    }

    # Don't know why the frame rate is wrong when transcoding AVIs
    $args =~ s/"-r"\s+"25"\s/"-r" "30000\/1001" /g;
    # This looks like a Serviio 0.6.1 bug for 3GP files; the aCodec is not recognized
    if ($args =~ /"-i"\s+"[^"]+\.3GP"\s.*\s"-an"/i) {
       $args =~ s/"-an"\s/"-acodec" "ac3" "-ar" "48000" "-map" "0:a" /ig;
    }

    my $cmd = "\"C:\\Program Files\\Serviio\\lib\\ffmpeg.exe\" $args";

    open(LOGFILE, ">>C:\\Program Files\\Serviio\\ffmpeg-wrapper.log");

    print LOGFILE scalar localtime . " Starting: " . $cmd . "\n";
    if (system($cmd) != 0) {
      print LOGFILE scalar localtime . " Failed: " . $cmd . " with $?\n";
      close (LOGFILE);
      die "Failed\n";
    } else {
      print LOGFILE scalar localtime . " Succeeded: " . $cmd . "\n";
      close (LOGFILE);
    }

Now, restart your Serviio service (by running services.msc) and you should be good to go.

If someone could shine some light on why the hacks for video-audio syncing and 3GP w/ AMR-NB are needed for Serviio 6.1, that would be great. I'm hoping these are just Serviio bugs that will be fixed, thus deprecating this Perl script.

Now, I wonder if I can solve the subtitles problem. Right now, MKVs with embedded subtitles are not supported by Serviio, and SRT files served alongside MKVs are ignored by the Panasonic TV. Any tips?

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 12:18 am
by Cerberus
If someone could shine some light on why the hacks for video-audio syncing and 3GP w/ AMR-NB are needed for Serviio 6.1, that would be great. I'm hoping these are just Serviio bugs that will be fixed, thus deprecating this Perl script.


video-audio syncing - not sure maybe ZIP can answer that one.

AMR-NB - never heard of that audio format but if you request support for it to be added in the request section ZIP can add it to future release.

MKVs with embedded subtitles are not supported by Serviio


yes they are, but they might not be by the device, and will need burning into video track which is not supported yet.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 12:25 am
by huyz
Cerberus wrote:AMR-NB - never heard of that audio format but if you request support for it to be added in the request section ZIP can add it to future release.


Apparently, amrnb support was recently added. It is one of the aCodec matches allowed, as per http://www.serviio.org/index.php?option ... icle&id=24. But for me, putting aCodec="amrnb" doesn't work: the file doesn't match. And not mentioning the acodec makes Serviio disable the audio entirely by invoking ffmpeg with -an

Maybe that addition of amrnb support was a result of this thread viewtopic.php?f=7&t=2027&start=10 and this enhancement request https://bitbucket.org/xnejp03/serviio/i ... -3gp-video

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 12:34 am
by Cerberus
ah ok amrnd now i know what it is, well that can be solved in the profile then and doesnt require your hack.

in your profile you have this code:

  Code:
<Video targetContainer="mpegts" targetACodec="ac3">
<Matches container="3gp" vCodec="h264" />
</video>


That suggest that 3gp container is supported


and then later on your have.

  Code:
<Video targetContainer="mpegts" targetVCodec="mpeg2video" targetACodec="ac3">
<Matches container="3gp" />
</video>


but then you have this which suggests that its not supported.

so remove the first instance of 3gp in your profile and then it should work without your hack.


if it doesnt then maybe there is an issue that Zip need to look into.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 12:41 am
by huyz
Cerberus wrote:so remove the first instance of 3gp in your profile and then it should work without your hack.


The only difference between the two 3gp lines are video transcoding. The audio output parameter is the same. But the video is fine; it's the audio that's disabled.
I had tried what you suggested, and for good measure, I tried it again, but still no go.

For some reason, ffmpeg is invoked with audio disabled.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 12:42 am
by Cerberus
ok thats one for zip to look at then, will send him a PM.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 9:39 am
by zip
huyz wrote:Apparently, amrnb support was recently added. It is one of the aCodec matches allowed, as per http://www.serviio.org/index.php?option ... icle&id=24. But for me, putting aCodec="amrnb" doesn't work: the file doesn't match. And not mentioning the acodec makes Serviio disable the audio entirely by invoking ffmpeg with -an

Can you post ffmpeg -i of the file?

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 10:08 am
by huyz
zip wrote:
huyz wrote:Apparently, amrnb support was recently added. It is one of the aCodec matches allowed, as per http://www.serviio.org/index.php?option ... icle&id=24. But for me, putting aCodec="amrnb" doesn't work: the file doesn't match. And not mentioning the acodec makes Serviio disable the audio entirely by invoking ffmpeg with -an

Can you post ffmpeg -i of the file?


Sure, it's

  Code:
ffmpeg version 0.9, Copyright (c) 2000-2011 the FFmpeg developers
  built on Dec 13 2011 20:46:11 with gcc 4.4.2
  configuration: --enable-static --disable-shared --disable-ffplay --disable-ffserver --enable-memalign-hack --enable-li
bmp3lame --enable-librtmp --extra-libs='-lrtmp -lpolarssl -lws2_32 -lwinmm' --arch=x86 --enable-runtime-cpudetect --enab
le-pthreads --target-os=mingw32 --cross-prefix=i686-mingw32- --pkg-config=pkg-config
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 42. 0 / 53. 42. 0
  libavformat  53. 24. 0 / 53. 24. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'E:\DLNA Test files\3GP - MPEG4, AMRnb.3GP':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41isom
    creation_time   : 2009-10-10 20:18:01
    title           : 3GP - MPEG4, AMRnb
  Duration: 00:02:30.16, start: 0.000000, bitrate: 525 kb/s
    Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 480x352 [SAR 1:1 DAR 15:11], 510 kb/s,
 23.05 fps, 30 tbr, 30 tbn, 30 tbc
    Metadata:
      creation_time   : 2009-10-10 20:18:01
      handler_name    : vide
    Stream #0:1(eng): Audio: amr_nb (samr / 0x726D6173), 8000 Hz, 1 channels, flt, 12 kb/s
    Metadata:
      creation_time   : 2009-10-10 20:18:01
      handler_name    : soun
At least one output file must be specified

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 11:43 am
by Illico
huyz wrote: But for me, putting aCodec="amrnb" doesn't work: the file doesn't match.


Try aCodec="AMR"

match for 'amrnb' and 'amrwb' ffmpeg audio codec

Zip, you probably have to add 'amr_nb' and 'amr_wb"

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 12:33 pm
by zip
Illico wrote:Zip, you probably have to add 'amr_nb' and 'amr_wb"

Yep, seems that has changed in a recent FFmpeg. WIll stick it to 0.6.2.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 5:45 pm
by Cerberus
thank god for that though i was going mad.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 7:04 pm
by zip
Added to 0.6.2, the -an parameter was used as Serviio didn't recognize the codec.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 10:35 pm
by huyz
Illico wrote:
huyz wrote: But for me, putting aCodec="amrnb" doesn't work: the file doesn't match.


Try aCodec="AMR"

match for 'amrnb' and 'amrwb' ffmpeg audio codec

Zip, you probably have to add 'amr_nb' and 'amr_wb"


aCodec="AMR" doesn't work; neither does aCodec="amr". The Serviio service won't start.

If I do write aCodec="amrnb", the Serviio service does start, but as you said, Serviio should be supporting "amr_nb" and "amr_wb" instead, given the new FFmpeg.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 10:41 pm
by huyz
zip wrote:Added to 0.6.2, the -an parameter was used as Serviio didn't recognize the codec.


Great, thanks for the explanation.

How about the "-r 25" when I'm transcoding AVIs, that I mentioned in my OP? Any idea where that comes from and how it should specified without hacking a ffmpeg-wrapper.pl ?

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 11:06 pm
by zip
the -r 25 is based on the original fps. Can you post ffmpeg -i of a file that uses this frame rate transcoding option?

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Mon Jan 30, 2012 11:36 pm
by huyz
zip wrote:the -r 25 is based on the original fps. Can you post ffmpeg -i of a file that uses this frame rate transcoding option?


Here:
  Code:
ffmpeg version 0.9, Copyright (c) 2000-2011 the FFmpeg developers
  built on Dec 13 2011 20:46:11 with gcc 4.4.2
  configuration: --enable-static --disable-shared --disable-ffplay --disable-ffserver --enable-memalign-hack --enable-li
bmp3lame --enable-librtmp --extra-libs='-lrtmp -lpolarssl -lws2_32 -lwinmm' --arch=x86 --enable-runtime-cpudetect --enab
le-pthreads --target-os=mingw32 --cross-prefix=i686-mingw32- --pkg-config=pkg-config
  libavutil    51. 32. 0 / 51. 32. 0
  libavcodec   53. 42. 0 / 53. 42. 0
  libavformat  53. 24. 0 / 53. 24. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 53. 0 /  2. 53. 0
  libswscale    2.  1. 0 /  2.  1. 0
Input #0, avi, from 'e:\DLNA Test files\AVI - Xvid, MP3.avi':
  Duration: 00:00:42.12, start: 0.000000, bitrate: 1342 kb/s
    Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 640x272 [SAR 1:1 DAR 40:17], 25 tb
r, 25 tbn, 25 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16, 192 kb/s
At least one output file must be specified


Oh really? Well, if -r is about input and not output, then I can't make sense of the audio-video sync problems.

Here's the behavior I get:

  1. Input file AVI 25fps
    1. Default (ffmpeg is invoked with -r 25) => BAD, the video is apparently a bit slow, so the audio is not synced
    2. My hack changing invocation of ffmpeg -r 25 to ffmpeg -r 30000/1001 (yes, on 25fps input) => OK, the video and audio are synced
  2. Input file AVI 23.976fps
    1. Default (ffmpeg is invoked with -r 24000/1001) => OK, the video and audio are synced
    2. My hack changing invocation of ffmpeg -r ANYTHING to ffmpeg -r 30000/1001 (yes, on 23.976fps input) => OK, the video and audio are synced

Can you make sense of that?

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Wed Feb 01, 2012 1:00 pm
by zip
might be a bug in FFmpeg, try the latest version. they also provide tome parameters for syncing audio, by default we use async = 1 (I think).

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Fri Feb 17, 2012 11:19 pm
by zvjer
I don't have so many problems with my Viera G30 like these guys. I only have trouble decoding some TV series in avi container but otherwise an MPEG4 XVID. Most of the XVID movies work fine so You can guess I don't want to recode nothing but the "faulty" videos. Is there a way to separate those? I some avi-mpeg4-xvids are fine and some are not, how can I differentiate them? Transcoding cannot be configured "per folder" nor I can run two Serviios with two different profiles. Any other ideas?

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Sat Feb 18, 2012 6:21 am
by Tarrasque
zvjer wrote:I don't have so many problems with my Viera G30 like these guys. I only have trouble decoding some TV series in avi container but otherwise an MPEG4 XVID. Most of the XVID movies work fine so You can guess I don't want to recode nothing but the "faulty" videos. Is there a way to separate those? I some avi-mpeg4-xvids are fine and some are not, how can I differentiate them? Transcoding cannot be configured "per folder" nor I can run two Serviios with two different profiles. Any other ideas?


I have a found with the Panasonic, videos transcoded with transcode 1.0.2 - 1.1.10 ish do not seem to work. (play, but crash after a few seconds) I just run them through MKVmerge.. but yeah its annoying since about half of my collection (a lot of tv shows) have used transcode.

Re: [Solved] Panasonic Viera profile w/ AVI/DivX/Xvid, 3GP,

PostPosted: Sat Feb 18, 2012 9:20 am
by Cerberus
Tarrasque wrote:
zvjer wrote:I don't have so many problems with my Viera G30 like these guys. I only have trouble decoding some TV series in avi container but otherwise an MPEG4 XVID. Most of the XVID movies work fine so You can guess I don't want to recode nothing but the "faulty" videos. Is there a way to separate those? I some avi-mpeg4-xvids are fine and some are not, how can I differentiate them? Transcoding cannot be configured "per folder" nor I can run two Serviios with two different profiles. Any other ideas?


I have a found with the Panasonic, videos transcoded with transcode 1.0.2 - 1.1.10 ish do not seem to work. (play, but crash after a few seconds) I just run them through MKVmerge.. but yeah its annoying since about half of my collection (a lot of tv shows) have used transcode.


what profile are you using as avi and mp4 are not transcoded for most panasonics???