Last active
December 20, 2015 07:59
-
-
Save bjou/6097170 to your computer and use it in GitHub Desktop.
ffmpeg_hd2sd_transcode_segment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert HD video to SD and transcode in one-shot | |
ffmpeg -i video.ts -preset ultrafast -y [-loglevel quiet] -aspect 16:9 -s 640:360 video.mp4 | |
# batch segment the video in one-shot (no looped seeking) | |
# NOTES: "-vcodec" and "-acodec" can be changed to preferred stream types, e.g. libx264 and libfaac, respectively | |
# "-vbsf h264_mp4toannexb" optionally allows for broken mp4's to still get parsed | |
ffmpeg -i video.mp4 -vcodec copy -acodec copy -map 0 [-vbsf h264_mp4toannexb] [-loglevel quiet] -f segment -segment_format mp4 -segment_times <time_sec_1>,<time_sec_2>,<time_sec_3>,<...> output%02d.mp4 | |
# TODO: needs further investigation on segmentation accuracy; cutting may still happen on i-frames due to keyframe-level accuracy, but this may have been solved by mpegts-to-mp4 transcoding |
tail -n +2
in the triple marker parsing should be ignored if the first line of the file is still usable
To change to cutting by frames use -segment_frames
instead of -segment_times
, and change the triple marker parsing to:
cut -d' ' -f1 $2 | \
tr ',' '.' | \
awk -F: '{ printf "%d,",((($1 * 3600) + ($2 * 60) + $3) * 29.97) }' | \
sed 's/.$//'
(assuming the frame rate of the video is 29.97 fps and the first line of the triple marker file is valid)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a script for directly parsing triple-marker files and passing it as a parameter to segmentation:
The portion that does the actual parsing is (it assumes the first column of the file contains cut times, i.e. beginning of new segments):
Example usage: