You are not logged in.

#1 2018-07-16 21:24:32

ss
Member
Registered: 2018-06-04
Posts: 89

How to print the current timestamp to a file with mpv?

I want to do some basic video editing without large graphical suites like Kdenlive.
Also because my most powerful computer at home is now headless, it would be nice if I can somehow still use it for video editing.

Let's suppose the following simple case: I need to cut and re-encode a specific portion of the video. Given the starting and ending timestamp, this can be easily accomplished with ffmpeg. But how to get the start and end points in a scriptable way? Currently I have this workflow in mind: I playback the video with mpv, pause at the positions where I want to cut, bind a keyboard shortcut which will simply write the current timestamp to a text file, then run ffmpeg with the timestamps from that file.

However, I can't figure out how to use mpv in such way. Any suggestions? I am sure this has been done by many people, just don't know where to fine the relevant information.

Well, in fact, it doesn't have to be mpv and ffmpeg. Any solutions which will solve this problem are appreciated.

Offline

#2 2018-07-16 21:34:32

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: How to print the current timestamp to a file with mpv?

Maybe using one of the user scripts, like this one: https://github.com/nimatrueway/mpv-bookmark-lua-script to create the timestamp file?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2018-07-16 21:38:16

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,450
Website

Re: How to print the current timestamp to a file with mpv?

ffplay video.mpg 2> /tmp/log

Then pause whenever you want, and get the timestamp:

tr '\r' '\n' < /tmp/log | awk 'END { print $1; }'

"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2018-07-16 23:14:55

monodromy
Member
Registered: 2014-02-08
Posts: 62

Re: How to print the current timestamp to a file with mpv?

mplayer can also do this natively with

mplayer -edlout

The manual has more info.

Offline

#5 2018-07-17 20:31:40

teckk
Member
Registered: 2013-02-21
Posts: 571

Re: How to print the current timestamp to a file with mpv?

then run ffmpeg with the timestamps from that file.

You are going to have a hard time with that. The ending time stamp isn't what ffmpeg wants, but rather the duration from where you started.
If you want from time stamp 00:02:36 to 00:05:17 in a video, then what you want is:

ffmpeg -ss 00:02:36 -t 00:02:41

This little bash script will spit out the start of a ffmpeg line, after you enter the start and stop times.
https://bbs.archlinux.org/viewtopic.php … 7#p1765337

You can also start/stop on frame number if that's better for your script.
This will show you frame numbers of video while it's playing.

ffplay file.mp4 \
-vf "drawtext=fontfile=Arial.ttf: text=%{n}: \
x=(w-tw)/2: y=h-(2*lh): fontcolor=white: \
fontsize=100: box=1: boxcolor=0x00000099"

Press the space bar to pause, get the frame number.
30 fps video, frame_num / 30 = time stamp.

Offline

#6 2018-07-17 22:50:07

DrZaius
Member
Registered: 2008-01-02
Posts: 193

Re: How to print the current timestamp to a file with mpv?

teckk wrote:

You are going to have a hard time with that. The ending time stamp isn't what ffmpeg wants, but rather the duration from where you started.

Or use the -to option instead.

Offline

Board footer

Powered by FluxBB