Can't write packet with unknown timestamp av_interleaved_write_frame(): Invalid argument
Asked Answered
S

3

15

I'm trying to convert a .ts file with this output to mkv:

ffmpeg version 4.3.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 12.0.0 (clang-1200.0.32.27)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3.1_4 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[mp3float @ 0x7fbd6282b200] Header missing
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 2, dts = 7125804577).
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 2, dts = 7125804577).
[mpegts @ 0x7fbd62809000] PES packet size mismatch
[mpegts @ 0x7fbd62809000] Packet corrupt (stream = 1, dts = 7125790091).
Input #0, mpegts, from '/Users/"User"/Downloads/input.ts':
  Duration: 02:11:32.82, start: 71283.837456, bitrate: 17149 kb/s
  Program 1 
    Stream #0:0[0x1004]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuvj420p(pc, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 2.08 tbr, 90k tbn, 100 tbc
    Stream #0:1[0x1104](swe): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 256 kb/s
    Stream #0:2[0x704](swe): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 640 kb/s

To do that I'm using this command:

ffmpeg -i input.ts -c copy output.mkv

But the conversion fails with this error:

Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:2 -> #0:1 (copy)
Press [q] to stop, [?] for help
[matroska @ 0x7fb8c1808200] 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
[matroska @ 0x7fb8c1808200] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument
[matroska @ 0x7fb8c1808200] Can't write packet with unknown timestamp
Error writing trailer of output.mkv: Invalid argument
frame=   27 fps=0.0 q=-1.0 Lsize=      74kB time=00:00:00.85 bitrate= 705.5kbits/s speed=  99x    
video:1092kB audio:35kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

What should I do in order to fix this? I've already tried to add -fflags +genpts in the beginning but it fails anyway.

EDIT: I did solve it by using MKVToolNix instead.

Spiller answered 2/2, 2021 at 16:15 Comment(0)
M
5

Try to run with the -ss flag.

ffmpeg -ss 0:01 -i input.ts -c copy output.mkv
Mammillary answered 2/5, 2021 at 8:14 Comment(6)
Thank you for your answer! I did already solve it however using MKVToolNix.Spiller
@Spiller How exactly did you solve it? the -ss argument only gets rid of one of the timestamp errors for meKenogenesis
@HorațiuMlendea I used MKVToolNiz instead of ffmpeg.Spiller
Ok I am still not sure how exactly you used mkvtoolnix, but I managed to work around the issue since then. I used ffmpeg -i [inputfile] [oututfile] without -c or other ways of mapping streams. It ended performing a transcode on both the video and the audio streams, I'm not sure why, but for me in that particular scenario that was good enoughKenogenesis
Works for me. What exactly is the -ss 0:01 argument doing?Factoring
@Factoring here the arguments -ss 0:01 should cut the first second of the input video.Frizz
F
30

For anyone else having this issue, I had a similar problem that was solved by adding -fflags +genpts before the input and have it generate the missing timestamps for me.

ffmpeg -fflags +genpts -i input.ts -c copy output.mkv

Edit:

Another solution might be to take it to mp4 instead of mkv (possibly using it as a middleman and then take to mkv.)

Extreme cases:

I have run into a scenario that required basically the "nuclear" option of taking the video to a raw stream file with its set frame rate, then pulling it back into a mp4 container with the audio.

First find the frame rate it should be

ffprobe -v quiet -loglevel panic -show_entries stream=avg_frame_rate -print_format flat -select_streams v <my_video>

It will output something like streams.stream.0.avg_frame_rate="60000/1001" and we care about what is in the quotes, 60000/1001

Convert the stream to a raw format of itself at that set frame rate. For example H264 would go into a .h264 container.

ffmpeg -fflags +genpts -ignore_editlist 1 -r 60000/1001 -i <my_video> -c:v copy -map 0:v -r 60000/1001 temp.h264

Then bring that raw track back in from the temp file -map 0:v -c:v copy and mux the audio -map 1:a -c:a copy and any subtitles -map 1:s -c:s copy from the original.

ffmpeg -fflags +genpts -r 60000/1001 -i temp.h264 -i <my_video> -c:v copy -map 0:v -map 1:a -map 1:s -c:a copy -c:s copy fixed_video.mp4
Forebear answered 15/9, 2021 at 19:47 Comment(3)
That did not work for my file but it might work for others though.Spiller
Thank-you worked for me but (as above) had to pick a container that supported eac3 explicitly aka .mkv.Bukovina
This helped me get past an error trying to concatenate ogg/vorbis video filesHaywoodhayyim
M
5

Try to run with the -ss flag.

ffmpeg -ss 0:01 -i input.ts -c copy output.mkv
Mammillary answered 2/5, 2021 at 8:14 Comment(6)
Thank you for your answer! I did already solve it however using MKVToolNix.Spiller
@Spiller How exactly did you solve it? the -ss argument only gets rid of one of the timestamp errors for meKenogenesis
@HorațiuMlendea I used MKVToolNiz instead of ffmpeg.Spiller
Ok I am still not sure how exactly you used mkvtoolnix, but I managed to work around the issue since then. I used ffmpeg -i [inputfile] [oututfile] without -c or other ways of mapping streams. It ended performing a transcode on both the video and the audio streams, I'm not sure why, but for me in that particular scenario that was good enoughKenogenesis
Works for me. What exactly is the -ss 0:01 argument doing?Factoring
@Factoring here the arguments -ss 0:01 should cut the first second of the input video.Frizz
S
0

Simplest solution that worked for me:

  • change .mkv to .mp4
Schrock answered 28/5, 2024 at 19:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.