Mp4Dump.cpp
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:5k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - MP4 File Dumper
  4. |
  5. |    Copyright 2002 Gilles Boccon-Gibod
  6. |
  7. |
  8. |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
  9. |
  10. |    Unless you have obtained Bento4 under a difference license,
  11. |    this version of Bento4 is Bento4|GPL.
  12. |    Bento4|GPL is free software; you can redistribute it and/or modify
  13. |    it under the terms of the GNU General Public License as published by
  14. |    the Free Software Foundation; either version 2, or (at your option)
  15. |    any later version.
  16. |
  17. |    Bento4|GPL is distributed in the hope that it will be useful,
  18. |    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. |    GNU General Public License for more details.
  21. |
  22. |    You should have received a copy of the GNU General Public License
  23. |    along with Bento4|GPL; see the file COPYING.  If not, write to the
  24. |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  25. |    02111-1307, USA.
  26. |
  27.  ****************************************************************/
  28. /*----------------------------------------------------------------------
  29. |       includes
  30. +---------------------------------------------------------------------*/
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include "Ap4.h"
  34. #include "Ap4FileByteStream.h"
  35. #include "Ap4Atom.h"
  36. #include "Ap4File.h"
  37. #include "Ap4Sample.h"
  38. #include "Ap4DataBuffer.h"
  39. #include "Ap4AtomFactory.h"
  40. #include "Ap4Utils.h"
  41. /*----------------------------------------------------------------------
  42. |       constants
  43. +---------------------------------------------------------------------*/
  44. #define BANNER "MP4 File Dumper - Version 0.2an"
  45.                "(c) 2002-2005 Gilles Boccon-Gibod & Julien Boeuf"
  46.  
  47. /*----------------------------------------------------------------------
  48. |       PrintUsageAndExit
  49. +---------------------------------------------------------------------*/
  50. static void
  51. PrintUsageAndExit()
  52. {
  53.     fprintf(stderr, 
  54.             BANNER 
  55.             "nnusage: mp4dump [options] <input>n"
  56.             "options are:n"
  57.             "  -track <track_id> <data_file>: writes the track data in data_file");
  58.     exit(1);
  59. }
  60. #if 0
  61. /*----------------------------------------------------------------------
  62. |       DumpTrackData
  63. +---------------------------------------------------------------------*/
  64. void
  65. DumpTrackData(AP4_File* mp4_file, AP4_UI32 track_id, AP4_ByteStream* track_data)
  66. {
  67.     // get the track
  68.     AP4_Track* track = NULL;
  69.     AP4_Result result = mp4_file->GetTrack(track_id, track);
  70.     if (AP4_FAILED(result)) {
  71.         fprintf(stderr, "track not found (id = %d)", track_id);
  72.         return;
  73.     }
  74.     // write the data
  75.     AP4_Sample sample;
  76.     AP4_DataBuffer sample_data;
  77.     AP4_Ordinal index = 0;
  78.     while (AP4_SUCCEEDED(track->ReadSample(index, sample, sample_data))) {
  79.         track_data->Write(sample_data.GetData(), sample_data.GetDataSize());
  80.         index++;
  81.     }
  82. }
  83. #endif
  84. /*----------------------------------------------------------------------
  85. |       main
  86. +---------------------------------------------------------------------*/
  87. int
  88. main(int argc, char** argv)
  89. {
  90.     if (argc < 2) {
  91.         PrintUsageAndExit();
  92.     }
  93.     // init the variables
  94.     AP4_UI32 track_id = 0;
  95.     AP4_ByteStream* input = NULL;
  96.     AP4_ByteStream* track_data = NULL;
  97.     // parse the command line
  98.     argv++;
  99.     char* arg;
  100.     while ((arg = *argv++)) {
  101.         if (!strcmp(arg, "-track")) {
  102.             if (argv[0] && argv[1] && argv[2]) {
  103.                 track_id = atoi(argv[0]);
  104.                 if (track_id == 0) PrintUsageAndExit();
  105.                 track_data = 
  106.                     new AP4_FileByteStream(argv[1], 
  107.                                            AP4_FileByteStream::STREAM_MODE_WRITE);
  108.                 argv += 2;
  109.             } else {
  110.                 PrintUsageAndExit();
  111.             }
  112.         } else {
  113.             try {
  114.                 input = 
  115.                     new AP4_FileByteStream(arg,
  116.                     AP4_FileByteStream::STREAM_MODE_READ);
  117.             } catch(AP4_Exception e) {
  118.                 AP4_Debug("ERROR: cannot open input (%d)n", e.m_Error);
  119.                 return 1;
  120.             }
  121.         }
  122.     }
  123.     // open the output
  124.     AP4_ByteStream* output =
  125.         new AP4_FileByteStream("-stdout",
  126.                                AP4_FileByteStream::STREAM_MODE_WRITE);
  127.     
  128.     // create an inspector
  129.     AP4_PrintInspector inspector(*output);
  130.     // inspect the atoms one by one
  131.     AP4_Atom* atom;
  132.     //for (int i=0; i<1000; i++) {
  133.     AP4_AtomFactory& atom_factory = AP4_AtomFactory::DefaultFactory;
  134.     //MyTypeHandler my_type_handler;
  135.     //atom_factory.AddTypeHandler(&my_type_handler);
  136.     while (atom_factory.CreateAtomFromStream(*input, atom) == 
  137.         AP4_SUCCESS) {
  138.         atom->Inspect(inspector);
  139.         delete atom;
  140.     }
  141.     //input->Seek(0);
  142.     //}
  143.     // inspect the track data if needed
  144.     if ((track_id != 0) && (track_data != NULL)) {
  145.         //DumpTrackData(file, track_id, track_data);
  146.     }
  147.     if (input) input->Release();
  148.     if (output) output->Release();
  149.     if (track_data) track_data->Release();
  150.     return 0;
  151. }