Answers.Body: <p>Here is the solution.</p>
  <p>The ffmpeg presentation timestamp <code>%{pts}</code> can only be zeroed and offest, as far as I know, using the <code>C gmtime</code> function, with the time set to 1st Jan 2000 in unix time seconds, ie 946684800 seconds, or some other arbitrary time at midnight.</p>
  <p>946684800 seconds in UNIX time gives midnight 00:00:00 on 01/01/2000  as a starting point for our calculations, to which we can add our own offset, in this case 5 seconds, as follows.</p>
  <p>We don't display the <code>%d-%m-%Y</code> portion of the date, so our method is not seen. Works very well. Took a bit of figuring out though.</p>
  <pre><code># set file names
  in_file=&quot;my_video_file.mp4&quot;
  out_file=&quot;my_video__clipped.mp4&quot;
  
  # set start and end times of the clip to be made
  start_time_z=&quot;00:00:05&quot;
  end_time_z=&quot;00:00:10&quot;   
  
  ######################################################################
  ##########                                                  ########## 
  ##########       get the duration of the                    ##########
  ##########          input video in hh:mm:ss format          ##########
  ##########        and convert it to seconds                 ##########
  ##########                                                  ########## 
  ######################################################################
  
  
  total_duration=$(ffprobe -v error -show_entries format=duration \
    -of default=noprint_wrappers=1:nokey=1 &quot;$in_file&quot; \
    | awk '{printf(&quot;%02d:%02d:%02d\n&quot;, ($1/3600), ($1%3600)/60, $1%60)}')
  
  # escape the &quot;:&quot; in the time stamp so that they can be printed by ffmpeg
  total_duration=&quot;$(echo $total_duration | sed 's@:@\\:@g')&quot;
  
  # display the duration of the original video. Check we have captured it correctly
  ####    yad --text=&quot;\n\n$total_duration\n\n&quot; --button=&quot;Submit&quot;:0
  
  
  ######################################################################
  ##########                                                  ########## 
  ##########       convert the variable                       ##########
  ##########             $start_time_z   which                ##########
  ##########                    = 00:00:05                    ##########
  ##########                                                  ##########
  ##########    into seconds and add to it unix time for      ##########
  ##########           00:00:00 on 1st Jan 2000               ##########
  ##########                                                  ########## 
  ######################################################################
  
  
  # convert the clip start time from hh:mm:ss to seconds
  start_secs=$(echo &quot;$start_time_z&quot; | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
  
  # convert the clip end time from hh:mm:ss to seconds
  end_secs=$(echo &quot;$end_time_z&quot; | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
  
  # duration of the clip
  duration_z=$((end_secs-start_secs))
  
  
  # Add start time to 946684800 which is 00:00:00 on 1st Jan 2000
  total_z=$(echo &quot;$start_secs + 946684800&quot; | bc)
  echo $total
  
  
  ######################################################################
  ##########                                                  ########## 
  ##########   run the command to create the MAIN  clip       ##########
  ##########                                                  ########## 
  ######################################################################
  
  
  #   below string shows unix time in action
  #     by removing the %d-%m-%Y portion we remove the 01-01-2000 part
  #       this appears to be the only way to shift pts and add a time shift onto it
  
  # drawtext=fontfile=font.ttf:text='%{pts\:gmtime\:$total_z\:%d-%m-%Y %T} / &quot;$total_duration&quot;':fontsize=$main_clip_font_size:fontcolor=white:x=(w-text_w-10):y=(h-text_h-10)&quot; \
  
  ffmpeg -ss &quot;$start_time_z&quot; \
      -i &quot;$in_file_name&quot; \
      -filter_complex \
  &quot;drawtext=fontfile=font.ttf:text='%{pts\:gmtime\:$total_z\:%T} / &quot;$total_duration&quot;':fontsize=$main_clip_font_size:fontcolor=white:x=(w-text_w-10):y=(h-text_h-10)&quot; \
         -t  $duration_z \
         -c:a copy -c:v libx264 \
         &quot;$out_file&quot;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-25T17:34:46.170Z
Answers.Text: Does anyone know of a native ffmpeg command, or other way to add and offset in seconds to ffmpeg's `%{pts}` command without the above workaround?
Answers.UserDisplayName: Kes
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-25T08:23:35.447Z
Answers.LastActivityDate: 2023-05-25T08:23:35.447Z
Answers.UserDisplayName: Kes
Body: <p>I am using arch linux and bash and ffmpeg, all are up to date and the latest versions.</p>
  <p>I am clipping a video that is 30 seconds long and wish to clip from 5 secs to 10 seconds to a new file, from the original.</p>
  <p>In the bottom right hand corner of the clip I wish to show timestamps from the original video as follows</p>
  <ul>
  <li>in the  5th second &quot;00:00:05/ 00:00:30&quot;</li>
  <li>in the  6th second &quot;00:00:06/ 00:00:30&quot;<br />
  etc</li>
  <li>in the 10th second &quot;00:00:10/ 00:00:30&quot;</li>
  </ul>
  <p>This is an apparentley simple question(?) but the syntax of the command is not at all obvious and I am hoping an expert may shed some light on this.</p>
  <p>All I have so far for the drawtext part, which does not do what I want as it only counts the elapsed time from t=0 of the <strong>new</strong> clip, whereas <strong>I want it to show the timestamp and total duration of the original clip</strong></p>
  <p><code>drawtext</code> I started with</p>
  <pre><code>&quot;drawtext=text='%{pts\:gmtime\:0\:%M\\\\\:%S}':fontsize=24:fontcolor=black:x=(w-text_w-10):y=(h-text_h-10)&quot;
  </code></pre>
  <p>ffmpeg line with drawtext I have started with</p>
  <pre><code>ffmpeg -ss 00:00:05 -i  &quot;$in_file&quot; -filter_complex &quot;drawtext=fontfile=font.ttf:text='sample text':x=10:y=10:fontsize=12:fontcolor=white:box=1:boxcolor=black@0.5:boxborderw=5,drawtext=text='%{duration\:hms}':fontsize=12:fontcolor=black:x=(w-text_w-10):y=(h-text_h-10)&quot; -t 5 -c:a copy -c:v libx264 out_file.mp4
  </code></pre>
  
Tags: <ffmpeg><video><clipping>
Title: With ffmpeg print onto clipped video hh:mm:ss time *from original* and hh:mm:ss total duration from original
UserDisplayName: Kes
ThreadText: # With ffmpeg print onto clipped video hh:mm:ss time *from original* and hh:mm:ss total duration from original
  
  (Asked by: username_0 on 2023-05-25)
  
  I am using arch linux and bash and ffmpeg, all are up to date and the latest versions.
  
  I am clipping a video that is 30 seconds long and wish to clip from 5 secs to 10 seconds to a new file, from the original.
  
  In the bottom right hand corner of the clip I wish to show timestamps from the original video as follows
  
  * in the 5th second "00:00:05/ 00:00:30"
  * in the 6th second "00:00:06/ 00:00:30"  
    etc
  * in the 10th second "00:00:10/ 00:00:30"
  
  This is an apparentley simple question(?) but the syntax of the command is not at all obvious and I am hoping an expert may shed some light on this.
  
  All I have so far for the drawtext part, which does not do what I want as it only counts the elapsed time from t=0 of the **new** clip, whereas **I want it to show the timestamp and total duration of the original clip**
  
  `drawtext` I started with
  
  ```
  "drawtext=text='%{pts\:gmtime\:0\:%M\\\\\:%S}':fontsize=24:fontcolor=black:x=(w-text_w-10):y=(h-text_h-10)"
  
  ```
  
  ffmpeg line with drawtext I have started with
  
  ```
  ffmpeg -ss 00:00:05 -i  "$in_file" -filter_complex "drawtext=fontfile=font.ttf:text='sample text':x=10:y=10:fontsize=12:fontcolor=white:box=1:boxcolor=black@0.5:boxborderw=5,drawtext=text='%{duration\:hms}':fontsize=12:fontcolor=black:x=(w-text_w-10):y=(h-text_h-10)" -t 5 -c:a copy -c:v libx264 out_file.mp4
  
  ```
  
  **Tags:** ffmpeg, video, clipping
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-05-25. Score: 1 | Accepted answer
  
  Here is the solution.
  
  The ffmpeg presentation timestamp `%{pts}` can only be zeroed and offest, as far as I know, using the `C gmtime` function, with the time set to 1st Jan 2000 in unix time seconds, ie 946684800 seconds, or some other arbitrary time at midnight.
  
  946684800 seconds in UNIX time gives midnight 00:00:00 on 01/01/2000 as a starting point for our calculations, to which we can add our own offset, in this case 5 seconds, as follows.
  
  We don't display the `%d-%m-%Y` portion of the date, so our method is not seen. Works very well. Took a bit of figuring out though.
  
  ```
  # set file names
  in_file="my_video_file.mp4"
  out_file="my_video__clipped.mp4"
  
  # set start and end times of the clip to be made
  start_time_z="00:00:05"
  end_time_z="00:00:10"   
  
  ######################################################################
  ##########                                                  ########## 
  ##########       get the duration of the                    ##########
  ##########          input video in hh:mm:ss format          ##########
  ##########        and convert it to seconds                 ##########
  ##########                                                  ########## 
  ######################################################################
  
  total_duration=$(ffprobe -v error -show_entries format=duration \
    -of default=noprint_wrappers=1:nokey=1 "$in_file" \
    | awk '{printf("%02d:%02d:%02d\n", ($1/3600), ($1%3600)/60, $1%60)}')
  
  # escape the ":" in the time stamp so that they can be printed by ffmpeg
  total_duration="$(echo $total_duration | sed 's@:@\\:@g')"
  
  # display the duration of the original video. Check we have captured it correctly
  ####    yad --text="\n\n$total_duration\n\n" --button="Submit":0
  
  ######################################################################
  ##########                                                  ########## 
  ##########       convert the variable                       ##########
  ##########             $start_time_z   which                ##########
  ##########                    = 00:00:05                    ##########
  ##########                                                  ##########
  ##########    into seconds and add to it unix time for      ##########
  ##########           00:00:00 on 1st Jan 2000               ##########
  ##########                                                  ########## 
  ######################################################################
  
  # convert the clip start time from hh:mm:ss to seconds
  start_secs=$(echo "$start_time_z" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
  
  # convert the clip end time from hh:mm:ss to seconds
  end_secs=$(echo "$end_time_z" | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }')
  
  # duration of the clip
  duration_z=$((end_secs-start_secs))
  
  # Add start time to 946684800 which is 00:00:00 on 1st Jan 2000
  total_z=$(echo "$start_secs + 946684800" | bc)
  echo $total
  
  ######################################################################
  ##########                                                  ########## 
  ##########   run the command to create the MAIN  clip       ##########
  ##########                                                  ########## 
  ######################################################################
  
  #   below string shows unix time in action
  #     by removing the %d-%m-%Y portion we remove the 01-01-2000 part
  #       this appears to be the only way to shift pts and add a time shift onto it
  
  # drawtext=fontfile=font.ttf:text='%{pts\:gmtime\:$total_z\:%d-%m-%Y %T} / "$total_duration"':fontsize=$main_clip_font_size:fontcolor=white:x=(w-text_w-10):y=(h-text_h-10)" \
  
  ffmpeg -ss "$start_time_z" \
      -i "$in_file_name" \
      -filter_complex \
  "drawtext=fontfile=font.ttf:text='%{pts\:gmtime\:$total_z\:%T} / "$total_duration"':fontsize=$main_clip_font_size:fontcolor=white:x=(w-text_w-10):y=(h-text_h-10)" \
         -t  $duration_z \
         -c:a copy -c:v libx264 \
         "$out_file"
  
  ```
  
  > **Comments:**
  > **username_0**: Does anyone know of a native ffmpeg command, or other way to add and offset in seconds to ffmpeg's `%{pts}` command without the above workaround?  
  
  ---
  
  