Using FFMPEG to losslessly convert YUV to another format for editing in Adobe Premier

93,295

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

Share:
93,295
kilgoretrout
Author by

kilgoretrout

Updated on October 18, 2020

Comments

  • kilgoretrout
    kilgoretrout over 3 years

    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.

  • Necktwi
    Necktwi over 10 years
    in raw to mp4 ffmpeg command y did u use both yuv422p and yuv420p pix_fmts?
  • Omega
    Omega over 10 years
    Good point! I've made a mistake in there. You only need to provide just one pix_fmt offcourse. I will edit the answer.
  • Necktwi
    Necktwi over 10 years
    can u help me in converting the rawvideo generated by the code in 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 lh3.googleusercontent.com/-S_Oaj6CYqZw/UmAIQ-Kw5BI/AAAAAAAAA‌​uY/…
  • Omega
    Omega over 10 years
    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.
  • Necktwi
    Necktwi over 10 years
    yeah! thanq; mine is yuyv422
  • kilgoretrout
    kilgoretrout over 10 years
    @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?
  • Omega
    Omega over 10 years
    @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.
  • kilgoretrout
    kilgoretrout over 10 years
    @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.
  • Omega
    Omega over 10 years
    @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.
  • kilgoretrout
    kilgoretrout over 10 years
    @Nick, thanks again, I just wanted to double check that one thing, I somehow missed the -qp 0 parameter.