7

ビデオの長さを秒単位で取得するにはどうすればよいですか?

私が試したこと:

ffmpeg -i file.flv 2>&1 | grep "Duration"
  Duration: 00:39:43.08, start: 0.040000, bitrate: 386 kb/s


mediainfo file.flv | grep Duration
Duration : 39mn 43s

これは近いですが、それほど正確ではありません。2383 は 39.71 分です

    ffmpeg -i file.flv 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g' | awk '{ split($1, A, ":"); split(A[3], B, "."); print 3600*A[1] + 60*A[2] + B[1] }'
2383
4

8 に答える 8

4

2383が正解です。1 分間は 100 秒ではなく 60 秒です。43/60 = .71

https://www.google.com/#q=39+分+43.08+秒+秒+秒

于 2013-09-25T19:40:39.687 に答える
3

その作業は私のために試してみてください:)

$duration = shell_exec("ffmpeg -i \"". $input . "\" 2>&1");

preg_match("/Duration: (\d{2}:\d{2}:\d{2}\.\d{2})/",$duration,$matches);
$time = explode(':',$matches[1]);
$hour = $time[0];
$minutes = $time[1];
$seconds = round($time[2]);

$total_seconds = 0;
$total_seconds += 60 * 60 * $hour;
$total_seconds += 60 * $minutes;
echo $total_seconds += $seconds;
于 2014-08-05T10:06:04.647 に答える
2

使用できます

ffprobe -v quiet -print_format xml -show_format -show_streams inputfile.flv

このようなxmlを返します

<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
    <streams>
        <stream index="0" codec_name="h264" codec_long_name="H.264 / AVC / MPEG-4 AVC / 
    MPEG-4 part 10" profile="High" codec_type="video" codec_time_base="1/50" codec_tag_string="avc1" codec_tag="0x31637661" width="1920" height="1080" has_b_frames="2" sample_aspect_ratio="0:1" display_aspect_ratio="0:1" pix_fmt="yuvj420p" level="40" r_frame_rate="25/1" avg_frame_rate="25/1" time_base="1/12800" start_pts="0" start_time="0.000000" duration_ts="50176" duration="3.920000" bit_rate="4347640" nb_frames="98">
                <disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
                <tag key="language" value="eng"/>
                <tag key="handler_name" value="VideoHandler"/>
            </stream>
        <stream index="1" codec_name="aac" codec_long_name="AAC (Advanced Audio Coding)" codec_type="audi

o" codec_time_base="1/48000" codec_tag_string="mp4a" codec_tag="0x6134706d" sample_fmt="fltp" sample_rate="48000" channels="2" bits_per_sample="0" r_frame_rate="0/0" avg_frame_rate="0/0" time_base="1/48000" start_pts="-1024" start_time="-0.021333" duration_ts="189184" duration="3.941333" bit_rate="122277" nb_frames="185">
            <disposition default="0" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
            <tag key="language" value="eng"/>
            <tag key="handler_name" value="SoundHandler"/>
        </stream>
    </streams>

    <format filename="inputfile.flv" nb_streams="2" format_name="mov,mp4,m4a,3gp,3g2,mj2" format_long_name="QuickTime / MOV" start_time="-0.021333" duration="3.942000" size="2194901" bit_rate="4454390">
        <tag key="major_brand" value="isom"/>
        <tag key="minor_version" value="512"/>
        <tag key="compatible_brands" value="isomiso2avc1mp41"/>
        <tag key="encoder" value="Lavf54.63.100"/>
    </format>
</ffprobe>

次に、ビデオ ストリーム、つまり通常は属性 index = "0" でフィルター処理し、既に秒単位である属性 "duration" の値を取得します。

于 2014-01-28T12:35:35.570 に答える
0

インストールしたことがある場合はffmpeg、おそらくあなたもffprobeインストールしているはずです。

ffprobe -i file.mp4 -show_format -v quiet | sed -n 's/duration=//p' | xargs printf %.0f

コマンドは整数値を返します。

出力例:

190

于 2014-05-04T13:17:45.923 に答える
0

ffmpeg がある場合は、ffprobe も必要です。一連の key=value ペアで STDOUT に情報を出力し、デフォルトで秒単位の期間を指定します ( -sexagesimalhh:mm:ss が必要な場合は、オプションを使用する必要があります)。

ffprobe -show_format file.mp4 | grep -F duration | cut -d= -f2
于 2014-10-04T15:52:58.043 に答える