V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
mfsw
V2EX  ›  Windows

windows 下,如何无损旋转 mp4 视频?

  •  
  •   mfsw · Dec 30, 2023 · 2700 views
    This topic created in 853 days ago, the information mentioned may be changed or developed.

    我的视频是佳能相机拍的 MP4 文件。拍的时候是竖版。但是 POTPLAYER 播放的时候是以横版来播放的。 我想把这些横版视频,旋转 90 度,变成拍摄时候的视角。 请问,是否可以利用 ffmpeg,来批量的旋转一下? 如果 ffmpeg 不能实现,是否有其他的软件能快捷的实现批量无损旋转?

    16 replies    2023-12-31 22:22:02 +08:00
    mfsw
        1
    mfsw  
    OP
       Dec 30, 2023
    跟 chatgpt 斗智斗勇了好久,他都没能提供给我一个可用的 ffmpeg 的命令。诸位大佬请发威吧。
    qwertyegg
        2
    qwertyegg  
       Dec 30, 2023
    ffmpeg -i input.mp4 -vf "transpose=1" output.mp4

    transpose=1 或者=2
    mfsw
        3
    mfsw  
    OP
       Dec 30, 2023
    @qwertyegg 感谢大佬指教。实测不行,跟 gpt 的答案差不多,视频被旋转了,但是容量变得很小。只有原来的二十分之一。
    qwertyegg
        4
    qwertyegg  
       Dec 30, 2023   ❤️ 1
    ffmpeg -display_rotation:v:0 90 -i input.mp4 -c copy output.mp4

    这样 stream copy/remux 出来的视频,不重新编码
    AoEiuV020JP
        5
    AoEiuV020JP  
       Dec 30, 2023 via Android
    %bin%ffmpeg -i "%name%%ext%" -c copy -metadata:s:v:0 rotate=%rotate% "%name%-%rotate%%ext%"
    mfsw
        6
    mfsw  
    OP
       Dec 30, 2023
    大佬威武,在大佬面前,gpt 就是个弱智。
    再请教下,我要把您的这行代码,修改为一个批处理脚本。
    我要把指定目录下的所有 mp4 文件,都旋转 90 度,并替换删除原始文件,我该怎么修改? 我希望这个批处理,能提供一个输入选项,让我可以输入指定的目录。
    感谢大佬搭救。
    mfsw
        7
    mfsw  
    OP
       Dec 30, 2023
    @qwertyegg 6 楼内容是回复您的。忘记引用了。
    mfsw
        8
    mfsw  
    OP
       Dec 30, 2023
    @AoEiuV020JP 感谢指教。4 楼大佬的方法好用。就不尝试其他方案了。辛苦您啦。
    qwertyegg
        9
    qwertyegg  
       Dec 30, 2023
    用 ahk(v2)可以参考如下

    targetPattern := concat3("c:\captures\", prefix, "*.mp4")
    udp_profiles := []
    loop files targetPattern
    udp_profiles.Push(A_LoopFileName)
    }
    mfsw
        10
    mfsw  
    OP
       Dec 30, 2023
    @qwertyegg 没看懂。这是撒东东?您提供的代码已经很完美了。我只需要把他变成批处理即可。
    qwertyegg
        11
    qwertyegg  
       Dec 30, 2023
    下面这段 ahk 代码,"把 ffmpeg 加到 path 里面"和"mp4 文件不要带空格“两个要求满足的时候应该就可以批量转了

    #Requires AutoHotkey v2.0
    #SingleInstance Force

    ; Get list of files matching a prefix under a folder.
    ; Set prefix an empty string "" if we want all, otherwise add prefix to limit selection
    prefix := ""


    ;=============== init script ===============
    targetPattern := concat3("D:\captures\", prefix, "*.mp4")
    video_files := []
    loop files targetPattern
    video_files.Push(A_LoopFileName)
    lastIndex := video_files.Length

    ;;;;;;;;;;; F2 to cycle through rotation jobs
    #MaxThreadsPerHotkey 1
    F2::{
    static counter := 1
    while (counter <= lastIndex){
    ffmpeg_rotate(video_files[counter])
    counter := counter + 1
    }
    ; MsgBox "That was the last, exit."
    ExitApp
    }


    ffmpeg_rotate(video_file){
    SetWorkingDir "D:\captures"
    Run concat4("ffmpeg -display_rotation:v:0 90 -i ", video_file, " -c copy rotated_", video_file)
    }

    concat3(x, y, z) {
    Return x y z
    }

    concat4(w, x, y, z) {
    Return w x y z
    }
    mfsw
        12
    mfsw  
    OP
       Dec 30, 2023
    @qwertyegg 感谢大佬热心科普。
    能不能帮忙以批处理的方式,实现下?万分感谢。
    miaotaizi
        13
    miaotaizi  
       Dec 30, 2023
    把屏幕竖起来?
    forgottencoast
        14
    forgottencoast  
       Dec 30, 2023
    @mfsw
    批处理这个问题 chatGPT 保证不弱智,你问它就行了。
    mfsw
        15
    mfsw  
    OP
       Dec 30, 2023
    @forgottencoast 3.5 ruozhi ,4.0 可能不 ruozhi 。但是我现在没有 4.0 的账号了。
    EvaElfie
        16
    EvaElfie  
       Dec 31, 2023
    LOSSLESSCUT
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2481 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 09:54 · PVG 17:54 · LAX 02:54 · JFK 05:54
    ♥ Do have faith in what you're doing.