
At this Challenge there was a 27 minutes long video, the title picture is from this video, where you could watch 2 Led's flashing. The first assumption was that one of the Led's should represent the one and the other Led representing zero. Since this could take a bit longer manually, I decided to use a small Java program. The question was, how do I get to the individual frames of the video? A short web search didn't deliver anything helpful, and before spending more time searching I'd rather create a JNI wrapper for the FFMPEG library. After the access to the individual frames was made possible, the position of the LEDs and the color areas on or off were quickly determined. After the individual bits had been read in, they only had to be converted into representable characters, but the first attempt failed because only 7 bits were used instead of 8 bits per character as expected.
Translated with DeepL.com
Bei dieser Challenge gab es eine ca 27 Minuten langes Video, das Titelbild ist aus diesem Video, in dem man 2 Led's beim blinken zu schauen konnte. Die erste Vermutung war das eine der Led's die Eins und die andere Led die Null repräsentieren soll. Da das ganze manuell etwas länger dauern könnte habe ich mich hier für ein kleines Java Programm entschieden. Die Frage war nur, wie komme ich an die einzelnen Frames des Videos? Eine kurze web suche hat nichts hilfreiches geliefert, und bevor ich noch mehr Zeit mit suchen verbringe würde erstellte ich lieber einen JNI Wrapper für die FFMPEG-Library. Nach dem der zugriff auf die einzelnen Frames möglich war, war auch die Postion der LED's und die Farbbereiche die an bzw. aus repräsentierten rasch ermittelt. Nach dem die einzelnen Bits eingelesen waren mussten diese nur noch in darstellbare Zeichen umgewandelt werden, der erste versuch scheiterte aber, da nicht wie erwartet 8 Bit je Zeichen sondern nur 7 Bit verwendet wurden.
import java.awt.image.BufferedImage;
import java.io.StringWriter;
public class LEDflashing {
// check collors to determine if the led is on or off
private boolean led(int rgb, int l) {
int r = (rgb >> 16) &0xff;
int g = (rgb >> 8) &0xff;
int b = (rgb >> 0) &0xff;
if (r>0xa0 && g>0x50 && b>0x30)
return true;
return false;
}
public LEDflashing() {
JFFMPEG.initFFMPEG("LED flashing-P7yKZqAk2OY.mp4");
StringWriter sw = new StringWriter();
boolean getNext = false;
JFFMPEG.get();
try {
for (int i=1; i<50251; i++) {
if (i%500==0)
System.out.print(".");
BufferedImage frame = JFFMPEG.get();
if (frame==null)
break;
boolean led1 = led(frame.getRGB(182, 122), 0);
boolean led2 = led(frame.getRGB(208, 122), 1);
if (led1 && led2) {
throw new RuntimeException("check Frame "+i);
}
if (!led1 && !led2) {
getNext = true;
} else if (getNext) {
if (led1) {
sw.append('0');
} else {
sw.append('1');
}
getNext = false;
}
}
} catch(Exception e) {
e.printStackTrace();
}
System.out.println(sw.toString());
String bits = sw.toString();
while (bits.length()>0) {
int c = Integer.parseInt(bits.substring(0,7),2);
System.out.print((char)c);
bits = bits.substring(7);
}
JFFMPEG.exitFFMPEG();
}
public static void main(String[] args) {
new LEDflashing();
}
}
Congratulations @darkstar-42! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Energi yang terbarukan,, bisa menjadi energi alternatif
I like the programing...
Very good, please vote me master....
Apa yang anda katakan itu benar
good!!
this is so cool :) !
Good job sir i like you post
Good job
A like for the code, nicely arranged
Amazing @darkstar-42 please you vote me and follow
Interesting post, greetings :)
Good job
excellent post, thanks for sharing so valuable information, I congratulate you. I'm following you, I invite you to see my last post