Log in

View Full Version : FFMPEG - Timestamp unset in a packet


ABurns
7th December 2020, 00:50
I've Googled this problem, but every solution I've found doesn't seem to work for me. I'm encoding x265 with FFMPEG and then muxing, but on mux I get the error:
[matroska @ 000001c974ade080] Timestamps are unset in a packet for stream 2. This is deprecated and will stop working in the future.
Fix your code to set the timestamps properly
[matroska @ 000001c974ade080] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument

For clarity, I'm starting with an MKV ripped from a DVD, encoding it x265 (please don't start about x265 at SD - I know what I want), and then remuxing with the HEVC stream in place of the MPEG-2 stream. This is done via .bat files, which I will combine once I get everything working.

The encode script.
for %%F in (*.avs) do ffmpeg.exe -i "%%F" -c:v libx265 -framerate 24000/1001 -preset medium -crf 23 -profile:v main10
-x265-params "no-sao=1:selective-sao=0" -vf "scale=720:480,setdar=4/3" "%%~F.hevc"

The mux script.
for %%i in ("*.mkv") do ffmpeg -i "%%i" -i "%%~ni.avs.hevc" -c: copy -map 0 -map -0:v:0 -map 1 "../%%i"
I've tried -use_wallclock_as_timestamps 1, -vsync 0 -enc_time_base -1, and -fflags +genpts as suggested in various places, but none solve my problem. Any idea how to get these streams to mux properly?

quietvoid
7th December 2020, 01:44
Usually I would recommend using mkvmerge (or the MKVToolNix family of tools) for anything Matroska related.

ABurns
7th December 2020, 02:56
I've used the GUI and it works fine, but I've never used it from a command line, so I'm not that familiar with it that way. What might that command look like?

quietvoid
7th December 2020, 03:45
The GUI has a menu to show the CLI it's using, under Multiplexer > Show command line.
It's a bit verbose but it should be possible to adapt to your situation.

For example a video + audio source mkv with the encoded file, keeping only the encoded video (Linux CLI):
mkvmerge --ui-language en_US --output output.mkv --language 0:en '(' encode.hevc ')' --no-video --no-chapters --language 1:en --default-track 1:yes '(' source1.mkv ')' --track-order 0:0,1:1

That's the default for my input file, at least. I don't know if it allows for overwriting the original file.
That's something you could ask at the MKVToolNix thread: https://forum.doom9.org/showthread.php?t=175593

ABurns
7th December 2020, 04:37
Oh wow, I never knew that option was there in the GUI! It's amazing... you use a thing for years and never know something that basic....

But I'm having trouble converting that command line into something that works in a batch file. Let's say, for example, I'm working with Season 3 of Gilligan's Island (I am) and my file is named "3x27 It's a Bird, It's a Plane.mkv". Here is what mkvtoolnix shows for the command line of what I want to do. "C:\Program Files\MKVToolNix\mkvmerge.exe" --ui-language en --output ^"G:\Output\3x27 It's a Bird, It's a Plane.mkv^" --no-video --language 1:en
--track-name 1:Mono --default-track 1:yes --language 2:en --default-track 2:yes ^"^(^" ^"G:\Rips\GILLIGANS ISLAND SEASON 3\stripped\3x27 It's a Bird, It's a Plane.mkv^" ^"^)^"
--language 0:en ^"^(^" ^"G:\Rips\GILLIGANS ISLAND SEASON 3\stripped\3x27 It's a Bird, It's a Plane.avs.hevc^" ^"^)^" --track-order 0:1,0:2,1:0
Except I want to add that to a batch script that will do that for *every* file in the directory using the same naming structure - 30 episodes. I'm going to confess I've been messing with this for a week and I'm burned out with googling and trying to figure things out. I wouldn't ordinarily ask for somebody to hand me the answer but I'm just burned out and I need it t just work at this point.

Thanks in advance.

Boulder
7th December 2020, 08:52
You need to use the for command, I do that all the time.

For example like this - it will take all *s03*.hevc files from the current directory and use their filename structure for the other files and output as well. In this case the hevc files would be in F:\ and I would simply change to that directory in the command prompt before launching the command.

for %f in (*s03*.hevc) do "C:\Program Files\MKVToolNix\mkvmerge.exe" --ui-language en --output "m:\%~nf.mkv" --language 0:und --compression 0:none ( "F:\%~nf.hevc" ) --language 0:en --compression 0:none ( "F:\%~nf.opus" ) --language 0:fi --compression 0:none ( "F:\%~nf.srt" ) --chapter-language und --chapters "F:\%~nf.xml" --engage no_cue_duration --engage no_cue_relative_position --disable-track-statistics-tags --track-order 0:0,1:0,2:0

If you use it in a batch file, you need to use %% instead of %.

ABurns
8th December 2020, 03:29
Thanks, Boulder. I was able to make that work.