Llink:transcoding: Difference between revisions

From Lundman Wiki
No edit summary
 
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Year Six ===
== Transcoding ==


2010. Lokien is 6, but just a couple of months away from 7. Kajerik is 3, and about halfway to 4.
Transcoding with llink is a relatively new features (as of llink-2.3.2) which still needs a fair bit of work. Each device will need its own settings, and tweaks.


It has been a while, I guess maybe because we have all become a team,.. somehow. It just flows, and everyone is mostly sane now. Kajerik used to have tantrums, as you would expect of a 3 year old, but they too, have faded.
As an example, Playstation 3 can not play ''.mkv'' files (as of 3.70 anyway). So we ask llink to change any file ending with ''.mkv'' into a different format. Since it is streaming (not writing the whole encoded file on disk before sending) what we send to the PS3 has to be a format capable of streaming. Like that of MPEG-TS. So we convert the file into a ''.mpg'' file, or rather, ''.mkv.mpg''.


Lokien started school. That was quite the journey. Back at the start of the year, we were still quite concerned about his Speech Delay, and how it would affect him going to a Japanese school. Everything would presumably be harder for him as he would not have full Japanese at home. At the same time, his English would be much better than anyone in his class, but of course, compared to a child in New Zealand, he would be lagging in English as well.
To detect that it is a PS3 that is talking to llink, and not a player that CAN handle ''.mkv'' files, we need to make some match rules. Usually, these operate on the ''User-Agent'' header in HTTP requests, or the ''SERVER:'' tag in UPNP's ''BrowseDirectChildren''.


By default, you tend to get assigned to the school that is closest to your home. In our case, it is Sanya School. But the largest school in Shibuya-ward is Jinnan, which has a much higher number of foreigners, and after-school care for those with special needs. Naturally we went to both schools to get a better understanding. When they say 'special needs', they really mean it. They can handle children with serious afflictions, far beyond what Lokien required.
To define where to find the transcode binary, I have been using ''ffmpeg'', but other programs could probably be used. In fact, one day one might be able to pass it to a "transcode -for ps3" program, wouldn't that be nice.


Either way, we applied for Lokien to go to Jinnan as well, and figured that the decision would be made for us. Either he got in, or he didn't.  We went to the lottery-day for Jinnan school. Basically, they do a lottery to determine the order of the children in the waiting list. Lokien got number 17, out of 26. So it was not definite for either direction. Previous years had seen all 30 children be placed, and some years only 12. We figured we would stay in the waiting list anyway, and went on holiday to NZ.
So, a '''TRANSCODE''' line might look something like:


When we got back, as we had not heard anything we had figured that he was still in the waiting list, and Sanya would be the school. We were quite pleased with this outcome, as Sanya is very close to home. There is only one road to cross, and it has school crossing guards. We could see the benefits that Lokien could earn his independence to walk to school on his own (eventually) and all his class mates would all live nearby, within walking distance.  Whereas, Jinnan would be at least a Bus ride, or be transported by one of us parents.
TRANSCODE|USERAGENT=*playstation*|ext=*.mkv|newext=.mpg|args=./ffmpeg -d -i "%s" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 -


When we went to Sanya to sign up, they were a little surprised, as it turns out, he did in fact, get accepted into Jinnan school. Hah, so much for letting the decision work itself out. Oh well, we had already mentally prepared ourselves for Sanya, and that we would have to help him with extra work. So, Sanya is the school.
In this case, we detect a PS3 if the ''User-Agent:'' tag contains "playstation" anywhere in it (case-insensitive).
We only change files of ''.mkv'' type.
We will produce new files of ''.mpg'' type. (MIME type is then based on ''.mpg'' and becomes ''video/mpeg''.)
llink will execute


First day of school, we all joined in, there was a ceremony, and photo ops, the usual speeches and so on. Lokiens class has some 36 students (the exact maximum for a single class). He already knows one friend in the class, who went to the same Hoikuen (day care) as Lokien. Lokien was really proud to get his own train pass, home key and independence to walk to school without us. We do still tail him ' up the road' where he meets his class mates, and then they go on together, without us. As it turns out, because he is a foreigner in the school (actually, the only white kid in the school) the ward organises for him to get private Japanese classes when there is a generic Japanese class for the rest. As it turns out, since there are no foreigners in year 2 either, he gets 2 private classes a week. This turns out to be really good news. Had we known this last year, we might not have stressed as much as we did.
  '''./ffmpeg -d -i "http ://localhost:8001/path/to/video.mkv" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 -'''


He seems to excel at maths, and English (well, compared to peers), and appears to be on same level with his Hiragana as the other class mates. He does his homework as soon as he gets home, and no special concerns from his teachers, yet. He seems to really enjoy school, and we have no issues to get him up and going in the mornings. (knock on wood).
The important parts here is '''-i "%s"''' would specify input file, in this case llink will replace '''%s''' with the actual URL to play. Note that ffmpeg appears to be very picky with argument order. Ie, specifying '''-i "%s"''' at the end will not work.


He is very easy to get along with now, I have taken him to the cinema, and find that there is no stress at all, as compared to taking a new born out the first day! He has earned my trust in him after all, and he is great to take out. Not at all an effort to take out on the trains, or to a restaurant, movies and so on. He appears kind to other kids, and does not hit or do mean things. To the point where maybe he is tipping towards being 'too nice', if that makes sense.  
'''The final minus "-" is important. It tells ffmpeg to send the stream to stdout. Which is why you have to use ''-f mpegts'' to set the output format.'''  If you use '''mencoder''', use ''-o -'' to send stream to stdout. '''mencoder''' generally requires the use of ''-really-quiet'' as to not to pollute stdout.


He can occasionally have episodes where he gets 'super focused' on someone, or something. Like he used to be at the height of hyperlexia. Usually, it is that he just can not leave Kajerik alone, and follows him around until we have to hold Lokien back. Or it is some toy that he just has to have. He can't continue to play with other things either, he will just sit there and wait for the toy he has to have, for however long it takes. (we're talking 20 minutes or more). Complete tunnel vision! 
If you wish to see what ''User-Agent:'' headers your device send, use


Lokien will fall asleep within minutes at night, and wakes up early in the morning, ready to go. I would describe him as a morning person at the moment.
./llink -d -v 16
[skin] checking for matching transcoders to user-agent 'Platinum/0.5.3.0, DLNADOC/1.50'
[skin] matches '*latinum*' (ext '*.avi')


Kajerik is still going to Hoikuen, the same one that he and Lokien went to last year. He has moved up to the middle room, momo gumi. He isn't too sure about going, and had a period of not wanting to go at all. Nowhere near as strongly as Lokien was at one time, but still occasionally reluctant. Recently he has been resigned and accepting of it. It has helped that the pool opened at Hoikuen as he, this year at least, appears to enjoy splashing around in the pool. He speaks considerably better English that Lokien did at that age. Full, complete sentences compared to Lokien's 10-word vocabulary.  
As far as transcoding goes, we do almost none. Video codec (h264) and audio of the ''.mkv'' file is copied without changing. We are just changing transport encapsulation from ''.mkv'' to ''mpeg-ts''. Very low CPU in this case.


Kajerik's lengthy battle this year was toilet training. He got the peeing down pretty much the first day, and did well with it on average. Some days he didn't care, some days he had completely dry nappies . However, with pooing it was an entirely different story. He appeared to just plain not care to do that. I think he understood what was going on, but just did not see the point. He managed to not go to the toilet for 5 days, somehow, and learned to be really sneaky about it. He would simply, quietly, walk out of the room, and fill his nappy in about 12 seconds. Quite impressive when you think about the length he took to not have to go to the toilet.  But in the end, he figured it out, and was proud about the whole situation. Strangely, since Lokien was toilet trained a little later than Kajerik, it turns out that they figured it out at about the same time, to the month.  If they aren't ready, they just aren't.


Kajerik is quite a cheerful and mischievous little bugger, but already would appear a little less physical than Lokien. Kajerik does appear to like music and singing a little more though. Hoikuen has expressed some small concern that he does not speak much Japanese, and has not really made 'good' friends there, 'is there a speech problem'? Here at least we can just smile and know that Kajerik is just fine with his speech. It is true he uses much less Japanese, since he plays with Lokien for hours each day and they tend to play in English if they are at home. Lokien easily switches to Japanese when he plays with other friends, and I know Kajerik understands Japanese quite well. He just appears to 'not wanting to speak Japanese' by choice.  I suspect he will most likely make a friend close to his age soon enough. We all remember his much cooler it was to play with older kids.
To test your own transcoding argument, I would recommend running the command line yourself, like this:


There is little, to no stress taking Kajerik out, he is easier to 'steer' than his brother was. Much more accepting to directions. But will generally 'tire' more quickly to be carried, or pushed around. At least, until there is something of interest, then he'll be happy to jog off again.  
./ffmpeg -i "http ://localhost:8001/path/to/video.mkv" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 - > test-encode.mpg


Kajerik will generally take longer to fall asleep, just stuffs around in bed for a while, but he is good about it. Stays quiet for his brother's sake, and eventually falls a sleep. He sleeps a little longer in the mornings, and take longer to snap out the morning grumpy mood. Like myself, I would describe him as a night person, at the moment.
I removed the -d so you now get ''stderr'' output and can see any encoding errors. I keep the "-" to send to stream, and sent it to a file "> test-encode.mpg". This is to make sure you are using stream, and not doing formats that can not stream. (Like mp4).


 
Then simply test-play the file "test-encode.mpg" on your device to make sure it is ok.
Together they are great. They play together very well, show each other new things and generally get along well. They occasionally melt down a little and hassle each other (too far), but are fairly good at knowing the limits. They can both make each other cry, so it is not a one-way street by any means. There can still be some improvements in their diets I think, but that seems to work itself out too, with time.  


Lokien loves cheese, sausages, ham, omelets, fries, milk, milkshakes, bananas, sembe, bread, rice, chicken, plain cakes, and hates anything sweet like chocolate, coke, icing, chips.
In my tests, I am using:
Kajerik loves rice, fries, chicken nuggets, sausages, plain cakes, bread, chocolate, chips, coke and hates icing, milkshakes, bananas, cheese.


So they are different in their likes and don't like. They both eat everything served at school/hoikuen though, which is a very Asian fare. Including miso-soup and strange fish with vegetables.
ffmpeg version 0.8.4


We went to NZ and a short trip to Chiba this year, there were minor issues with Kajerik being restrained in a car, but overall they were excellent family-style holidays. We all had a great time, and had fun both traveling and being there. We learned that Lokien can't have two milkshakes in one day in Kuala Lumpur, and how to (not) fly with kids having chickenpox. It was great to see the interaction between our kids and my brother's three kids, as well as how my brother's family interacted internally. I can also look back at myself and how I was, and behaved, when Lokien was first born and know how much of the 'new parent' stress really is .. well.. amusing, but you can't know that until you have been through it. I know it doesn't help to tell 'new parents' to 'relax more', but really, you should relax more. :)
Below, insert any good transcoding options you might find.
 
=== Playstation 3 ===
 
'''ffmpeg''' Change MKV to MPG, appears to work for Scene standard tv. Almost plays 720p for me with 4 cores. Almost.
TRANSCODE|USERAGENT=*playstation*|ext=*.mkv|newext=.mpg|args=./ffmpeg -y -i "%s" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 -
 
'''mencoder''' Change MKV to MPG, appears to work for Scene standard tv.
TRANSCODE|USERAGENT=*|ext=*.mkv|newext=.mpg|args=./mencoder "%s" -really-quiet -oac lavc -ovc lavc -of mpeg  -lavcopts vcodec=mpeg2video:keyint=1:vbitrate=200000:vrc_maxrate=9000:vrc_buf_size=1835:threads=4  -mpegopts muxrate=12000 -vf harddup  -o -
 
=== XBox 360 ===
 
 
=== Apple ipad ===
 
 
=== Apple ipad 2 ===
 
 
=== Apple iphone ===
 
 
=== Google Android ===
 
Tested with ''Softmedia Player Trial'' and ''Mirage''.
 
TRANSCODE|USERAGENT=*android*|ext=*.avi|newext=.mpg|args=./ffmpeg -d -i "%s" -acodec libmp3lame -ar 48000 -ab 128k -ac 2 -s 720x480 -vcodec libx264 -b 1200k -flags +loop+mv4 -cmp 256 -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 3 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1200k -maxrate 1200k -bufsize 1200k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 -r 30 -g 90 -async 2 -f mpegts -
Almost works, plays fine for a while, but drops to 5 fps or so at times. Appears not to recover.
 
 
=== More here ===
 
EyeCon sends
User-Agent: Eyecon ControlPoint 2.0 | DMC/1.0
 
AcePlayer sends
Absolutely nothing :(
 
MLPlayer Lite
USER-AGENT: Darwin/11.0.0 UPnP/1.0 DLNADOC/1.50
 
PlugPlayer
USER-AGENT: iPad/4.3.2, UPnP/1.0, PlugPlayer/3.8.0
 
YXPlayer
User-Agent: Platinum/0.5.3.0, DLNADOC/1.50
 
Playstation 3
 
X-AV-Client-Info: av=5.0; cn="Sony Computer Entertainment Inc."; mn="PLAYSTATION 3"; mv="1.0";
User-Agent: UPnP/1.0 DLNADOC/1.50

Latest revision as of 12:27, 6 October 2011

Transcoding

Transcoding with llink is a relatively new features (as of llink-2.3.2) which still needs a fair bit of work. Each device will need its own settings, and tweaks.

As an example, Playstation 3 can not play .mkv files (as of 3.70 anyway). So we ask llink to change any file ending with .mkv into a different format. Since it is streaming (not writing the whole encoded file on disk before sending) what we send to the PS3 has to be a format capable of streaming. Like that of MPEG-TS. So we convert the file into a .mpg file, or rather, .mkv.mpg.

To detect that it is a PS3 that is talking to llink, and not a player that CAN handle .mkv files, we need to make some match rules. Usually, these operate on the User-Agent header in HTTP requests, or the SERVER: tag in UPNP's BrowseDirectChildren.

To define where to find the transcode binary, I have been using ffmpeg, but other programs could probably be used. In fact, one day one might be able to pass it to a "transcode -for ps3" program, wouldn't that be nice.

So, a TRANSCODE line might look something like:

TRANSCODE|USERAGENT=*playstation*|ext=*.mkv|newext=.mpg|args=./ffmpeg -d -i "%s" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 -

In this case, we detect a PS3 if the User-Agent: tag contains "playstation" anywhere in it (case-insensitive). We only change files of .mkv type. We will produce new files of .mpg type. (MIME type is then based on .mpg and becomes video/mpeg.) llink will execute

./ffmpeg -d -i "http ://localhost:8001/path/to/video.mkv" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 -

The important parts here is -i "%s" would specify input file, in this case llink will replace %s with the actual URL to play. Note that ffmpeg appears to be very picky with argument order. Ie, specifying -i "%s" at the end will not work.

The final minus "-" is important. It tells ffmpeg to send the stream to stdout. Which is why you have to use -f mpegts to set the output format. If you use mencoder, use -o - to send stream to stdout. mencoder generally requires the use of -really-quiet as to not to pollute stdout.

If you wish to see what User-Agent: headers your device send, use

./llink -d -v 16
[skin] checking for matching transcoders to user-agent 'Platinum/0.5.3.0, DLNADOC/1.50'
[skin] matches '*latinum*' (ext '*.avi')

As far as transcoding goes, we do almost none. Video codec (h264) and audio of the .mkv file is copied without changing. We are just changing transport encapsulation from .mkv to mpeg-ts. Very low CPU in this case.


To test your own transcoding argument, I would recommend running the command line yourself, like this:

./ffmpeg -i "http ://localhost:8001/path/to/video.mkv" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 - > test-encode.mpg

I removed the -d so you now get stderr output and can see any encoding errors. I keep the "-" to send to stream, and sent it to a file "> test-encode.mpg". This is to make sure you are using stream, and not doing formats that can not stream. (Like mp4).

Then simply test-play the file "test-encode.mpg" on your device to make sure it is ok.

In my tests, I am using:

ffmpeg version 0.8.4

Below, insert any good transcoding options you might find.

Playstation 3

ffmpeg Change MKV to MPG, appears to work for Scene standard tv. Almost plays 720p for me with 4 cores. Almost.

TRANSCODE|USERAGENT=*playstation*|ext=*.mkv|newext=.mpg|args=./ffmpeg -y -i "%s" -threads 4 -vbsf h264_mp4toannexb -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -ac 2 -vcodec copy -async 2 -

mencoder Change MKV to MPG, appears to work for Scene standard tv.

TRANSCODE|USERAGENT=*|ext=*.mkv|newext=.mpg|args=./mencoder "%s" -really-quiet -oac lavc -ovc lavc -of mpeg  -lavcopts vcodec=mpeg2video:keyint=1:vbitrate=200000:vrc_maxrate=9000:vrc_buf_size=1835:threads=4  -mpegopts muxrate=12000 -vf harddup  -o -

XBox 360

Apple ipad

Apple ipad 2

Apple iphone

Google Android

Tested with Softmedia Player Trial and Mirage.

TRANSCODE|USERAGENT=*android*|ext=*.avi|newext=.mpg|args=./ffmpeg -d -i "%s" -acodec libmp3lame -ar 48000 -ab 128k -ac 2 -s 720x480 -vcodec libx264 -b 1200k -flags +loop+mv4 -cmp 256 -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 3 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 1200k -maxrate 1200k -bufsize 1200k -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 30 -aspect 16:9 -r 30 -g 90 -async 2 -f mpegts -

Almost works, plays fine for a while, but drops to 5 fps or so at times. Appears not to recover.


More here

EyeCon sends

User-Agent: Eyecon ControlPoint 2.0 | DMC/1.0

AcePlayer sends

Absolutely nothing :(

MLPlayer Lite

USER-AGENT: Darwin/11.0.0 UPnP/1.0 DLNADOC/1.50

PlugPlayer

USER-AGENT: iPad/4.3.2, UPnP/1.0, PlugPlayer/3.8.0

YXPlayer

User-Agent: Platinum/0.5.3.0, DLNADOC/1.50

Playstation 3

X-AV-Client-Info: av=5.0; cn="Sony Computer Entertainment Inc."; mn="PLAYSTATION 3"; mv="1.0";
User-Agent: UPnP/1.0 DLNADOC/1.50