Heim  >  Artikel  >  Backend-Entwicklung  >  视频的横竖问题

视频的横竖问题

WBOY
WBOYOriginal
2016-06-06 20:25:061197Durchsuche

我们系统中用户上传到视频多数是客户用手机拍摄的,现在存在一个问题,就是PC浏览器上播放的时候,这个视频是横着的。
大家明白我的意思吗? 实际事物是: 1,但是视频看起来就是: 一 。

现在我想把视频变成是跟实际事物一直的状态。

七牛返回的视频元信息中有rotate:90这样的参数,还有高度和宽度。

我的想法:
1、判断高度和宽度,全部转为高>宽
2、我对rotate这个参数不太理解,这个能代表实际和视频的角度差吗? (百度上出来的全部是imagerotate(),没有视频方面的。ffmpeg也没有提到这个,只是说了一些截图之类的问题。)

考虑到有些视频就是手机横着拍摄的,强制转了不是又出现了偏差?

求助有什么办法可以解决这个问题

我提供一个视频的元信息,大家帮我看看咯,谢谢

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

<code>{
    "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"
        }
    }
}</code>

回复内容:

我们系统中用户上传到视频多数是客户用手机拍摄的,现在存在一个问题,就是PC浏览器上播放的时候,这个视频是横着的。
大家明白我的意思吗? 实际事物是: 1,但是视频看起来就是: 一 。

现在我想把视频变成是跟实际事物一直的状态。

七牛返回的视频元信息中有rotate:90这样的参数,还有高度和宽度。

我的想法:
1、判断高度和宽度,全部转为高>宽
2、我对rotate这个参数不太理解,这个能代表实际和视频的角度差吗? (百度上出来的全部是imagerotate(),没有视频方面的。ffmpeg也没有提到这个,只是说了一些截图之类的问题。)

考虑到有些视频就是手机横着拍摄的,强制转了不是又出现了偏差?

求助有什么办法可以解决这个问题

我提供一个视频的元信息,大家帮我看看咯,谢谢

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

<code>{
    "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"
        }
    }
}</code>

你需要使用七牛的转码方式将 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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn