【问题标题】:Audio recorded with MediaRecorder on Chrome missing duration在 Chrome 上使用 MediaRecorder 录制的音频缺少持续时间
【发布时间】:2017-03-09 20:41:16
【问题描述】:

我正在使用 MediaRecorder 录制音频 (oga/vorbis) 文件。当我通过 Chrome 记录这些文件时,我遇到了问题:我无法在 ffmpeg 上编辑文件,当我尝试在 Firefox 上播放它们时,它说它们已损坏(尽管它们在 Chrome 上播放正常)。

在 ffmpeg 上查看他们的元数据我明白了:

Input #0, matroska,webm, from '91.oga':
  Metadata:
    encoder         : Chrome
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
[STREAM]
index=0
codec_name=opus
codec_long_name=Opus (Opus Interactive Audio Codec)
profile=unknown
codec_type=audio
codec_time_base=1/48000
codec_tag_string=[0][0][0][0]
codec_tag=0x0000
sample_fmt=fltp
sample_rate=48000
channels=1
channel_layout=mono
bits_per_sample=0
id=N/A
r_frame_rate=0/0
avg_frame_rate=0/0
time_base=1/1000
start_pts=0
start_time=0.000000
duration_ts=N/A
duration=N/A
bit_rate=N/A
max_bit_rate=N/A
bits_per_raw_sample=N/A
nb_frames=N/A
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
TAG:language=eng
[/STREAM]
[FORMAT]
filename=91.oga
nb_streams=1
nb_programs=0
format_name=matroska,webm
format_long_name=Matroska / WebM
start_time=0.000000
duration=N/A
size=7195
bit_rate=N/A
probe_score=100
TAG:encoder=Chrome

如您所见,持续时间存在问题。我看过这样的帖子: How can I add predefined length to audio recorded from MediaRecorder in Chrome?

但即使尝试这样做,我在尝试剪切和合并文件时也会出错。例如在运行时:

ffmpeg -f concat  -i 89_inputs.txt -c copy final.oga

我得到了很多:

[oga @ 00000000006789c0] Non-monotonous DTS in output stream 0:0; previous: 57612, current: 1980; changing to 57613. This may result in incorrect timestamps in the output file.
[oga @ 00000000006789c0] Non-monotonous DTS in output stream 0:0; previous: 57613, current: 2041; changing to 57614. This may result in incorrect timestamps in the output file.
DTS -442721849179034176, next:42521 st:0 invalid dropping
PTS -442721849179034176, next:42521 invalid dropping st:0
[oga @ 00000000006789c0] Non-monotonous DTS in output stream 0:0; previous: 57614, current: 2041; changing to 57615. This may result in incorrect timestamps in the output file.
[oga @ 00000000006789c0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
DTS -442721849179031296, next:42521 st:0 invalid dropping
PTS -442721849179031296, next:42521 invalid dropping st:0

有谁知道我们需要对从 Chrome 录制的音频文件做些什么才能使它们有用吗?还是我的设置有问题?

录音机js:

if (navigator.getUserMedia) {
  console.log('getUserMedia supported.');

  var constraints = { audio: true };
  var chunks = [];

  var onSuccess = function(stream) {
    var mediaRecorder = new MediaRecorder(stream);

    record.onclick = function() {
      mediaRecorder.start();
      console.log(mediaRecorder.state);
      console.log("recorder started");
      record.style.background = "red";

      stop.disabled = false;
      record.disabled = true;

      var aud = document.getElementById("audioClip");
      start = aud.currentTime;
    }

    stop.onclick = function() {
      console.log(mediaRecorder.state);
      console.log("Recording request sent.");
      mediaRecorder.stop();
    }

    mediaRecorder.onstop = function(e) {
      console.log("data available after MediaRecorder.stop() called.");

      var audio = document.createElement('audio');
      audio.setAttribute('controls', '');
      audio.setAttribute('id', 'audioClip');

      audio.controls = true;
      var blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs="vorbis"' });
      chunks = [];
      var audioURL = window.URL.createObjectURL(blob);
      audio.src = audioURL;

      sendRecToPost(blob);   // this just send the audio blob to the server by post
      console.log("recorder stopped");

    }

【问题讨论】:

标签: google-chrome ffmpeg mediarecorder oggvorbis


【解决方案1】:

我在ffmpeg documentation 发现我们可以使用此选项在转换时设置元数据:

//-metadata[:metadata_specifier] key=value (output,per-metadata)
//Set a metadata key/value pair.

ffmpeg -i in.avi -metadata title="my title" out.flv

您还可以测试持续时间转换限制是否适用于您的案例:

//-t duration (input/output)
//When used as an input option (before -i), limit the duration of data read from the input file.

//When used as an output option (before an output url), stop writing the output after its duration reaches duration.

【讨论】:

    猜你喜欢
    • 2021-11-28
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多