Harshit Joshi
Harshit Joshi

Reputation: 290

FFMPEG Output Video Playback Starts at 10 Seconds

I have made a Python script whose task is to take a video file and split it up into separate videos of 60 secs each. Here's the code.

import os
import datetime
import subprocess

FILENAME = "SomeFile.mp4"
SECS_PER_VIDEO = 60

def add_secs(time, secs):
    dummy_datetime = datetime.datetime(1, 1, 1, time.hour, time.minute, time.second)
    dummy_datetime += datetime.timedelta(seconds = secs)
    return dummy_datetime.time()

def get_duration(filename):
    duration = subprocess.run(f"ffprobe -i \"{filename}\" -show_entries format=duration -v quiet -of csv=\"p=0\"", stdout=subprocess.PIPE)
    duration = duration.stdout
    duration = duration.decode("utf-8")[:len(duration)-2]
    duration = float(duration)
    return duration


num_of_videos = int(get_duration(FILENAME) // SECS_PER_VIDEO)
init = datetime.time(hour=0, minute=0, second=0)
folder_name = FILENAME[:len(FILENAME)-4]
if not os.path.isdir(folder_name):
    os.mkdir(folder_name)

for i in range(num_of_videos):
    print(f"Part {i}")
    os.system(f"ffmpeg -i \"{FILENAME}\" -ss {str(init)} -codec copy -t {SECS_PER_VIDEO} \"{folder_name}/{str(i+1)}_{FILENAME}\"")
    print("")
    init = add_secs(init, SECS_PER_VIDEO)

print(f"Split Into: {num_of_videos}")

Example ffmpeg call:

ffmpeg -i "SomeFile.mp4" -ss 01:49:00 -codec copy -t 60 "SomeFile/110_SomeFile.mp4"

The script works just fine, however when I'm playing any of the output files, VLC skips all the frames during the 1st 10 seconds and the playback starts from 00:00:10.

What's wrong with the script?

Upvotes: 0

Views: 701

Answers (1)

stevejobs
stevejobs

Reputation: 449

@Harshit this will workd: the order of parameters to every video have 60 secs of duration is the next:

ffmpeg -i "SomeFile.mp4" -ss 01:49:00.000   -t 60.000 -c copy  -dn -map_metadata -1 -map_chapters -1 "video_60seconds.mp4"
  • dn for no copy data in the file
  • map_metadata -1 remove all data from metadata, and this can be the responsable of problem, for this reason is good idea to remove all data
  • ss 01:49:00.000 t 60.000 (Add 000 zeros for millisecs)

Upvotes: 1

Related Questions