Audio aus mp4 extrahieren

  • VB.NET
  • .NET (FX) 4.0

Es gibt 8 Antworten in diesem Thema. Der letzte Beitrag () ist von Manawyrm.

    Lese die Spezifikation und schreibe auf dieser Basis ein Programm, das die Tracks der MP4-Datei extrahieren kann.
    Ich habe selbst einen Demuxer für den MP4 Container zu Übungszwecken geschrieben, es ist aufwändig. Wenn du dir diesen Aufwand ersparen willst, dann musst du eben auf eine vorgefertigte Lösung zurückgreifen. Da das Framework hier meines Wissens nach nichts bereitstellt, musst du wohl auf andere Bibliotheken wie ffmpeg, mp4Box, libmp4, ... zurückgreifen.
    @markus.obi : Ich möchte nicht für jede konversion ein neues programm starten. Ausserdem möchte ich ggf rückmeldungen(erfolgreich,arbeitet,25%,fehlgeschlagen) und das habe ich bei ffmpeg nicht, was ich so gesehen hab ;).
    @Infinity : Jo, ich möcht ja nicht gleich was eigenes, ne dll genügt(danke dafür) :)
    Thx
    Wer Rechtschreibfehler findet darf sie behalten :)
    Den hast du sehr wohl bei ffmpeg ;) du musst ihn nur richtig Interpretieren und natürlich zur dir bzw. deiner Anwendung umleiten (ProcessStartInfo.RedirectStandardOutput & ProcessStartInfo.RedirectStandardError)
    @slice : Jaaa, ok sagen wir mal so: ich bin ein wenig alergisch auf externe consolenanwendungen wo ich mir etwas hilflos vorkomme(ich hoffe du weist was ich meine),ich mein jeder kann mitlesen und so, ausserdem möchte ich das dann unter mono auf nem server laufen lassen und möchte nicht allzu viele fehler bekommen(du weist ja- je weniger fehler desto besser :D). Ausserdem liebe ich dll´s :D
    mfg
    Wer Rechtschreibfehler findet darf sie behalten :)
    Externe Konsolenanwendungs zu starten ist wesentlich einfach als sich in die API von ffmpeg/avconv oder einer ähnlichen Bibliothek einzulesen und sollte auch unter Mono keine Probleme bereiten (wobei ich wenn eine Linuxdistribution die Zielplattform sein sollte eher zu einer andern Programmiersprache als VB.Net raten würde). Hier trotzdem der Link zur Dokumentation von ffmpeg: ffmpeg.org/doxygen/2.1/index.html
    Natürlich gibt es noch weitere Bibliotheken die du nutzen könntest. Nur um der eventuellen nächsten Frage vorzubeugen: Wie du Funktionen aus Programmbiliotheken die mit C geschrieben wurden in VB.Net verwenden kannst wurde hier im Forum glaube ich bereits ganz gut beschrieben (Suche benutzen).

    Ausserdem liebe ich dll´s

    Unter unixartigen Systemen werden keine "DLLs" verwendet, deswegen solltest du lieber allgemein von Programmbiblotheken reden.
    Jo, ma gucken xD
    Hat wer ne ahnung wie ich das unter vb zum laufen bekomm:avblocks.com/download-try/ ?
    Ich hab das schon convertet, so gut´s ging, aber nun hats probleme mit " t.OnContinue ", das gibts nähmlich nicht....irgendwie...
    Das originale:
    Spoiler anzeigen

    Quellcode

    1. /*
    2. * Copyright (c) 2013 Primo Software. All Rights Reserved.
    3. *
    4. * Use of this source code is governed by a BSD-style license
    5. * that can be found in the LICENSE file in the root of the source
    6. * tree.
    7. */
    8. using System;
    9. using System.Collections.Generic;
    10. using System.Text;
    11. using PrimoSoftware.AVBlocks;
    12. namespace VideoConverter
    13. {
    14. class PresetDescriptor
    15. {
    16. public Preset Id;
    17. public string Name;
    18. public bool AudioOnly;
    19. public string FileExtension;
    20. public PresetDescriptor(Preset id, string name, bool audioOnly, string fileExtension)
    21. {
    22. this.Id = id;
    23. this.Name = name;
    24. this.AudioOnly = audioOnly;
    25. this.FileExtension = fileExtension;
    26. }
    27. public override string ToString()
    28. {
    29. if (this.FileExtension == null)
    30. return this.Name;
    31. return string.Format("{0} (.{1})", this.Name, this.FileExtension);
    32. }
    33. };
    34. class AvbTranscoder
    35. {
    36. private static PresetDescriptor[] presets = new PresetDescriptor[]
    37. {
    38. // video presets
    39. new PresetDescriptor(Preset.DVD_PAL_MP2, "DVD PAL 4:3, MP2", false, "mpg"),
    40. new PresetDescriptor(Preset.DVD_PAL_WIDE_MP2, "DVD PAL 16:9, MP2", false, "mpg"),
    41. new PresetDescriptor(Preset.DVD_NTSC_PCM, "DVD NTSC 4:3, PCM", false, "mpg"),
    42. new PresetDescriptor(Preset.DVD_NTSC_MP2, "DVD NTSC 4:3, MP2", false, "mpg" ),
    43. new PresetDescriptor(Preset.DVD_NTSC_WIDE_PCM, "DVD NTSC 16:9, PCM", false, "mpg" ),
    44. new PresetDescriptor(Preset.DVD_NTSC_WIDE_MP2, "DVD NTSC 16:9, MP2", false, "mpg"),
    45. new PresetDescriptor(Preset.AppleTv_H264, "Apple TV H.264", false, "mp4"),
    46. new PresetDescriptor(Preset.AppleTv_MPEG4, "Apple TV MPEG-4", false, "mp4"),
    47. new PresetDescriptor(Preset.Apple_LiveStreaming,"Apple Live Streaming",false, "ts"),
    48. new PresetDescriptor(Preset.MP4_H264, "MP4 H.264", false, "mp4"),
    49. new PresetDescriptor(Preset.iPad_H264, "iPad H.264", false, "mp4"),
    50. new PresetDescriptor(Preset.iPad_H264_HD, "iPad H.264 HD", false, "mp4"),
    51. new PresetDescriptor(Preset.iPad_MPEG4, "iPad MPEG-4", false, "mp4"),
    52. new PresetDescriptor(Preset.iPhone_H264, "iPhone, iPod Touch H.264", false, "mp4"),
    53. new PresetDescriptor(Preset.iPhone_MPEG4, "iPhone, iPod Touch MPEG-4", false, "mp4"),
    54. new PresetDescriptor(Preset.iPod_H264, "iPod Classic H.264", false, "mp4"),
    55. new PresetDescriptor(Preset.iPod_MPEG4, "iPod Classic MPEG-4", false, "mp4"),
    56. new PresetDescriptor(Preset.MPEG1, "MPEG-1", false, "mpg"),
    57. new PresetDescriptor(Preset.WebM, "WebM", false, "webm"),
    58. // audio presets
    59. new PresetDescriptor(Preset.AudioCD, "Audio CD Wav", true, "wav"),
    60. new PresetDescriptor(Preset.AAC, "AAC ADTS", true, "aac"),
    61. new PresetDescriptor(Preset.M4A, "AAC M4A", true, "m4a"),
    62. new PresetDescriptor(Preset.MP2_DVD, "MPEG Audio for DVD", true, "mp2"),
    63. new PresetDescriptor(Preset.MP3, "MP3", true, "mp3"),
    64. new PresetDescriptor(Preset.WMA_Standard, "WMA Standard", true, "wma"),
    65. new PresetDescriptor(Preset.WMA_Professional, "WMA Professional", true, "wma"),
    66. new PresetDescriptor(Preset.WMA_Lossless, "WMA Lossless", true, "wma"),
    67. new PresetDescriptor(Preset.OggVorbis, "Ogg (Vorbis)", true, "ogg"),
    68. };
    69. public static PresetDescriptor[] Presets
    70. {
    71. get { return presets; }
    72. }
    73. private static string FormatErrorMessage(ErrorInfo e)
    74. {
    75. return string.Format("{0} Error, Code: {1} ({2})", e.Facility, e.Code, e.Message ?? "");
    76. }
    77. // return error message or null if success
    78. public static string ConvertFileWithPreset(string inputFile, string outputFile, Preset outputPreset,
    79. EventHandler<TranscoderContinueEventArgs> onContinue,
    80. EventHandler<TranscoderProgressEventArgs> onProgress,
    81. EventHandler<TranscoderStatusEventArgs> onStatus
    82. )
    83. {
    84. MediaInfo mediaInfo = new MediaInfo();
    85. mediaInfo.InputFile = inputFile;
    86. if (!mediaInfo.Load())
    87. {
    88. return FormatErrorMessage(mediaInfo.Error);
    89. }
    90. using (Transcoder t = new Transcoder())
    91. {
    92. if (onContinue != null)
    93. t.OnContinue += onContinue;
    94. if (onProgress != null)
    95. t.OnProgress += onProgress;
    96. if (onStatus != null)
    97. t.OnStatus += onStatus;
    98. MediaSocket insocket = MediaSocket.FromMediaInfo(mediaInfo);
    99. t.Inputs.Add(insocket);
    100. MediaSocket outsocket = MediaSocket.FromPreset(outputPreset, Quality.Normal);
    101. if (outsocket == null)
    102. {
    103. return "Cannot create output preset";
    104. }
    105. outsocket.File = outputFile;
    106. t.Outputs.Add(outsocket);
    107. if (!t.Open())
    108. return FormatErrorMessage(mediaInfo.Error);
    109. if (!t.Run())
    110. return FormatErrorMessage(mediaInfo.Error);
    111. t.Close();
    112. }
    113. return null; // no error
    114. }
    115. }
    116. }

    das convertierte:
    Spoiler anzeigen

    Quellcode

    1. Imports System.Collections.Generic
    2. Imports System.Text
    3. Imports PrimoSoftware.AVBlocks
    4. Imports PrimoSoftware
    5. Namespace VideoConverter
    6. Class PresetDescriptor
    7. Public Id As Preset
    8. Public Name As String
    9. Public AudioOnly As Boolean
    10. Public FileExtension As String
    11. Public Sub New(ByVal id As Preset, ByVal name As String, ByVal audioOnly As Boolean, ByVal fileExtension As String)
    12. Me.Id = id
    13. Me.Name = name
    14. Me.AudioOnly = audioOnly
    15. Me.FileExtension = fileExtension
    16. End Sub
    17. Public Overrides Function ToString() As String
    18. If Me.FileExtension Is Nothing Then
    19. Return Me.Name
    20. End If
    21. Return String.Format("{0} (.{1})", Me.Name, Me.FileExtension)
    22. End Function
    23. End Class
    24. Class AvbTranscoder
    25. ' video presets
    26. ' audio presets
    27. Private Shared m_presets As PresetDescriptor() = New PresetDescriptor() {New PresetDescriptor(Preset.DVD_PAL_MP2, "DVD PAL 4:3, MP2", False, "mpg"), New PresetDescriptor(Preset.DVD_PAL_WIDE_MP2, "DVD PAL 16:9, MP2", False, "mpg"), New PresetDescriptor(Preset.DVD_NTSC_PCM, "DVD NTSC 4:3, PCM", False, "mpg"), New PresetDescriptor(Preset.DVD_NTSC_MP2, "DVD NTSC 4:3, MP2", False, "mpg"), New PresetDescriptor(Preset.DVD_NTSC_WIDE_PCM, "DVD NTSC 16:9, PCM", False, "mpg"), New PresetDescriptor(Preset.DVD_NTSC_WIDE_MP2, "DVD NTSC 16:9, MP2", False, "mpg"), _
    28. New PresetDescriptor(Preset.AppleTv_H264, "Apple TV H.264", False, "mp4"), New PresetDescriptor(Preset.AppleTv_MPEG4, "Apple TV MPEG-4", False, "mp4"), New PresetDescriptor(Preset.Apple_LiveStreaming, "Apple Live Streaming", False, "ts"), New PresetDescriptor(Preset.MP4_H264, "MP4 H.264", False, "mp4"), New PresetDescriptor(Preset.iPad_H264, "iPad H.264", False, "mp4"), New PresetDescriptor(Preset.iPad_H264_HD, "iPad H.264 HD", False, "mp4"), _
    29. New PresetDescriptor(Preset.iPad_MPEG4, "iPad MPEG-4", False, "mp4"), New PresetDescriptor(Preset.iPhone_H264, "iPhone, iPod Touch H.264", False, "mp4"), New PresetDescriptor(Preset.iPhone_MPEG4, "iPhone, iPod Touch MPEG-4", False, "mp4"), New PresetDescriptor(Preset.iPod_H264, "iPod Classic H.264", False, "mp4"), New PresetDescriptor(Preset.iPod_MPEG4, "iPod Classic MPEG-4", False, "mp4"), New PresetDescriptor(Preset.MPEG1, "MPEG-1", False, "mpg"), _
    30. New PresetDescriptor(Preset.WebM, "WebM", False, "webm"), New PresetDescriptor(Preset.AudioCD, "Audio CD Wav", True, "wav"), New PresetDescriptor(Preset.AAC, "AAC ADTS", True, "aac"), New PresetDescriptor(Preset.M4A, "AAC M4A", True, "m4a"), New PresetDescriptor(Preset.MP2_DVD, "MPEG Audio for DVD", True, "mp2"), New PresetDescriptor(Preset.MP3, "MP3", True, "mp3"), _
    31. New PresetDescriptor(Preset.WMA_Standard, "WMA Standard", True, "wma"), New PresetDescriptor(Preset.WMA_Professional, "WMA Professional", True, "wma"), New PresetDescriptor(Preset.WMA_Lossless, "WMA Lossless", True, "wma"), New PresetDescriptor(Preset.OggVorbis, "Ogg (Vorbis)", True, "ogg")}
    32. Public Shared ReadOnly Property Presets() As PresetDescriptor()
    33. Get
    34. Return m_presets
    35. End Get
    36. End Property
    37. Private Shared Function FormatErrorMessage(ByVal e As ErrorInfo) As String
    38. Return String.Format("{0} Error, Code: {1} ({2})", e.Facility, e.Code, If(e.Message, ""))
    39. End Function
    40. ' return error message or null if success
    41. Public Shared Function ConvertFileWithPreset(ByVal inputFile As String, ByVal outputFile As String, ByVal outputPreset As Preset, ByVal onContinue As EventHandler(Of TranscoderContinueEventArgs), ByVal onProgress As EventHandler(Of TranscoderProgressEventArgs), ByVal onStatus As EventHandler(Of TranscoderStatusEventArgs)) As String
    42. Dim mediaInfo As New MediaInfo()
    43. mediaInfo.InputFile = inputFile
    44. If Not mediaInfo.Load() Then
    45. Return FormatErrorMessage(mediaInfo.[Error])
    46. End If
    47. Using t As New PrimoSoftware.AVBlocks.Transcoder()
    48. If onContinue IsNot Nothing Then
    49. t.OnContinue += onContinue
    50. End If
    51. If onProgress IsNot Nothing Then
    52. t.OnProgress += onProgress
    53. End If
    54. If onStatus IsNot Nothing Then
    55. t.OnStatus += onStatus
    56. End If
    57. Dim insocket As MediaSocket = MediaSocket.FromMediaInfo(mediaInfo)
    58. t.Inputs.Add(insocket)
    59. Dim outsocket As MediaSocket = MediaSocket.FromPreset(outputPreset, Quality.Normal)
    60. If outsocket Is Nothing Then
    61. Return "Cannot create output preset"
    62. End If
    63. outsocket.File = outputFile
    64. t.Outputs.Add(outsocket)
    65. If Not t.Open() Then
    66. Return FormatErrorMessage(mediaInfo.[Error])
    67. End If
    68. If Not t.Run() Then
    69. Return FormatErrorMessage(mediaInfo.[Error])
    70. End If
    71. t.Close()
    72. End Using
    73. Return Nothing
    74. ' no error
    75. End Function
    76. End Class
    77. End Namespace

    Wer Rechtschreibfehler findet darf sie behalten :)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „joniator“ ()