33

I have a raw YUV video file that I want to do some basic editing to in Adobe CS6 Premiere, but it won't recognize the file. I thought to use ffmpeg to convert it to something Premiere would take in, but I want this to be lossless because afterwards I will need it in YUV format again. I thought of avi, mov, and prores but I can't seem to figure out the proper command line to ffmpeg and how to ensure it is lossless.

Thanks for your help.

kilgoretrout
  • 3,547
  • 5
  • 31
  • 46
  • by lossless do you mean little loss? as unfortunately you will always loose some quality when transcoding file formats – brendosthoughts Apr 03 '13 at 04:24
  • 5
    Lossless is **not** little loss. Like when you compress a file, which will be smaller, and extract it again, it is fully the same file. This is lossless compression. – Omega Apr 03 '13 at 08:07
  • 3
    Consider [UT Video](http://umezawa.dyndns.info/archive/utvideo/?C=M;O=D). It is a fast, lossless format and is great for temporary, intermediate files. ffmpeg can natively encode and decode it (example: `ffmpeg -i input -codec:v utvideo -codec:a pcm_s16le output.avi`), and Premiere can too if you install UT Video. Also see [How to encode with FFmpeg from Adobe Premiere Pro](https://ffmpeg.org/trac/ffmpeg/wiki/FFmpegPremierePro). – llogan Apr 03 '13 at 17:53

1 Answers1

67

Yes, this is possible. It is normal that you can't open that raw video file since it is just raw data in one giant file, without any headers. So Adobe Premiere doesn't know what the size is, what framerate ect.

First make sure you downloaded the FFmpeg command line tool. Then after installing you can start converting by running a command with parameters. There are some parameters you have to fill in yourself before starting to convert:

  1. What type of the YUV pixel format are you using? The most common format is YUV4:2:0 planar 8-bit (YUV420p). You can type ffmpeg -pix_fmts to get a list of all available formats.
  2. What is the framerate? In my example I will use -r 25 fps.
  3. What encoder do you want to use? The libx264 (H.264) encoder is a great one for lossless compression.
  4. What is your framesize? In my example I will use -s 1920x1080

Then we get this command to do your compression.

ffmpeg -f rawvideo -vcodec rawvideo -s 1920x1080 -r 25 -pix_fmt yuv420p -i inputfile.yuv -c:v libx264 -preset ultrafast -qp 0 output.mp4

A little explanation of all other parameters:

  • With -f rawvideo you set the input format to a raw video container
  • With -vcodec rawvideo you set the input file as not compressed
  • With -i inputfile.yuv you set your input file
  • With -c:v libx264 you set the encoder to encode the video to libx264.
  • The -preset ultrafast setting is only speeding up the compression so your file size will be bigger than setting it to veryslow.
  • With -qp 0 you set the maximum quality. 0 is best, 51 is worst quality in our example.
  • Then output.mp4 is your new container to store your data in.

After you are done in Adobe Premiere, you can convert it back to a YUV file by inverting allmost all parameters. FFmpeg recognizes what's inside the mp4 container, so you don't need to provide parameters for the input.

ffmpeg -i input.mp4 -f rawvideo -vcodec rawvideo -pix_fmt yuv420p -s 1920x1080 -r 25 rawvideo.yuv

Omega
  • 1,101
  • 9
  • 14
  • 2
    in raw to mp4 ffmpeg command y did u use both yuv422p and yuv420p pix_fmts? – Necktwi Oct 16 '13 at 07:19
  • 1
    Good point! I've made a mistake in there. You only need to provide just one pix_fmt offcourse. I will edit the answer. – Omega Oct 17 '13 at 10:06
  • can u help me in converting the rawvideo generated by the code in http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html? when i converted it with ur ffmpeg command the output.mp4 when played with vlc, the video is distorted. here is a frame from the video https://lh3.googleusercontent.com/-S_Oaj6CYqZw/UmAIQ-Kw5BI/AAAAAAAAAuY/l2CBwo32g0w/w640-h480-no/myframe.jpg – Necktwi Oct 17 '13 at 15:58
  • It seems you are using another pixel format. In my case I use yuv420p, but in your case you should try another one. Use the `ffmpeg -pix_fmts` command to see a list about all different formats. – Omega Oct 24 '13 at 11:39
  • yeah! thanq; mine is yuyv422 – Necktwi Oct 25 '13 at 09:20
  • @Nick, isn't using H.264 to encode mean it is automatically not lossless because there is a lossy quantization step in any H.264 encode unless you set the QP (quantization parameter) to 0. I doubt this is the default when you call -c:v libx264, though I know that x264 can be set to lossless encoding. How is that guaranteed in your ffmpeg command line? – kilgoretrout Feb 06 '14 at 01:04
  • @river_jones, I don't get you. Do you ask the question: How do you know the video is encoded lossless in ffmpeg? If so, please ask it as a new question at superuser.com. – Omega Feb 13 '14 at 17:40
  • @Nick, My original question was "what is the proper command line call to ffmpeg to perform lossless conversion of YUV to some container that Premiere would take." In your answer you used the parameter -c:v libx264 in your command line. So I wanted to double check that indeed the command line call you provided would perform lossless encoding and not lossy. This is not a separate question, I am trying to make sure that using the libx264 parameter without additional arguments is going to be lossless. – kilgoretrout Feb 13 '14 at 19:10
  • @river_jones, Sorry for my late answer. From the libx264 manual: The range of the quantizer scale is 0-51: where 0 is lossless, 23 is default, and 51 is worst possible. In above example I use the `-qp 0` parameter to do so. Also stackoverflow related, you can accept this answer if it has helped you solving the question. – Omega Feb 25 '14 at 19:52
  • @Nick, thanks again, I just wanted to double check that one thing, I somehow missed the -qp 0 parameter. – kilgoretrout Mar 05 '14 at 09:37