View Single Post
Old 05-08-2012, 09:17 PM   #60
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Arrow geekmaster kindle video transcoder

I added 90-degree rotate right to my "geekmaster video transcoder" so there is no need to compile ffmpeg from source code to get the video rotate function. While adding this feature, my code shrunk down to about 10-percent of the code it had before. Last time it shrunk a lot was when I added contrast and brightness adjustments. I like when adding features makes your code smaller.

Here is my simple, efficient and elegant video transcoder that takes 800x600 grayscale raw video piped from ffmpeg (or any other source of raw video), then does rotate right, "no dither table" ordered dither, and 8-pixel-per-byte packing.

I can find no evidence that performing an ordered dither using a logical expression derived by applying Karnaugh mapping to a dither table has been used before.

Here is the source code:
PHP Code:
//====================================================
// raw2gmv 1.0a - raw to geekmaster video transcoder
// Copyright (C) 2012 by geekmaster, with MIT license:
// http://www.opensource.org/licenses/mit-license.php
//----------------------------------------------------
#include <stdio.h>  // stdin,stdout
typedef unsigned char u8typedef unsigned int u32;
int main(void) {
    
u8 o,to,tb,wb0[800*600]; u32 x,y,xi,yi,c=250,b=120// c=contrast, b=brightness
    
while (fread(wb0,800*600,1,stdin)) for (y=0;y<800;y++) { xi=ytb=0;
        for (
x=0;x<600;x++) { yi=599-xo=x^y;
            
to=(y>>2&1|o>>1&2|y<<1&4|o<<2&8|y<<4&16|o<<5&32)-(wb0[yi*800+xi]*63+b)/c>>8;
            
tb=(tb>>1)|(to&128); if (7==(x&7)) { fwrite(&tb,1,1,stdout); tb=0; }
        }
    } return 
0;

Here is how I proxy a video stream to my kindle with 16:9 aspect ratio:
PHP Code:
ffmpeg -i http://mirrorblender.top-ix.org/movies/sintel-2048-surround.mp4 \
 
-pix_fmt gray -f rawvideo -vf pad=800:600:0:75 -s 800x450 -|./raw2gmv|nc -l 5555 
And here is a command to play a file from the host pc at full 800x600 resolution:
PHP Code:
ffmpeg -i SundayPicnic.mp4 -pix_fmt gray -f rawvideo -s 800x600 -|./raw2gmv|nc -l 5555 
Here is how I play those video streams on my kindle, after starting them on the PC:
PHP Code:
nc 192.168.15.201 5555|./gmplay 
UPDATE: I compiled this with gcc and again with arm-linux-gcc, so I can run it on either side of the network connection (host PC or kindle). It also works fine when compiled with tcc.

HINT: To pipe the output to a file (before or after transcoding) you need to add "-r 7.7" to the ffmpeg command line. When the kindle display is at the end of the chain (even over the USBnet using nc) ffmpeg automatically adapts to 7.7 Hz framerate (the max that a K3 can do). Such a low framerate makes for better compression and works amazingly (and surprisingly) well on eink. You could never go that slow on a light-emitting display.

I plan to combine this new transcoder inside gmplay, adding command-line switches to select input (raw or transcoded) and output (transcoded or framebuffer). Piping data between a transcoder and player adds a LOT of overhead passing video between two processes piped on the command line. Combining them will save a lot of energy, especially when running from battery. Because both functions can run inside the nested loops together, the total lines of code will be a lot smaller. I like that...


The ffmpeg commands above were for linux ffmpeg installed with apt-get.

We can do this in Windows too. Here are some download links:
EDIT: There are reports that some versions of netcat (nc) on the host PC need a "-p" before the port number (nc -l -p 5555). The command without the "-p" works fine on my linux host PC, so YMMV.


Last edited by geekmaster; 07-11-2012 at 05:56 PM.
geekmaster is offline   Reply With Quote