FLV-Datei-Parser

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • FLV-Datei-Parser

    Hallo zusammen,

    ich versuch jetzt schon seit mehrern Tagen an den Audio-Stream einer FLV-Datei zu kommen. Die Orange markierte Stelle ist die DataSize des FileBodyTags der Tag sollte also 843 Bytes lang sein, was nach meinem HexEditor so auch stimmt. Ich habe nur leider das Problem, dass in meinem Java Pogramm ganze 33 Bytes fehlen.

    Quellcode

    1. private void parseFile() throws JavourFLaVeException {
    2. try {
    3. LOG.debug("parsing " + file.getAbsolutePath());
    4. InputStream istream = new FileInputStream(file);
    5. byte[] header = new byte[9];
    6. istream.read(header);
    7. /* check for flv start*/
    8. if (header[0] != 70 || header[1] != 76 || header[2] != 86) {
    9. throw new JavourFLaVeException("Signature is missing!" +
    10. " File have to start with FLV.");
    11. }
    12. /* assign version */
    13. version = header[3];
    14. /* check TypeFlagsReserved first five bits */
    15. if ((header[4] & 0xF8) != 0) {
    16. throw new JavourFLaVeException("First five " +
    17. "TypeFlagsReserved is not 0.");
    18. }
    19. /* check TypeFlagsReserved bit after TypeFlagsAudio */
    20. if ((header[4] & 0x2) != 0) {
    21. throw new JavourFLaVeException("TypeFlagsReserved Bit after " +
    22. "TypeFlagsAudio is not 0.");
    23. }
    24. /* assign audioTagsPresent */
    25. audioTagsPresent =
    26. ((header[4] & 0x4) >> 2) == 1;
    27. LOG.debug("audioTagsPresent: " + audioTagsPresent);
    28. /* assign videoTagsPresent */
    29. videoTagsPresent =
    30. ((header[4] & 0x1)) == 1;
    31. LOG.debug("videoTagsPresent: " + videoTagsPresent);
    32. /* dataOffset*/
    33. if (header[8] != 9) {
    34. throw new JavourFLaVeException("Header seems not to be an " +
    35. "FLV version 1 header. Excepting 9 was " + header[8]);
    36. }
    37. boolean eof = false;
    38. while (!eof) {
    39. /* parsing the flv body */
    40. int previousTagSize = BitByteHelper.read32BitUnsignedInt(istream);
    41. int tagType = istream.read();
    42. int dataSize = BitByteHelper.read24BitUnsignedInt(istream);
    43. int timestamp = BitByteHelper.read24BitUnsignedInt(istream);
    44. int timestampExtended = istream.read();
    45. int streamId = BitByteHelper.read24BitUnsignedInt(istream);
    46. LOG.debug("Found FLV-TAG:");
    47. LOG.debug("\ttagType: " + tagType);
    48. LOG.debug("\tdataSize: " + dataSize);
    49. LOG.debug("\ttimestamp: " + timestamp);
    50. LOG.debug("\ttimestampExtended: " + timestampExtended);
    51. LOG.debug("\tstreamId: " + streamId);
    52. switch (tagType) {
    53. /* audio */
    54. case 8:
    55. audioOffset[0] = 0;
    56. audioOffset[1] = audioOffset[0] + dataSize;
    57. break;
    58. /* video */
    59. case 9:
    60. videoOffset[0] = 0;
    61. videoOffset[1] = videoOffset[0] + dataSize;
    62. break;
    63. case 18:
    64. break;
    65. /* others */
    66. default:
    67. break;
    68. }
    69. long skipped = istream.skip(dataSize);
    70. }
    71. } catch (FileNotFoundException ex) {
    72. throw new JavourFLaVeException(ex);
    73. } catch (IOException ex) {
    74. throw new JavourFLaVeException(ex);
    75. }
    76. }
    Alles anzeigen


    Quellcode

    1. public static int read24BitUnsignedInt(InputStream istream) throws IOException {
    2. return readAmountOfBytes(3, istream);
    3. }
    4. public static int read32BitUnsignedInt(InputStream istream) throws IOException {
    5. return readAmountOfBytes(4, istream);
    6. }
    7. public static int readAmountOfBytes(int bytes, InputStream istream)
    8. throws IOException {
    9. byte[] buffer = new byte[bytes];
    10. istream.read(buffer);
    11. int out = 0;
    12. for (int i = 0; i < bytes; i++) {
    13. out += ((int)buffer[i]) << ((bytes - i -1) * 8);
    14. }
    15. return out;
    16. }
    Alles anzeigen


    Mit dem Code komme ich aber leider nur zum Anfang der blaumarkierten Stelle. Mir fehlen also aus mir nicht ersichtlichen Gründen 33 Bytes. Mach ich irgendeinen Denk- oder Umrechnungsfehler? Hier nochma die FLV specs: adobe.com/devnet/flv/pdf/video_file_format_spec_v10.pdf
    Bilder
    • HEX.png

      52,15 kB, 1.094×523, 407 mal angesehen