-1

I am trying to convert a video .ts to .mp4 that I have imported subprocess to convert video

subprocess.run(['ffmpeg', '-i', 'C:\Users\Gyana\Desktop\my project\blender-creating-game-animation-0-0.ts', 'C:\Users\Gyana\Desktop\my project\blender_creating_game_animation2460-0-0.mp4'])

def convert_video(video_input, video_output):
    cmds = ['ffmpeg', '-i', video_input, video_output]
    subprocess.Popen(cmds)

convert_video('C:\Users\Gyana\Desktop\my project\blender-creating-game-animation-0-0.ts','C:\Users\Gyana\Desktop\my project\lender.mp4')

python subpro.py File "subpro.py", line 7 cmds = ['ffmpeg', '-i', 'C:\Users\Gyana\Desktop\my project\blender-creating-game-animation-0-0.ts', 'C:\Users\Gyana\Desktop\my project\blender_creating_game_animation2460-0-0.mp4'] ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

python subpro.py File "subpro.py", line 11 convert_video('C:\Users\Gyana\Desktop\my project\blender-creating-game-animation-0-0.ts','C:\Users\Gyana\Desktop\my project\lender.mp4') ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

Underoos
  • 3,734
  • 6
  • 30
  • 63
lapu
  • 1
  • 1
  • 1
    Add r before path to make it raw string like `r'C:\..'` – Smart Manoj May 31 '19 at 05:00
  • 2
    Yes, @SmartManoj is right. You need to put 'r' in front of all of your path strings so that the backslashes aren't interpreted as the start of escape sequences. You could also double up each of your backslashes, but using 'r' is much cleaner. – CryptoFool May 31 '19 at 05:08
  • Possible duplicate of ["Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3](https://stackoverflow.com/questions/1347791/unicode-error-unicodeescape-codec-cant-decode-bytes-cannot-open-text-file) – buran May 31 '19 at 06:03

1 Answers1

0

Here, \U in 'C:\Users\Gyana\Desktop\my project\blender-creating-game-animation-0-0.ts' and 'C:\Users\Gyana\Desktop\my project\lender.mp4' start eight-characters Unicodes escapes, such as \U00014321. In your code, the escapes are followed by the character "s" which is invalid.

So, you have 3 possibilites

  1. use raw string:
convert_video(r'C:\Users\Gyana\Desktop\my project\blender-creating-game-animation-0-0.ts', r'C:\Users\Gyana\Desktop\my project\lender.mp4')
  1. use double anti slash:
convert_video('C:\\Users\\Gyana\\Desktop\\my project\\blender-creating-game-animation-0-0.ts','C:\\Users\\Gyana\\Desktop\\my project\\lender.mp4')
  1. replace "\" (anti slash) by "/" (slash)
convert_video('C:/Users/Gyana/Desktop/my project/blender-creating-game-animation-0-0.ts','C:/Users/Gyana/Desktop/my project/lender.mp4')
Zelow
  • 15
  • 4