简体   繁体   中英

Lost video when converting from MKV to MP4 with FFMPEG

I'm trying to come up with a robust script to handle all MKV -> MP4 video conversions.

The classic example I've found is ffmpeg -i input.mkv -codec copy output.mp4 . This works for most videos, but I find that the video stream gets lost for certain videos. Using -map 0 doesn't help, the examples I'm using only have one video stream and one audio stream.

If I only copy the audio codec, it seems to work fine, but takes much longer since video is re-encoded. For this I'm use ffmpeg -i input.mkv -c:a copy output.mp4 . I'm fine to use this for certain videos, but am not sure how to determine whether video re-encoding is needed or not (since I want to avoid it when possible).

Here's the output I get when I run the first command and lose video:

% ffmpeg -i input.mkv -codec copy output.mp4

ffmpeg version N-103075-g4c694093be-tessus  https://evermeet.cx/ffmpeg/  Copyright (c) 2000-2021 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.17)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
  libavutil      57.  2.100 / 57.  2.100
  libavcodec     59.  3.102 / 59.  3.102
  libavformat    59.  4.101 / 59.  4.101
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  1.103 /  8.  1.103
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100
Input #0, matroska,webm, from 'input.mkv':
  Metadata:
    CREATION_TIME   :
    ENCODER         : Lavf55.12.0
  Duration: 00:59:15.97, start: 0.062000, bitrate: 1892 kb/s
  Stream #0:0: Video: hevc (Main), yuv420p(tv, bt709), 1912x1072 [SAR 1:1 DAR 239:134], 23.98 fps, 23.98 tbr, 1k tbn (default)
  Stream #0:1(eng): Audio: aac (LC), 48000 Hz, 5.1, fltp (default)
    Metadata:
      title           : Surround
      LANGUAGE        : eng
  Stream #0:2(eng): Subtitle: ass (default)
  Stream #0:3(eng): Subtitle: ass
Output #0, mp4, to 'output.mp4':
  Metadata:
    encoder         : Lavf59.4.101
  Stream #0:0: Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, bt709), 1912x1072 [SAR 1:1 DAR 239:134], q=2-31, 23.98 fps, 23.98 tbr, 16k tbn (default)
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, 5.1, fltp (default)
    Metadata:
      title           : Surround
      LANGUAGE        : eng
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=32634 fps=0.0 q=-1.0 size=  295424kB time=00:22:41.04 bitrate=1778.1kbits/s speed=2.72e+03x frame=63776 fps=63775 q=-1.0 size=  611840kB time=00:44:19.94 bitrate=1884.3kbits/s speed=2.66e+03frame=85256 fps=62686 q=-1.0 Lsize=  822207kB time=00:59:15.83 bitrate=1894.2kbits/s speed=2.61e+03x
video:736136kB audio:83404kB subtitle:0kB other streams:0kB global headers:1kB muxing overhead: 0.325361%

Have you tried ffmpeg -i input.mkv -vcodec copy -acodec copy -scodec mov_text output.mp4 ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM