TooTallNate / node-amf

"Action Message Format" read() and write() functions for Buffers
21 stars 6 forks source link

Can't JSON.stringify() objects returned by read() #3

Closed deoxxa closed 11 years ago

deoxxa commented 11 years ago
var amf = require("amf");

var data = Buffer("080000001c000c6861734b65796672616d657301010009637565506f696e74730a00000000000d617564696f646174617261746500405012eb7a81c30e0008686173566964656f0101000673746572656f0101000c63616e5365656b546f456e64010000096672616d6572617465004039000000000000000f617564696f73616d706c65726174650040d57c0000000000000c766964656f636f646563696400401000000000000000086461746173697a650041710de410000000000d6c61737474696d657374616d70004073c28f5c28f5c3000f617564696f73616d706c6573697a650040300000000000000009617564696f73697a6500414466cd000000000008686173417564696f0101000a617564696f64656c61790000000000000000000009766964656f73697a6500416d0127e0000000000c6d65746164617461646174650b42732ca55ad50b500078000f6d6574616461746163726561746f72020040696e6c6574206d6564696120464c56546f6f6c322076312e302e36202d20687474703a2f2f7777772e696e6c65742d6d656469612e64652f666c76746f6f6c3200156c6173746b65796672616d6574696d657374616d7000407380a3d70a3d710006686569676874004078c00000000000000866696c6573697a65004171216ea0000000000b6861734d65746164617461010100096b65796672616d657303000574696d65730a000000420000000000000000000040135c28f5c28f5c00402347ae147ae14800402ce147ae147ae10040333d70a3d70a3d0040380a3d70a3d70a00403cd70a3d70a3d7004040d1eb851eb8520040433851eb851eb80040459eb851eb851f004048051eb851eb8500404a6b851eb851ec00404cd1eb851eb85200404f3851eb851eb8004050cf5c28f5c28f004052028f5c28f5c300405335c28f5c28f600405468f5c28f5c290040559c28f5c28f5c004056cf5c28f5c28f004058028f5c28f5c300405935c28f5c28f600405a68f5c28f5c2900405b9c28f5c28f5c00405ccf5c28f5c28f00405e028f5c28f5c300405f35c28f5c28f6004060347ae147ae14004060ce147ae147ae00406167ae147ae1480040620147ae147ae10040629ae147ae147b004063347ae147ae14004063ce147ae147ae00406467ae147ae1480040650147ae147ae10040659ae147ae147b004066347ae147ae14004066ce147ae147ae00406767ae147ae1480040680147ae147ae10040689ae147ae147b004069347ae147ae14004069ce147ae147ae00406a67ae147ae14800406b0147ae147ae100406b9ae147ae147b00406c347ae147ae1400406cce147ae147ae00406d67ae147ae14800406e0147ae147ae100406e9ae147ae147b00406f347ae147ae1400406fce147ae147ae00407033d70a3d70a400407080a3d70a3d71004070cd70a3d70a3d0040711a3d70a3d70a004071670a3d70a3d7004071b3d70a3d70a400407200a3d70a3d710040724d70a3d70a3d0040729a3d70a3d70a004072e70a3d70a3d700407333d70a3d70a400407380a3d70a3d71000d66696c65706f736974696f6e730a000000420040a06e000000000000411157b80000000000411fcc9000000000004126b6140000000000412f44aa00000000004133fe6f000000000041385de50000000000413cb5610000000000414080bf80000000004142b29980000000004144bfa500000000004146c36080000000004148f1c68000000000414b2ed48000000000414d3c200000000000414f376a80000000004150a9c0c0000000004151bf4140000000004152d3fc00000000004153de5280000000004154edce800000000041560cee400000000041573618c000000000415883a30000000000415998670000000000415ad63b4000000000415bafbfc000000000415c97944000000000415da30a4000000000415ea5198000000000415fa89f4000000000416059fec0000000004160e1fc00000000004161634480000000004161de1180000000004162651760000000004162eab460000000004163711aa0000000004163f420c000000000416466e620000000004164ed00800000000041657509a0000000004165f899200000000041667f0dc000000000416705e6200000000041678af1000000000041680600800000000041688808400000000041690d2620000000004169875c0000000000416a0195a000000000416a89116000000000416b0ffc0000000000416b95062000000000416c1bd64000000000416ca30f0000000000416d2bc22000000000416db0e58000000000416e37740000000000416ebd228000000000416f455e6000000000416fcb43600000000041702b0f400000000041706ee230000000004170b0ced0000000004170fc3610000000000009000c617564696f636f6465636964004000000000000000000d766964656f6461746172617465004077e95dcc2d9a6e00086475726174696f6e004073c33333333334000c686173437565506f696e7473010000057769647468004080800000000000000009", "hex");
var parsed = amf.read(data);

console.log(parsed);
console.log(JSON.stringify(parsed));
[ hasKeyframes: true,
  cuePoints: [],
  audiodatarate: 64.29562246963562,
  hasVideo: true,
  stereo: true,
  canSeekToEnd: false,
  framerate: 25,
  audiosamplerate: 22000,
  videocodecid: 4,
  datasize: 17882689,
  lasttimestamp: 316.16,
  audiosamplesize: 16,
  audiosize: 2674074,
  hasAudio: true,
  audiodelay: 0,
  videosize: 15206719,
  metadatadate: Tue Oct 04 2011 02:10:05 GMT+1100 (EST),
  metadatacreator: 'inlet media FLVTool2 v1.0.6 - http://www.inlet-media.de/flvtool2',
  lastkeyframetimestamp: 312.04,
  height: 396,
  filesize: 17962730,
  hasMetadata: true,
  keyframes: { times:
     [ 0,
       4.84,
       9.64,
       14.44,
       19.24,
       24.04,
       28.84,
       33.64,
       38.44,
       43.24,
       48.04,
       52.84,
       57.64,
       62.44,
       67.24,
       72.04,
       76.84,
       81.64,
       86.44,
       91.24,
       96.04,
       100.84,
       105.64,
       110.44,
       115.24,
       120.04,
       124.84,
       129.64,
       134.44,
       139.24,
       144.04,
       148.84,
       153.64,
       158.44,
       163.24,
       168.04,
       172.84,
       177.64,
       182.44,
       187.24,
       192.04,
       196.84,
       201.64,
       206.44,
       211.24,
       216.04,
       220.84,
       225.64,
       230.44,
       235.24,
       240.04,
       244.84,
       249.64,
       254.44,
       259.24,
       264.04,
       268.84,
       273.64,
       278.44,
       283.24,
       288.04,
       292.84,
       297.64,
       302.44,
       307.24,
       312.04 ],
    filepositions:
     [ 2103,
       284142,
       520996,
       744202,
       1024597,
       1310319,
       1596901,
       1881441,
       2163071,
       2450739,
       2719562,
       2983617,
       3269517,
       3562921,
       3831872,
       4091605,
       4368131,
       4652293,
       4935664,
       5208394,
       5486394,
       5780409,
       6084707,
       6426252,
       6709660,
       7035117,
       7257855,
       7495249,
       7769129,
       8033382,
       8299133,
       8572918,
       8851424,
       9116196,
       9367692,
       9644219,
       9917859,
       10193109,
       10461446,
       10696497,
       10971140,
       11249741,
       11519177,
       11794542,
       12070705,
       12343176,
       12595204,
       12861506,
       13134129,
       13384416,
       13634733,
       13912203,
       14188512,
       14460977,
       14737074,
       15014008,
       15293969,
       15566636,
       15842208,
       16115988,
       16394995,
       16669211,
       16953588,
       17231395,
       17501421,
       17810273 ] },
  audiocodecid: 2,
  videodatarate: 382.58539979757086,
  duration: 316.20000000000005,
  hasCuePoints: false,
  width: 528 ]
[]
TooTallNate commented 11 years ago

Basically the problem is that ECMAScript allows "named properties" on Array instances, however the JSON standard does not (it only allows indexed entries)...

FLV for some reason likes to encode their metadata into an Array instance with properties on it, where it would be more appropriate to use an Object here. It's kinda lame.

Unfortunately this is a language level thing and there's not much that node-amf can do about it (we're at the mercy of JSON.stringify()). I'd suggest trying to catch, and convert it to an Object in your code before calling JSON.stringify(). Cheers!

deoxxa commented 11 years ago

ActionScript, you crazy. Thanks for the clarification.