Проблема с преобразованием контейнера TS в MP4 с помощью ffmpeg

У меня есть видеопоток, который я захватил VLCи сохранил как файл TS. Кодеки в файле — h.264/AAC, поэтому я подумал, что было бы тривиально использовать ffmpegдля преобразования файла из контейнера TS в контейнер MP4, чтобы я мог воспроизвести файл в QuickTime. Я использовал следующую команду:

ffmpeg -i vlc-output.ts -acodec copy -vcodec copy car-free\ tourism.mp4

Все выглядело нормально, но хотя полученный файл можно открыть в QuickTime, после воспроизведения 1 с файла он возвращается к началу, а затем воспроизводит только звук, а видео остается черным. Видео отлично воспроизводится в VLC и MPlayerX. Я не могу понять, почему QuickTime не воспроизводит файл. Кодеки выглядят совместимыми, и длина файла выглядит нормально. Я делаю что-то неправильно? Есть ли дополнительные метаданные, которые нужны QuickTime?

Я почему-то подозреваю, что проблема заключается в отсутствии полных метаданных о скорости передачи данных, но я не в курсе.

Спасибо за любую помощь.

Вывод ffprobe для обоих файлов выглядит следующим образом:

vlc-output.ts

[~/Desktop] 113: ffprobe vlc-output.ts                                                   10:51:13 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vlc-output.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    creation_time   : 2015-06-23T20:48:30.000000Z
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    encoder         : vlc 2.2.1 stream output
    encoder-eng     : vlc 2.2.1 stream output
  Duration: 00:01:50.09, start: 0.000000, bitrate: 1149 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : SoundHandler

туризм без автомобилей.mp4

[~/Desktop] 114: ffprobe car-free\ tourism.mp4                                           10:51:36 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'car-free tourism.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
  Duration: 00:01:50.09, start: 0.000000, bitrate: 1150 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

Когда я использую эту -reportопцию при запуске команды rewrap, я получаю следующий файл журнала:

ffmpeg-20170824-164217.log

ffmpeg started on 2017-08-24 at 16:42:17
Report written to "ffmpeg-20170824-164217.log"
Command line:
ffmpeg -i vlc-output.ts -acodec copy -vcodec copy -report "car-free tourism.mp4"
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'vlc-output.ts'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option 'car-free tourism.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url vlc-output.ts.
Successfully parsed a group of options.
Opening an input file: vlc-output.ts.
[NULL @ 0x7f8f8e004200] Opening 'vlc-output.ts' for reading
[file @ 0x7f8f8ce00300] Setting default whitelist 'file,crypto'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Processing st: 0, edit list 0 - media time: 0, duration: 109960000
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Processing st: 1, edit list 0 - media time: 0, duration: 4854784
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Before avformat_find_stream_info() pos: 76497 bytes read:98304 seeks:0 nb_streams:2
[h264 @ 0x7f8f8e008400] nal_unit_type: 9, nal_ref_idc: 0
[h264 @ 0x7f8f8e008400] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 0x7f8f8e008400] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 0x7f8f8e008400] nal_unit_type: 6, nal_ref_idc: 0
[h264 @ 0x7f8f8e008400] nal_unit_type: 5, nal_ref_idc: 3
[h264 @ 0x7f8f8e008400] user data:"x264 - core 118 r2085 8a62835 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=5 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=36 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=50 keyint_min=25 scenecut=0 intra_refresh=0 rc_lookahead=40 rc=cbr mbtree=1 bitrate=1200 ratetol=1.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 vbv_maxrate=1200 vbv_bufsize=600 nal_hrd=none ip_ratio=1.40 aq=1:1.00"
[h264 @ 0x7f8f8e008400] Reinit context to 640x368, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] After avformat_find_stream_info() pos: 99278 bytes read:131072 seeks:0 frames:2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vlc-output.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    creation_time   : 2015-06-23T20:48:30.000000Z
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    encoder         : vlc 2.2.1 stream output
    encoder-eng     : vlc 2.2.1 stream output
  Duration: 00:01:50.09, start: 0.000000, bitrate: 1149 kb/s
    Stream #0:0(eng), 1, 1/1000000: Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : SoundHandler
Successfully opened the file.
Parsing a group of options: output url car-free tourism.mp4.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument copy.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument copy.
Successfully parsed a group of options.
Opening an output file: car-free tourism.mp4.
[file @ 0x7f8f8ce04fe0] Setting default whitelist 'file,crypto'
Successfully opened the file.
Output #0, mp4, to 'car-free tourism.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    encoder         : Lavf57.71.100
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    Stream #0:0(eng), 0, 1/1000000: Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p, 640x360, q=2-31, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 1000k tbc (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng), 0, 1/44100: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
No more output streams to write to, finishing.
frame= 2749 fps=0.0 q=-1.0 Lsize=   15455kB time=00:01:50.04 bitrate=1150.5kbits/s speed= 588x    
video:14120kB audio:1258kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.503515%
Input file #0 (vlc-output.ts):
  Input stream #0:0 (video): 2749 packets read (14459053 bytes); 
  Input stream #0:1 (audio): 4741 packets read (1287842 bytes); 
  Total: 7490 packets (15746895 bytes) demuxed
Output file #0 (car-free tourism.mp4):
  Output stream #0:0 (video): 2749 packets muxed (14459053 bytes); 
  Output stream #0:1 (audio): 4741 packets muxed (1287842 bytes); 
  Total: 7490 packets (15746895 bytes) muxed
0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x7f8f8ce050a0] Statistics: 60 seeks, 7583 writeouts
[AVIOContext @ 0x7f8f8ce00480] Statistics: 16617055 bytes read, 17 seeks

Видеофайл, который я пытаюсь преобразовать, представляет собой поток новостей STV, указанный в файле m3u8, который я захватил с помощью VLC. Я разместил его копию здесь .

Ответы (1)

Обновление : VLC TS имеет неверный формат.

Первый забег

ffmpeg -i vlc-output.ts -c copy ffmpeg-output.ts

а потом

ffmpeg -i ffmpeg-output.ts -c copy working.mp4

Главное, что не устраивает, это временная шкала 1000k tbn.

Пытаться

ffmpeg -i vlc-output.ts -c copy -video_track_timescale 90k car-free\ tourism.mp4
Спасибо за предложение, к сожалению, оно имеет тот же результат (за исключением того, что видеопоток говорит 90k tbn:Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Затем попробуйте с меньшим числом, например, 600.
Это не повлияло на результат. Однако я также понял, что эта -reportопция создает файл журнала (раньше я этого не видел), поэтому я обновил вопрос, указав содержимое этого файла, когда вы впервые попросили меня запустить переработку с отчетом. Может быть, содержимое этого файла поможет определить, что происходит? Я очень ценю вашу помощь, спасибо.
Или другой подход: есть ли способ проанализировать файл .ts и определить, какой должна быть временная шкала?
Разрешение меняется на полпути. Попробуйте ffmpeg -ss 30 -i vlc-output.ts -c copy -video_track_timescale 600 -report car-free\ tourism.mp4. Если это сработает, попробуйте с более низкими значениями ss, пока все еще не заработает.
Еще раз спасибо за помощь. Я пробовал это, и не повезло. Тот же результат, как с начальными 0-1, так и с возвратом к началу, и видео не отображается. Я пробовал и с -ss 60and -ss 90, и получил точно такой же результат (за исключением того, что звук явно начинается с 60-х и 90-х годов, а общая длина короче). Что-нибудь еще я могу попробовать?
Поделитесь исходным файлом, если можете.
Спасибо Мульвия. Я добавил информацию и ссылку на исходный файл в конце оригинального поста ⬆️.
Извините, я только что заметил, что вы обновили этот ответ. Большое спасибо, первое копирование в новый файл TS сработало! Мне не нужно возиться с временной базой, когда я следовал вашей инструкции, чтобы скопировать в новый файл TS, а затем скопировать из него в MP4, все работает хорошо. Так хорошо, что, наконец, это заархивировано должным образом, ваша помощь очень ценится.