I use
ffmpeg.exe -f concat -i file_path_list_txt -c copy out_out.mp4
to concat
for file in 1265_*; do ffmpeg -i $file -cr
With the help of Gyan's answer,I make it works,both the compress and append process I need to set tbn
.
Details as below:
Each time a new video slice generated, get tbn
with get_video_attributes
, then compress it with,
ffmpeg -i $video_path_i -crf 30 -b:a 23k -b:v 96k -video_track_timescale $tbn -threads 3 -y 'out_'$file
Then append the compressed slice to previous video with,
ffmpeg.exe -f concat -i file_path_list_txt -video_track_timescale $tbn -c copy out_out.mp4
Update get_video_attribute
function according to llogan 's comment
function get_video_attribute(&$video_attribute,$video_path,$ffprobe="ffprobe"){
$command = "$ffprobe -v error -show_entries stream=codec_type,codec_name,width,height,bit_rage,avg_frame_rate,r_frame_rate,".
"channels,channel_layout,sample_rate,bit_rate,time_base,codec_time_base,duration:format=duration,size,bit_rate -of json $video_path";
$video_attribute = [];
exec($command,$output,$return_var);
if ($return_var) {
return false;
}
if(false !== ($attribute=json_decode(join($output),true))){
// TODO video file may have more streams or less streams than one video and one audio stream
foreach($attribute["streams"] as $stream){
if(!isset(${$stream["codec_type"]})){
${$stream["codec_type"]} = $stream;
}
}
$video_attribute = array(
'width' => $video["width"],
'height' => $video["height"],
'duration' => intval($attribute["format"]["duration"]),
'v_codec' => $video["codec_name"],
'a_codec' => $audio["codec_name"],
"tbn" => $video["time_base"] ? explode("/",$video["time_base"])[1] : null,
'bps' => $attribute["format"]["bit_rate"],
'v_bps' => $video["bit_rate"],
'a_bps' => $audio["bit_rate"]
);
return true;
}else{
return false;
}
}