맥락과 질문

맥락과 질문

맥락과 질문

내 MotoG3 휴대폰 안드로이드 휴대폰으로 동영상을 녹화했는데 결과 동영상(아마도 휴대폰 흔들림으로 인해)이 회전, 즉 수직으로 재생되는데 이는 제가 원하는 것이 아닙니다. 비디오가 MP4 컨테이너에 저장되었습니다.

녹화된 파일을 검사한 결과 ( ffprobe및 를 모두 사용하여 mediainfo) 비디오 스트림이 90도 회전되었음을 나타내는 플래그가 포함되어 있음을 확인했습니다. 이는 비디오 재생 중 회전을 설명합니다. 다음의 출력은 다음과 같습니다 ffprobe.

$ ffprobe -hide_banner ~/Pictures/2016/06/19/vid_20160619_170845475.mp4 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/rbrito/Pictures/2016/06/19/vid_20160619_170845475.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-06-19 20:25:49
    com.android.version: 6.0
  Duration: 00:17:01.96, start: 0.000000, bitrate: 17134 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17000 kb/s, SAR 1:1 DAR 16:9, 29 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 90
      creation_time   : 2016-06-19 20:25:49
      handler_name    : VideoHandle
      encoder         : MOTO
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-06-19 20:25:49
      handler_name    : SoundHandle

이 비디오는 제 아들과 함께한 드문 이벤트에서 나온 것이기 때문에 비디오 파일을 최소한으로 변경하고 싶습니다. 가급적이면 회전 메타데이터만 제거하고 다른 것은 제거하지 않는 것이 좋습니다.

불행하게도, 다음의 정보를 사용하여다른 답변도움이되지 않았습니다. 나는 다음을 사용해 보았습니다.

ffmpeg -i ~/Pictures/2016/06/19/vid_20160619_170845475.mp4 -c copy -metadata:s:v:0 rotate=0 -an vid_20160619_170845475_unrotated.mp4

그러나 날짜 등과 같은 다른 메타데이터는 결과 파일에 존재하지 않습니다. 특히 이로 인해 파일을 날짜별로 표시하는 동안 Organizer 프로그램이 혼란스러워집니다.

원본 데이터에 최대한 가깝게 유지하기 위해 입력 데이터를 최소한으로 변경(재다중화)할 수 있는 방법이 있습니까? 특히 파일을 다시 인코딩하고 싶지 않습니다.

Linux에서 사용 가능한 모든 도구가 선호됩니다.


추가 정보

ffmpeg의 전체 출력이 요청되었으므로 여기에 있습니다. 이것은 순수한 데비안 테스트 사용자 영역입니다.

참고로, ffmpeg는 데비안에서 잠재적으로 문제가 있는 코덱 없이 한 번, 일부 추가 코덱을 사용하여 두 번 컴파일되기 때문에 일치하지 않는 라이브러리에 대해 불평합니다. 나는 추가 코덱이 포함된 버전을 사용하고 있지만 여기서는 다중화만 사용되기 때문에 그것은 중요하지 않다고 생각합니다.

재다중화 전의 메타데이터

$ ffprobe  -hide_banner ~/Pictures/2016/06/19/vid_20160619_170845475.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/rbrito/Pictures/2016/06/19/vid_20160619_170845475.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-06-19 20:25:49
    com.android.version: 6.0
  Duration: 00:17:01.96, start: 0.000000, bitrate: 17134 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17000 kb/s, SAR 1:1 DAR 16:9, 29 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 90
      creation_time   : 2016-06-19 20:25:49
      handler_name    : VideoHandle
      encoder         : MOTO
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-06-19 20:25:49
      handler_name    : SoundHandle

재다중화 과정

여기서 오디오 메타데이터는 복사되지 않으며(옵션으로 인해 예상했던 결과임 -metadata:s:v:0) ffmpeg는 회전 설정 없이 비디오 메타데이터를 복사한다고 알려줍니다.

$ ffmpeg -hide_banner -i ~/Pictures/2016/06/19/vid_20160619_170845475.mp4 -c copy -metadata:s:v:0 rotate=0 -an vid_20160619_170845475_unrotated.mp4 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/rbrito/Pictures/2016/06/19/vid_20160619_170845475.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-06-19 20:25:49
    com.android.version: 6.0
  Duration: 00:17:01.96, start: 0.000000, bitrate: 17134 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17000 kb/s, SAR 1:1 DAR 16:9, 29 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 90
      creation_time   : 2016-06-19 20:25:49
      handler_name    : VideoHandle
      encoder         : MOTO
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      creation_time   : 2016-06-19 20:25:49
      handler_name    : SoundHandle
Output #0, mp4, to 'vid_20160619_170845475_unrotated.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    com.android.version: 6.0
    encoder         : Lavf57.25.100
    Stream #0:0(eng): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 17000 kb/s, 29 fps, 29.42 tbr, 90k tbn, 90k tbc (default)
    Metadata:
      encoder         : MOTO
      creation_time   : 2016-06-19 20:25:49
      handler_name    : VideoHandle
      rotate          : 0
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=29640 fps=403 q=-1.0 Lsize= 2121038kB time=00:17:01.91 bitrate=17003.0kbits/s speed=13.9x    
video:2120800kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.011211%

재다중화 후의 메타데이터

여기서는 출력에 비디오 메타데이터가 없고 컨테이너 수준 메타데이터만 있다는 점에 유의하세요.

$ ffprobe -hide_banner vid_20160619_170845475_unrotated.mp4 
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vid_20160619_170845475_unrotated.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:17:01.95, start: 0.000000, bitrate: 17002 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 17000 kb/s, 29 fps, 29.42 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      handler_name    : VideoHandler

답변1

FFmpeg는 기본적으로 대부분의 사용자 메타데이터를 전송하지 않지만 회전 태그와 같은 필드는 전송합니다.

아래 명령은 FFmpeg에 모든 메타데이터를 전송하도록 지시한 다음 회전 태그 값을 재정의합니다.

ffmpeg -i in.mp4 -c copy -map_metadata 0 -metadata:s:v:0 rotate=0 -an out.mp4

답변2

다음 명령을 실행하세요:

ffmpeg -i oldfile.mp4 -codec copy -metadata title="" -metadata album="" -metadata year="" -metadata container="" -metadata artist="" -metadata comment="" newfile.mp4

각 메타데이터 유형에 ""를 사용하면 이전 메타데이터가 비워지고 ffmpeg는 메타데이터가 지워진 새 파일에 전체 파일을 복사합니다.

중복을 방지하려면 새 파일을 만든 후 이전 파일을 삭제해야 합니다.

답변3

  • mutagen Python 라이브러리를 설치합니다.

    python3.6 -m pip install --user mutagen
    

    또는:

    python2.7 -m pip install --user mutagen
    

    Mutagen은 오디오 메타데이터를 처리하는 Python 모듈입니다.

  • 아래 내용을 metadata_cleaner.py다른 이름으로 저장하되 이름은 무엇이든 지정할 수 있습니다.

  • 변수 를 변경합니다 VIDEO_FOLDER = 'your_full_path_for_your_videos_folder'.

  • "변경 사항"이라고 표시된 줄 사이에서 덮어쓰려는 속성을 수정합니다.

  • 어디든 달려보세요 python metadata_cleaner.py.

스크립트는 다음과 같습니다.

import os
from mutagen.mp4 import MP4
## Can import MP3 as well if you want to modify MP3 files

## Folder full path to the files you want to modify:

FILES_FOLDER = "/media/removable/64GB-Micro/FilesToClean"

def get_all_files(path):
    """Returns all the files in the path as a list
    """
    return os.listdir(path)

def clean_metadata(videos_dir, files):
    """
    Receives two variables videos_dir (full file folder path) and files (list)
    Iterates over all the files in the directory and creates full paths for 
    every file using the videos_dir path and os.path.join function.
    """
    for file_name in files:
        file_path = os.path.join(videos_dir, file_name)

        ## create MP4 video_file instance

        video_file = MP4(file_path)

        ## This line will print out all key-value for the video_file-s:
        ## Useful if you don't know which attributes you want to modify yet

        print(video_file)

        ## In this example I wanted to clean the ART, aArt = Artist metadata
        ## and nam = Song Name metadata
        ## These prints will show artists and titles for each file before clean
        ## -------------------------- Your changes ---------------------------
        print("file_name: {}".format(file_name))
        print("Old ART: {}".format(video_file.get('\xa9ART', "Key not found")))
        print("Old aArt: {}".format(video_file.get('aART', "Key not found")))
        print("Old nam: {}".format(video_file.get('\xa9nam', "Key not found")))

        ## clean artist and name
        ## This part will overwrite the artist and song name attributes

        video_file['\xa9ART'] = ''
        video_file['aART'] = ''
        video_file['\xa9nam'] = ''
        ## -------------------------- Your changes ---------------------------
        ## save new metadata

        video_file.save()

        ## show video_file artist and title after clean
        ## Just to see if our actions were successful print out song metadata
        ## again after the changes

        print("New ART: {}".format(video_file.get('\xa9ART', "Key not found")))
        print("New aArt: {}".format(video_file.get('aART', "Key not found")))
        print("New nam: {}".format(video_file.get('\xa9nam', "Key not found")))


if __name__ == '__main__':
    ## load all the files into files variable as a list

    files = get_all_files(FILES_FOLDER)

    ## run clean_metadata function to clean all the files in the VIDEO_FOLDER
    ## path
    clean_metadata(videos_dir=FILES_FOLDER, files=files)

관련 정보