視頻的橫豎問題

來源:互聯網
上載者:User
我們系統中使用者上傳到視頻多數是客戶用手機拍攝的,現在存在一個問題,就是PC瀏覽器上播放的時候,這個視頻是橫著的。
大家明白我的意思嗎? 實際事物是: 1,但是視頻看起來就是: 一 。

現在我想把視頻變成是跟實際事物一直的狀態。

七牛返回的視頻元資訊中有rotate:90這樣的參數,還有高度和寬度。

我的想法:
1、判斷高度和寬度,全部轉為高>寬
2、我對rotate這個參數不太理解,這個能代表實際和視頻的角度差嗎? (百度上出來的全部是imagerotate(),沒有視頻方面的。ffmpeg也沒有提到這個,只是說了一些之類的問題。)

考慮到有些視頻就是手機橫著拍攝的,強制轉了不是又出現了偏差?

求助有什麼辦法可以解決這個問題

我提供一個視頻的元資訊,大家幫我看看咯,謝謝

streams[1].tags.rotate "rotate": "90",

{    "streams": [        {            "index": 0,            "codec_name": "aac",            "codec_long_name": "AAC (Advanced Audio Coding)",            "profile": "LC",            "codec_type": "audio",            "codec_time_base": "1/44100",            "codec_tag_string": "mp4a",            "codec_tag": "0x6134706d",            "sample_fmt": "fltp",            "sample_rate": "44100",            "channels": 1,            "channel_layout": "mono",            "bits_per_sample": 0,            "r_frame_rate": "0/0",            "avg_frame_rate": "0/0",            "time_base": "1/44100",            "start_pts": 0,            "start_time": "0.000000",            "duration_ts": 2408448,            "duration": "54.613333",            "bit_rate": "89406",            "nb_frames": "2352",            "disposition": {                "default": 1,                "dub": 0,                "original": 0,                "comment": 0,                "lyrics": 0,                "karaoke": 0,                "forced": 0,                "hearing_impaired": 0,                "visual_impaired": 0,                "clean_effects": 0,                "attached_pic": 0            },            "tags": {                "creation_time": "2015-11-08 14:36:49",                "language": "und",                "handler_name": "Core Media Audio"            }        },        {            "index": 1,            "codec_name": "h264",            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",            "profile": "Main",            "codec_type": "video",            "codec_time_base": "1/1200",            "codec_tag_string": "avc1",            "codec_tag": "0x31637661",            "width": 480,            "height": 272,            "has_b_frames": 0,            "sample_aspect_ratio": "0:1",            "display_aspect_ratio": "0:1",            "pix_fmt": "yuv420p",            "level": 21,            "color_range": "tv",            "color_space": "bt709",            "color_transfer": "bt709",            "color_primaries": "bt709",            "chroma_location": "left",            "is_avc": "1",            "nal_length_size": "4",            "r_frame_rate": "30000/1001",            "avg_frame_rate": "490800/16369",            "time_base": "1/600",            "start_pts": 0,            "start_time": "0.000000",            "duration_ts": 32738,            "duration": "54.563333",            "bit_rate": "710127",            "bits_per_raw_sample": "8",            "nb_frames": "1636",            "disposition": {                "default": 1,                "dub": 0,                "original": 0,                "comment": 0,                "lyrics": 0,                "karaoke": 0,                "forced": 0,                "hearing_impaired": 0,                "visual_impaired": 0,                "clean_effects": 0,                "attached_pic": 0            },            "tags": {                "rotate": "90",                "creation_time": "2015-11-08 14:36:49",                "language": "und",                "handler_name": "Core Media Video"            }        }    ],    "format": {        "nb_streams": 2,        "nb_programs": 0,        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",        "format_long_name": "QuickTime / MOV",        "start_time": "0.000000",        "duration": "54.563333",        "size": "5488167",        "bit_rate": "804667",        "probe_score": 100,        "tags": {            "major_brand": "mp42",            "minor_version": "1",            "compatible_brands": "mp41mp42isom",            "creation_time": "2015-11-08 14:36:49"        }    }}

回複內容:

我們系統中使用者上傳到視頻多數是客戶用手機拍攝的,現在存在一個問題,就是PC瀏覽器上播放的時候,這個視頻是橫著的。
大家明白我的意思嗎? 實際事物是: 1,但是視頻看起來就是: 一 。

現在我想把視頻變成是跟實際事物一直的狀態。

七牛返回的視頻元資訊中有rotate:90這樣的參數,還有高度和寬度。

我的想法:
1、判斷高度和寬度,全部轉為高>寬
2、我對rotate這個參數不太理解,這個能代表實際和視頻的角度差嗎? (百度上出來的全部是imagerotate(),沒有視頻方面的。ffmpeg也沒有提到這個,只是說了一些之類的問題。)

考慮到有些視頻就是手機橫著拍攝的,強制轉了不是又出現了偏差?

求助有什麼辦法可以解決這個問題

我提供一個視頻的元資訊,大家幫我看看咯,謝謝

streams[1].tags.rotate "rotate": "90",

{    "streams": [        {            "index": 0,            "codec_name": "aac",            "codec_long_name": "AAC (Advanced Audio Coding)",            "profile": "LC",            "codec_type": "audio",            "codec_time_base": "1/44100",            "codec_tag_string": "mp4a",            "codec_tag": "0x6134706d",            "sample_fmt": "fltp",            "sample_rate": "44100",            "channels": 1,            "channel_layout": "mono",            "bits_per_sample": 0,            "r_frame_rate": "0/0",            "avg_frame_rate": "0/0",            "time_base": "1/44100",            "start_pts": 0,            "start_time": "0.000000",            "duration_ts": 2408448,            "duration": "54.613333",            "bit_rate": "89406",            "nb_frames": "2352",            "disposition": {                "default": 1,                "dub": 0,                "original": 0,                "comment": 0,                "lyrics": 0,                "karaoke": 0,                "forced": 0,                "hearing_impaired": 0,                "visual_impaired": 0,                "clean_effects": 0,                "attached_pic": 0            },            "tags": {                "creation_time": "2015-11-08 14:36:49",                "language": "und",                "handler_name": "Core Media Audio"            }        },        {            "index": 1,            "codec_name": "h264",            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",            "profile": "Main",            "codec_type": "video",            "codec_time_base": "1/1200",            "codec_tag_string": "avc1",            "codec_tag": "0x31637661",            "width": 480,            "height": 272,            "has_b_frames": 0,            "sample_aspect_ratio": "0:1",            "display_aspect_ratio": "0:1",            "pix_fmt": "yuv420p",            "level": 21,            "color_range": "tv",            "color_space": "bt709",            "color_transfer": "bt709",            "color_primaries": "bt709",            "chroma_location": "left",            "is_avc": "1",            "nal_length_size": "4",            "r_frame_rate": "30000/1001",            "avg_frame_rate": "490800/16369",            "time_base": "1/600",            "start_pts": 0,            "start_time": "0.000000",            "duration_ts": 32738,            "duration": "54.563333",            "bit_rate": "710127",            "bits_per_raw_sample": "8",            "nb_frames": "1636",            "disposition": {                "default": 1,                "dub": 0,                "original": 0,                "comment": 0,                "lyrics": 0,                "karaoke": 0,                "forced": 0,                "hearing_impaired": 0,                "visual_impaired": 0,                "clean_effects": 0,                "attached_pic": 0            },            "tags": {                "rotate": "90",                "creation_time": "2015-11-08 14:36:49",                "language": "und",                "handler_name": "Core Media Video"            }        }    ],    "format": {        "nb_streams": 2,        "nb_programs": 0,        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",        "format_long_name": "QuickTime / MOV",        "start_time": "0.000000",        "duration": "54.563333",        "size": "5488167",        "bit_rate": "804667",        "probe_score": 100,        "tags": {            "major_brand": "mp42",            "minor_version": "1",            "compatible_brands": "mp41mp42isom",            "creation_time": "2015-11-08 14:36:49"        }    }}

你需要使用七牛的轉碼方式將 rotate 參數為 0
文檔視頻轉碼

1.安裝ffmpeg
2.ffmpeg -i INPUT.AVI -vcodec libx264 -preset slower -crf 18 -threads 4 -vf transpose=2 -acodec copy OUTPUT.MKV

-i 待轉碼檔案
-vcodec 選擇視頻編碼。做過一番搜尋,相比與MPEG2, MPEG4等,H.264是公認最好的高清編碼格式,同時壓縮率也高於MPEG4,所以我選擇使用H.264(libx264)進行視頻編碼。

-preset 選擇編碼預設,更慢=更好的視頻品質,可選取值為 ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo。placebo是沒用的取值。

-crf Constant Rate Factor,0~51之間取值,0為無損,23為預設取值,取值越大,視頻整體品質越差。一般建議在18~28之間取值。18已經達到視覺無損的效果,即人眼幾乎察覺不到和原片的差別。

-threads 編碼使用線程數,CPU幾個核心就設定幾個線程好了。

-vf 濾鏡,我們只需要用到旋轉濾鏡transpose=2,transpose濾鏡可取0-3,0為逆時針90°且垂直翻轉,1為順時針旋轉90°,2為逆時針旋轉90°,3為順時針90°且垂直翻轉。

-acodec 音頻編碼,這裡直接設定為copy保留原檔案音頻編碼。

最後設定輸出檔案為OUTPUT.MKV

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.